aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp54
1 files changed, 39 insertions, 15 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index ee61c23..9998b48 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -101,7 +101,7 @@ namespace QuickMedia {
UserInfo::UserInfo(RoomData *room, std::string user_id) :
room(room), display_name_color(user_id_to_color(user_id)), user_id(user_id), resolve_state(UserResolveState::NOT_RESOLVED)
{
- display_name = std::move(user_id);
+ display_name = user_id;
}
UserInfo::UserInfo(RoomData *room, std::string user_id, std::string display_name, std::string avatar_url) :
@@ -1368,7 +1368,6 @@ namespace QuickMedia {
room->set_prev_batch(prev_batch_json.GetString());
}
- // TODO: Use /_matrix/client/r0/notifications ? or remove this and always look for displayname/user_id in messages
bool has_unread_notifications = false;
const rapidjson::Value &unread_notification_json = GetMember(it.value, "unread_notifications");
if(unread_notification_json.IsObject() && !is_additional_messages_sync) {
@@ -1382,7 +1381,7 @@ namespace QuickMedia {
const rapidjson::Value &events_json = GetMember(timeline_json, "events");
events_add_user_info(events_json, room);
events_set_room_name(events_json, room);
- set_room_name_to_users_if_empty(room, user_id);
+ set_room_name_to_users_if_empty(room, my_user_id);
if(account_data_json.IsObject()) {
const rapidjson::Value &events_json = GetMember(account_data_json, "events");
@@ -1397,7 +1396,7 @@ namespace QuickMedia {
if(!is_additional_messages_sync)
events_add_pinned_events(events_json, room);
} else {
- set_room_name_to_users_if_empty(room, user_id);
+ set_room_name_to_users_if_empty(room, my_user_id);
if(account_data_json.IsObject()) {
const rapidjson::Value &events_json = GetMember(account_data_json, "events");
auto me = get_me(room);
@@ -1784,8 +1783,9 @@ namespace QuickMedia {
if(strcmp(membership_json.GetString(), "join") == 0) {
const rapidjson::Value &unsigned_json = GetMember(event_item_json, "unsigned");
if(unsigned_json.IsObject()) {
+ const rapidjson::Value &prev_sender = GetMember(unsigned_json, "prev_sender");
const rapidjson::Value &prev_content_json = GetMember(unsigned_json, "prev_content");
- if(prev_content_json.IsObject()) {
+ if(prev_content_json.IsObject() && (!prev_sender.IsString() || strcmp(prev_sender.GetString(), user->user_id.c_str()) == 0)) {
const rapidjson::Value &prev_displayname_json = GetMember(prev_content_json, "displayname");
const rapidjson::Value &prev_avatar_url_json = GetMember(prev_content_json, "avatar_url");
const rapidjson::Value &new_displayname_json = GetMember(*content_json, "displayname");
@@ -2003,7 +2003,7 @@ namespace QuickMedia {
std::vector<std::shared_ptr<UserInfo>> users_excluding_me;
if(!has_room_name || !has_room_avatar_url || room->name_is_fallback || room->avatar_is_fallback)
- users_excluding_me = room->get_users_excluding_me(user_id);
+ users_excluding_me = room->get_users_excluding_me(my_user_id);
if(!has_room_name) {
room->set_name(combine_user_display_names_for_room_name(users_excluding_me, room_creator_user_id));
@@ -2255,7 +2255,7 @@ namespace QuickMedia {
std::string desc;
LeaveType leave_type;
if(strcmp(membership_json.GetString(), "leave") == 0) {
- if(strcmp(sender_json.GetString(), user_id.c_str()) == 0) {
+ if(strcmp(sender_json.GetString(), my_user_id.c_str()) == 0) {
leave_type = LeaveType::LEAVE;
} else {
leave_type = LeaveType::KICKED;
@@ -2929,7 +2929,7 @@ namespace QuickMedia {
// such as pantalaimon
json_root.AddMember("homeserver", rapidjson::StringRef(homeserver.c_str()), request_data.GetAllocator());
- this->user_id = user_id_json.GetString();
+ this->my_user_id = user_id_json.GetString();
this->access_token = access_token_json.GetString();
this->homeserver = homeserver;
@@ -2964,7 +2964,7 @@ namespace QuickMedia {
// Make sure all fields are reset here!
rooms.clear();
room_data_by_id.clear();
- user_id.clear();
+ my_user_id.clear();
access_token.clear();
homeserver.clear();
upload_limit.reset();
@@ -3063,7 +3063,7 @@ namespace QuickMedia {
std::string access_token = access_token_json.GetString();
std::string homeserver = homeserver_json.GetString();
- this->user_id = std::move(user_id);
+ this->my_user_id = std::move(user_id);
this->access_token = std::move(access_token);
this->homeserver = std::move(homeserver);
return PluginResult::OK;
@@ -3086,7 +3086,7 @@ namespace QuickMedia {
};
std::string server_response;
- DownloadResult download_result = download_to_string(homeserver + "/_matrix/client/r0/rooms/" + room->id + "/typing/" + url_param_encode(user_id) , server_response, std::move(additional_args), use_tor, true);
+ DownloadResult download_result = download_to_string(homeserver + "/_matrix/client/r0/rooms/" + room->id + "/typing/" + url_param_encode(my_user_id) , server_response, std::move(additional_args), use_tor, true);
return download_result_to_plugin_result(download_result);
}
@@ -3106,7 +3106,7 @@ namespace QuickMedia {
};
std::string server_response;
- DownloadResult download_result = download_to_string(homeserver + "/_matrix/client/r0/rooms/" + room->id + "/typing/" + url_param_encode(user_id), server_response, std::move(additional_args), use_tor, true);
+ DownloadResult download_result = download_to_string(homeserver + "/_matrix/client/r0/rooms/" + room->id + "/typing/" + url_param_encode(my_user_id), server_response, std::move(additional_args), use_tor, true);
return download_result_to_plugin_result(download_result);
}
@@ -3199,7 +3199,7 @@ namespace QuickMedia {
bool Matrix::was_message_posted_by_me(void *message) {
Message *message_typed = (Message*)message;
- return user_id == message_typed->user->user_id;
+ return my_user_id == message_typed->user->user_id;
}
std::string Matrix::message_get_author_displayname(Message *message) const {
@@ -3239,7 +3239,7 @@ namespace QuickMedia {
}
std::shared_ptr<UserInfo> Matrix::get_me(RoomData *room) {
- return get_user_by_id(room, user_id);
+ return get_user_by_id(room, my_user_id);
}
RoomData* Matrix::get_room_by_id(const std::string &id) {
@@ -3336,6 +3336,7 @@ namespace QuickMedia {
}
void Matrix::update_room_users(RoomData *room) {
+#if 1
std::vector<CommandArg> additional_args = {
{ "-H", "Authorization: Bearer " + access_token }
};
@@ -3360,7 +3361,8 @@ namespace QuickMedia {
const rapidjson::Value &avatar_url_json = GetMember(joined_obj.value, "avatar_url");
const rapidjson::Value &display_name_json = GetMember(joined_obj.value, "display_name");
- auto user = get_user_by_id(room, std::string(joined_obj.name.GetString(), joined_obj.name.GetStringLength()));
+ std::string user_id(joined_obj.name.GetString(), joined_obj.name.GetStringLength());
+ auto user = get_user_by_id(room, user_id);
assert(user);
std::string display_name = display_name_json.IsString() ? display_name_json.GetString() : user_id;
@@ -3372,6 +3374,28 @@ namespace QuickMedia {
room->set_user_avatar_url(user, std::move(avatar_url));
room->set_user_display_name(user, std::move(display_name));
}
+#else
+ std::vector<CommandArg> additional_args = {
+ { "-H", "Authorization: Bearer " + access_token }
+ };
+
+ // TODO: Use at param? which is room->get_prev_batch();
+ char url[512];
+ snprintf(url, sizeof(url), "%s/_matrix/client/r0/rooms/%s/members?membership=join", homeserver.c_str(), room->id.c_str());
+
+ rapidjson::Document json_root;
+ DownloadResult download_result = download_json(json_root, url, std::move(additional_args), true);
+ if(download_result != DownloadResult::OK || !json_root.IsObject()) {
+ fprintf(stderr, "Fetching users for room %s failed!\n", room->id.c_str());
+ return;
+ }
+
+ const rapidjson::Value &chunk_json = GetMember(json_root, "chunk");
+ if(!chunk_json.IsArray())
+ return;
+
+ events_add_user_info(chunk_json, room);
+#endif
}
// TODO: GET the filter to check if its valid?