diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-11-19 12:23:06 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-11-19 12:23:06 +0100 |
commit | 9134914f6065c0b248dd1b4317dbf9b16f5f52b5 (patch) | |
tree | 730e286439bed8022cd7fd11b421310932b5a768 /src/plugins | |
parent | 9aa8c291e775083078efe93d0bc42390955ae61a (diff) |
Matrix: fix duplicate tag items, cache events we dont have permission to view as well
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Matrix.cpp | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index f6a91e7..f17da30 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -715,7 +715,15 @@ namespace QuickMedia { } for(auto &room_body_item : it.second) { - tag_data->room_body_items.push_back(room_body_item); + bool already_exists = false; + for(auto &body_it : tag_data->room_body_items) { + if(body_it->userdata == room_body_item->userdata) { + already_exists = true; + break; + } + } + if(!already_exists) + tag_data->room_body_items.push_back(room_body_item); } } add_room_body_items_by_tags.clear(); @@ -2744,7 +2752,22 @@ namespace QuickMedia { snprintf(url, sizeof(url), "%s/_matrix/client/r0/rooms/%s/event/%s", homeserver.c_str(), room->id.c_str(), event_id.c_str()); #endif std::string response; - DownloadResult download_result = download_to_string_cache(url, response, std::move(additional_args), use_tor, true); + DownloadResult download_result = download_to_string_cache(url, response, std::move(additional_args), use_tor, true, [](std::string &response) { + rapidjson::Document json_root; + rapidjson::ParseResult parse_result = json_root.Parse(response.c_str(), response.size()); + if(parse_result.IsError() || !json_root.IsObject()) + return false; + + const rapidjson::Value &errcode_json = GetMember(json_root, "errcode"); + if(errcode_json.IsString()) { + if(strcmp(errcode_json.GetString(), "M_FORBIDDEN") == 0) + return true; + else + return false; + } + + return true; + }); if(download_result != DownloadResult::OK) return nullptr; rapidjson::Document json_root; @@ -2761,6 +2784,13 @@ namespace QuickMedia { return nullptr; } + const rapidjson::Value &errcode_json = GetMember(json_root, "errcode"); + if(errcode_json.IsString() && strcmp(errcode_json.GetString(), "M_FORBIDDEN") == 0) { + fprintf(stderr, "You donm't have permission to access event %s\n", event_id.c_str()); + room->fetched_messages_by_event_id.insert(std::make_pair(event_id, nullptr)); + return nullptr; + } + const rapidjson::Value &error_json = GetMember(json_root, "error"); if(error_json.IsString()) { fprintf(stderr, "Matrix::get_message_by_id, error: %s\n", error_json.GetString()); |