aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Matrix.hpp1
-rw-r--r--src/QuickMedia.cpp2
-rw-r--r--src/plugins/Matrix.cpp34
3 files changed, 34 insertions, 3 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 50f8c6b..607ef81 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -40,6 +40,7 @@ namespace QuickMedia {
std::vector<UserInfo> user_info;
std::vector<Message> messages;
std::string name;
+ std::string avatar_url;
std::string prev_batch;
bool initial_fetch_finished = false;
};
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 5d8a7e4..c481d49 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -640,6 +640,7 @@ namespace QuickMedia {
return std::to_string(seconds) + " second" + (seconds == 1 ? "" : "s") + " ago";
}
+ // TODO: Make asynchronous
static void fill_history_items_from_json(const Json::Value &history_json, BodyItems &history_items) {
assert(history_json.isArray());
@@ -676,6 +677,7 @@ namespace QuickMedia {
}
}
+ // TODO: Make asynchronous
static void fill_recommended_items_from_json(const Json::Value &recommended_json, BodyItems &body_items) {
assert(recommended_json.isObject());
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";
}
}