diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Matrix.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index afa8738..e015ada 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -1631,14 +1631,20 @@ namespace QuickMedia { static std::string thumbnail_url_extract_media_id(const std::string &media_url) { size_t start = 0; size_t end = media_url.size(); - if(strncmp(media_url.c_str(), "mxc://", 6) == 0) - start = 6; + if(strncmp(media_url.c_str(), "mxc://", 6) != 0) + return ""; + + start = 6; if(media_url.size() >= start + 5 && strncmp(media_url.c_str() + media_url.size() - 5, "#auto", 5) == 0) end = media_url.size() - 5; + return media_url.substr(start, end - start); } static std::string get_thumbnail_url(const std::string &homeserver, const std::string &mxc_id) { + if(mxc_id.empty()) + return ""; + std::string size = std::to_string(int(32 * get_ui_scale())); return homeserver + "/_matrix/media/r0/thumbnail/" + mxc_id + "?width=" + size + "&height=" + size + "&method=crop"; } @@ -1749,10 +1755,11 @@ namespace QuickMedia { 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); - } + if(strncmp(thumbnail_str.c_str(), "mxc://", 6) != 0) + return ""; + + thumbnail_str.erase(thumbnail_str.begin(), thumbnail_str.begin() + 6); + return homeserver + "/_matrix/media/r0/download/" + std::move(thumbnail_str); } } @@ -2287,11 +2294,10 @@ namespace QuickMedia { continue; const rapidjson::Value &url_json = GetMember(content_json, "url"); - if(!url_json.IsString()) + if(!url_json.IsString() || strncmp(url_json.GetString(), "mxc://", 6) != 0) continue; - std::string url_json_str = url_json.GetString() + 6; - room_data->set_avatar_url(get_thumbnail_url(homeserver, thumbnail_url_extract_media_id(url_json_str))); + room_data->set_avatar_url(get_thumbnail_url(homeserver, thumbnail_url_extract_media_id(url_json.GetString()))); room_data->avatar_is_fallback = false; } else if(strcmp(type_json.GetString(), "m.room.avatar") == 0) { const rapidjson::Value &content_json = GetMember(event_item_json, "content"); @@ -2299,11 +2305,10 @@ namespace QuickMedia { continue; const rapidjson::Value &url_json = GetMember(content_json, "url"); - if(!url_json.IsString()) + if(!url_json.IsString() || strncmp(url_json.GetString(), "mxc://", 6) != 0) continue; - std::string url_json_str = url_json.GetString() + 6; - room_data->set_avatar_url(get_thumbnail_url(homeserver, thumbnail_url_extract_media_id(url_json_str))); + room_data->set_avatar_url(get_thumbnail_url(homeserver, thumbnail_url_extract_media_id(url_json.GetString()))); room_data->avatar_is_fallback = false; } else if(strcmp(type_json.GetString(), "m.room.topic") == 0) { const rapidjson::Value &content_json = GetMember(event_item_json, "content"); |