From 50fba2bd585aa51f41d98f70afa4760fa03c92b0 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 28 Mar 2021 00:52:27 +0100 Subject: Matrix: use proper url for downloading thumbnails --- src/plugins/Matrix.cpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 220a059..e0a9a4b 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -1668,21 +1668,6 @@ namespace QuickMedia { } } - static std::string message_content_extract_thumbnail_url(const rapidjson::Value &content_json, const std::string &homeserver) { - const rapidjson::Value &info_json = GetMember(content_json, "info"); - if(info_json.IsObject()) { - const rapidjson::Value &thumbnail_url_json = GetMember(info_json, "thumbnail_url"); - if(thumbnail_url_json.IsString()) { - std::string thumbnail_str = thumbnail_url_json.GetString(); - 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 ""; - } - static bool message_content_extract_thumbnail_size(const rapidjson::Value &content_json, sf::Vector2i &thumbnail_size) { const rapidjson::Value &info_json = GetMember(content_json, "info"); if(!info_json.IsObject()) @@ -1711,6 +1696,26 @@ namespace QuickMedia { return found_resolution; } + static std::string message_content_extract_thumbnail_url(const rapidjson::Value &content_json, const std::string &homeserver) { + const rapidjson::Value &info_json = GetMember(content_json, "info"); + if(info_json.IsObject()) { + sf::Vector2i thumbnail_size; + if(!message_content_extract_thumbnail_size(content_json, thumbnail_size)) + return ""; + + const rapidjson::Value &thumbnail_url_json = GetMember(info_json, "thumbnail_url"); + if(thumbnail_url_json.IsString()) { + std::string thumbnail_str = thumbnail_url_json.GetString(); + if(strncmp(thumbnail_str.c_str(), "mxc://", 6) == 0) { + thumbnail_str.erase(thumbnail_str.begin(), thumbnail_str.begin() + 6); + return homeserver + "/_matrix/media/r0/thumbnail/" + std::move(thumbnail_str) + "?width=" + std::to_string(thumbnail_size.x) + "&height=" + std::to_string(thumbnail_size.y); + } + } + } + + return ""; + } + // TODO: Is this really the proper way to check for username mentions? static bool is_username_seperating_character(char c) { switch(c) { -- cgit v1.2.3