aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-09-27 11:26:03 +0200
committerdec05eba <dec05eba@protonmail.com>2020-09-27 11:26:03 +0200
commitc9a9450cf2737ade139944dc901cc80832ab4499 (patch)
treebe434d51979b713e9aa1972fcdc84ca0742b1d1b /src/plugins
parent888fba907eba13ee6a30bf7169d4d96af5b443a5 (diff)
Fix matrix thumbnails
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 3ce6ffd..2321ff4 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -167,7 +167,7 @@ namespace QuickMedia {
body_item->set_description(messages[i].body);
if(!messages[i].thumbnail_url.empty())
body_item->thumbnail_url = messages[i].thumbnail_url;
- else if(!messages[i].url.empty())
+ else if(!messages[i].url.empty() && messages->type == MessageType::IMAGE)
body_item->thumbnail_url = messages[i].url;
else
body_item->thumbnail_url = user_info.avatar_url;
@@ -380,6 +380,21 @@ namespace QuickMedia {
}
}
+ static std::string message_content_extract_thumbnail_url(const Json::Value &content_json, const std::string &homeserver) {
+ const Json::Value &info_json = content_json["info"];
+ if(info_json.isObject()) {
+ const Json::Value &thumbnail_url_json = info_json["thumbnail_url"];
+ if(thumbnail_url_json.isString()) {
+ std::string thumbnail_str = thumbnail_url_json.asString();
+ if(strncmp(thumbnail_str.c_str(), "mxc://", 6) == 0) {
+ thumbnail_str.erase(thumbnail_str.begin(), thumbnail_str.begin() + 6);
+ return homeserver + "/_matrix/media/r0/download/" + std::move(thumbnail_str);
+ }
+ }
+ }
+ return "";
+ }
+
void Matrix::events_add_messages(const Json::Value &events_json, RoomData *room_data, MessageDirection message_dir) {
if(!events_json.isArray())
return;
@@ -433,6 +448,7 @@ namespace QuickMedia {
message.user_id = user_it->second;
message.body = body_json.asString();
message.url = homeserver + "/_matrix/media/r0/download/" + url_json.asString().substr(6);
+ message.thumbnail_url = message_content_extract_thumbnail_url(content_json, homeserver);
message.type = MessageType::IMAGE;
new_messages.push_back(std::move(message));
} else if(strcmp(content_type.asCString(), "m.video") == 0) {
@@ -441,22 +457,10 @@ namespace QuickMedia {
continue;
Message message;
-
- const Json::Value &info_json = content_json["info"];
- if(info_json.isString()) {
- const Json::Value &thumbnail_url_json = info_json["thumbnail_url"];
- if(thumbnail_url_json.isString()) {
- std::string thumbnail_str = thumbnail_url_json.asString();
- if(strncmp(thumbnail_str.c_str(), "mxc://", 6) == 0) {
- thumbnail_str.erase(thumbnail_str.begin(), thumbnail_str.begin() + 6);
- message.thumbnail_url = homeserver + "/_matrix/media/r0/download/" + std::move(thumbnail_str);
- }
- }
- }
-
message.user_id = user_it->second;
message.body = body_json.asString();
message.url = homeserver + "/_matrix/media/r0/download/" + url_json.asString().substr(6);
+ message.thumbnail_url = message_content_extract_thumbnail_url(content_json, homeserver);
message.type = MessageType::VIDEO;
new_messages.push_back(std::move(message));
}