aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 1e8b927..2d4fd4a 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -135,6 +135,7 @@ namespace QuickMedia {
std::string room_id_str = room_id_json.asString();
std::string room_name;
+ std::string avatar_url;
auto room_it = room_data_by_id.find(room_id_str);
if(room_it == room_data_by_id.end()) {
@@ -146,10 +147,12 @@ namespace QuickMedia {
room_name = room_it->second->name;
if(room_name.empty())
room_name = room_id_str;
+ avatar_url = room_it->second->avatar_url;
}
auto body_item = std::make_unique<BodyItem>(std::move(room_name));
body_item->url = room_id_str;
+ body_item->thumbnail_url = std::move(avatar_url);
result_items.push_back(std::move(body_item));
}
@@ -448,7 +451,6 @@ namespace QuickMedia {
continue;
room_data->name = name_json.asString();
- return;
}
for(const Json::Value &event_item_json : events_json) {
@@ -467,8 +469,34 @@ namespace QuickMedia {
if(!creator_json.isString())
continue;
- room_data->name = extract_user_name_from_user_id(creator_json.asString());
- return;
+ if(room_data->name.empty())
+ room_data->name = extract_user_name_from_user_id(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;
+ }
+ }
+
+ for(const Json::Value &event_item_json : events_json) {
+ if(!event_item_json.isObject())
+ continue;
+
+ const Json::Value &type_json = event_item_json["type"];
+ if(!type_json.isString() || strcmp(type_json.asCString(), "m.room.avatar") != 0)
+ continue;
+
+ const Json::Value &content_json = event_item_json["content"];
+ if(!content_json.isObject())
+ continue;
+
+ const Json::Value &url_json = content_json["url"];
+ if(!url_json.isString() || strncmp(url_json.asCString(), "mxc://", 6) != 0)
+ continue;
+
+ std::string url_json_str = url_json.asCString() + 6;
+ room_data->avatar_url = homeserver + "/_matrix/media/r0/thumbnail/" + std::move(url_json_str) + "?width=32&height=32&method=crop";
}
}