diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-09-24 02:43:08 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-09-24 02:43:08 +0200 |
commit | be1e24edae3a6f388929569269c27c53e28b8921 (patch) | |
tree | 2b032f384e392799d270e57ed5412960373a3897 /src | |
parent | fe6db40c2f6cd10b4af086d622cf59442b7e7c67 (diff) |
matrix: Add thumbnails to room list
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 2 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 34 |
2 files changed, 33 insertions, 3 deletions
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"; } } |