From 8ce51433c8a73b76e57f124bb62e5aa39867238a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 3 Oct 2020 13:12:55 +0200 Subject: Matrix: show messages from users without an avatar --- src/plugins/Matrix.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/plugins') 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)); + } } } -- cgit v1.2.3