From a6a309c0c9828d62e81632a863108d6b5233d1ba Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 2 Oct 2020 16:50:19 +0200 Subject: Matrix: show audio and files in body --- plugins/Matrix.hpp | 4 +++- src/plugins/Matrix.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index bbf35db..a4f0cf4 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -16,7 +16,9 @@ namespace QuickMedia { enum class MessageType { TEXT, IMAGE, - VIDEO + VIDEO, + AUDIO, + FILE }; struct Message { diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 60fc8a9..32cabe1 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -542,6 +542,20 @@ namespace QuickMedia { 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; + } else if(strcmp(content_type.asCString(), "m.audio") == 0) { + const Json::Value &url_json = content_json["url"]; + if(!url_json.isString() || strncmp(url_json.asCString(), "mxc://", 6) != 0) + continue; + + message->url = homeserver + "/_matrix/media/r0/download/" + url_json.asString().substr(6); + message->type = MessageType::AUDIO; + } else if(strcmp(content_type.asCString(), "m.file") == 0) { + const Json::Value &url_json = content_json["url"]; + if(!url_json.isString() || strncmp(url_json.asCString(), "mxc://", 6) != 0) + continue; + + message->url = homeserver + "/_matrix/media/r0/download/" + url_json.asString().substr(6); + message->type = MessageType::FILE; } else { continue; } @@ -890,6 +904,12 @@ namespace QuickMedia { case MessageType::VIDEO: related_to_body = "sent a video"; break; + case MessageType::AUDIO: + related_to_body = "sent an audio file"; + break; + case MessageType::FILE: + related_to_body = "sent a file"; + break; } return "> <" + room_data->user_info[message->user_id].user_id + "> " + std::move(related_to_body) + "\n\n" + body; } @@ -1157,6 +1177,10 @@ namespace QuickMedia { new_message->type = MessageType::IMAGE; } else if(strcmp(content_type.asCString(), "m.video") == 0) { new_message->type = MessageType::VIDEO; + } else if(strcmp(content_type.asCString(), "m.audio") == 0) { + new_message->type = MessageType::AUDIO; + } else if(strcmp(content_type.asCString(), "m.file") == 0) { + new_message->type = MessageType::FILE; } else { return nullptr; } -- cgit v1.2.3