diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-03 13:12:55 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-03 13:12:55 +0200 |
commit | 8ce51433c8a73b76e57f124bb62e5aa39867238a (patch) | |
tree | a58a5b9a3f70b4039a9662cfbf1b0d8fe3ff44bb /src | |
parent | a9074aeb6fdef5139ce978449efa55cf7e388020 (diff) |
Matrix: show messages from users without an avatar
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 2 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 22 |
2 files changed, 13 insertions, 11 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 01bef82..2607873 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1883,7 +1883,6 @@ namespace QuickMedia { } } - // TODO: This code is duplicated in many places. Handle it in one place. if(redraw) { redraw = false; search_bar->onWindowResize(window_size); @@ -2459,7 +2458,6 @@ namespace QuickMedia { } } - // TODO: This code is duplicated in many places. Handle it in one place. if(redraw) { redraw = false; search_bar->onWindowResize(window_size); diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 8189806..69c2686 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -331,30 +331,34 @@ namespace QuickMedia { if(!membership_json.isString() || strcmp(membership_json.asCString(), "join") != 0) continue; + std::string avatar_url_str; const Json::Value &avatar_url_json = content_json["avatar_url"]; - if(!avatar_url_json.isString()) - continue; + if(avatar_url_json.isString()) + avatar_url_str = avatar_url_json.asString(); const Json::Value &display_name_json = content_json["displayname"]; if(!display_name_json.isString()) continue; - + std::string sender_json_str = sender_json.asString(); - auto user_it = room_data->user_info_by_user_id.find(sender_json_str); - if(user_it != room_data->user_info_by_user_id.end()) - continue; UserInfo user_info; user_info.user_id = sender_json_str; - user_info.avatar_url = avatar_url_json.asString(); + user_info.avatar_url = std::move(avatar_url_str); if(strncmp(user_info.avatar_url.c_str(), "mxc://", 6) == 0) user_info.avatar_url.erase(user_info.avatar_url.begin(), user_info.avatar_url.begin() + 6); // TODO: What if the user hasn't selected an avatar? user_info.avatar_url = homeserver + "/_matrix/media/r0/thumbnail/" + user_info.avatar_url + "?width=32&height=32&method=crop"; user_info.display_name = display_name_json.asString(); user_info.display_name_color = user_id_to_color(sender_json_str); - room_data->user_info.push_back(user_info); - room_data->user_info_by_user_id.insert(std::make_pair(sender_json_str, room_data->user_info.size() - 1)); + + auto user_it = room_data->user_info_by_user_id.find(sender_json_str); + if(user_it != room_data->user_info_by_user_id.end()) { + room_data->user_info[user_it->second] = std::move(user_info); + } else { + room_data->user_info.push_back(user_info); + room_data->user_info_by_user_id.insert(std::make_pair(sender_json_str, room_data->user_info.size() - 1)); + } } } |