aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-03 11:21:01 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-03 11:21:01 +0200
commitadfdc6109c18776c69d8b519606d6721354ec004 (patch)
tree3fd2bf2341df84ed20c340a9ab2f58f7f14d1b8d /src
parent769000b8f979fd2c4d7cd87fb83cf08912eb90dc (diff)
Matrix: use correct avatar for direct message rooms
Diffstat (limited to 'src')
-rw-r--r--src/plugins/Matrix.cpp40
1 files changed, 26 insertions, 14 deletions
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;
+ }
}
}