diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-03-28 00:52:27 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-03-28 00:52:27 +0100 |
commit | 50fba2bd585aa51f41d98f70afa4760fa03c92b0 (patch) | |
tree | 08b1c96dd5a2958559ad660a566af5d5f1c02081 /src/plugins | |
parent | c428eb6118a2c7e7dcf9ebdee05e80eb5cd3dc1b (diff) |
Matrix: use proper url for downloading thumbnails
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Matrix.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
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) { |