aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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));
}