diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-03 11:21:01 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-03 11:21:01 +0200 |
commit | adfdc6109c18776c69d8b519606d6721354ec004 (patch) | |
tree | 3fd2bf2341df84ed20c340a9ab2f58f7f14d1b8d | |
parent | 769000b8f979fd2c4d7cd87fb83cf08912eb90dc (diff) |
Matrix: use correct avatar for direct message rooms
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 40 |
2 files changed, 28 insertions, 15 deletions
@@ -81,4 +81,5 @@ Show deleted messages in matrix as MESSAGE DELETED or whatever. Use linear-interpolation for thumbnail creation. If --no-audio is used then music should be played with a lightweight music player instead. MPV is heavy even for music (60mb RAM). Optimize startup time. -Update 4chan thread in real time, just like 4chan-x.
\ No newline at end of file +Update 4chan thread in real time, just like 4chan-x. +Save the original event message, so when replying for example we can use the original message as the replying to message, rather than our converted "body" text.
\ No newline at end of file diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 8796729..8189806 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -573,23 +573,26 @@ namespace QuickMedia { return user_id.substr(1, index - 1); } - static std::string combine_user_display_names_for_room_name(const std::string &my_user_id, const std::vector<UserInfo> &user_info, const std::string &fallback_user_id) { - std::vector<const UserInfo*> users_excluding_me; - for(const UserInfo &user : user_info) { + static std::vector<UserInfo*> get_users_excluding_me(const std::string &my_user_id, std::vector<UserInfo> &user_info) { + std::vector<UserInfo*> users_excluding_me; + for(UserInfo &user : user_info) { if(user.user_id != my_user_id) { users_excluding_me.push_back(&user); } } + return users_excluding_me; + } + static std::string combine_user_display_names_for_room_name(const std::vector<UserInfo*> &user_info, const std::string &fallback_user_id) { std::string result; - if(users_excluding_me.size() == 0) + if(user_info.size() == 0) result = extract_user_name_from_user_id(fallback_user_id); - else if(users_excluding_me.size() == 1) - result = users_excluding_me[0]->display_name; - else if(users_excluding_me.size() == 2) - result = users_excluding_me[0]->display_name + " and " + users_excluding_me[1]->display_name; - else if(users_excluding_me.size() > 2) - result = users_excluding_me[0]->display_name + ", " + users_excluding_me[1]->display_name + " and " + std::to_string(users_excluding_me.size() - 2) + " other(s)"; + else if(user_info.size() == 1) + result = user_info[0]->display_name; + else if(user_info.size() == 2) + result = user_info[0]->display_name + " and " + user_info[1]->display_name; + else if(user_info.size() > 2) + result = user_info[0]->display_name + ", " + user_info[1]->display_name + " and " + std::to_string(user_info.size() - 2) + " other(s)"; return result; } @@ -616,6 +619,10 @@ namespace QuickMedia { room_data->name = name_json.asString(); } + std::vector<UserInfo*> users_excluding_me; + if(room_data->name.empty() || room_data->avatar_url.empty()) + users_excluding_me = get_users_excluding_me(user_id, room_data->user_info); + for(const Json::Value &event_item_json : events_json) { if(!event_item_json.isObject()) continue; @@ -633,12 +640,17 @@ namespace QuickMedia { continue; if(room_data->name.empty()) - room_data->name = combine_user_display_names_for_room_name(user_id, room_data->user_info, creator_json.asString()); + room_data->name = combine_user_display_names_for_room_name(users_excluding_me, creator_json.asString()); if(room_data->avatar_url.empty()) { - auto user_it = room_data->user_info_by_user_id.find(creator_json.asString()); - if(user_it != room_data->user_info_by_user_id.end()) - room_data->avatar_url = room_data->user_info[user_it->second].avatar_url; + if(users_excluding_me.empty()) { + auto user_it = room_data->user_info_by_user_id.find(creator_json.asString()); + if(user_it != room_data->user_info_by_user_id.end()) + room_data->avatar_url = room_data->user_info[user_it->second].avatar_url; + } else { + // TODO: If there are multiple users, then we want to use some other type of avatar, not the first users avatar + room_data->avatar_url = users_excluding_me.front()->avatar_url; + } } } |