From 9aa8c291e775083078efe93d0bc42390955ae61a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 19 Nov 2020 10:16:05 +0100 Subject: Matrix: cache get_message_by_id, temporary remove fetching additional messages which corrupts messages --- src/QuickMedia.cpp | 5 ++++- src/plugins/Matrix.cpp | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 20c2371..5c88322 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3457,7 +3457,10 @@ namespace QuickMedia { auto message = std::make_shared(); message->user = matrix->get_me(current_room); - message->body = text; + if(msgtype == "m.emote") + message->body = "*" + current_room->get_user_display_name(me) + "* " + text; + else + message->body = text; message->type = MessageType::TEXT; message->timestamp = time(NULL) * 1000; diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 1e35d9e..f6a91e7 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -1005,7 +1005,7 @@ namespace QuickMedia { { "-H", "Authorization: Bearer " + access_token }, { "-m", "35" } }; - +#if 0 sync_additional_messages_thread = std::thread([this]() { std::vector additional_args = { { "-H", "Authorization: Bearer " + access_token }, @@ -1031,7 +1031,7 @@ namespace QuickMedia { additional_messages_queue.pop_wait(); parse_sync_response(json_root, true); }); - +#endif const rapidjson::Value *next_batch_json; PluginResult result; bool initial_sync = true; @@ -2743,13 +2743,20 @@ namespace QuickMedia { char url[512]; 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 err_msg; - rapidjson::Document json_root; - DownloadResult download_result = download_json(json_root, url, std::move(additional_args), true, &err_msg); + std::string response; + DownloadResult download_result = download_to_string_cache(url, response, std::move(additional_args), use_tor, true); if(download_result != DownloadResult::OK) return nullptr; + rapidjson::Document json_root; + rapidjson::ParseResult parse_result = json_root.Parse(response.c_str(), response.size()); + if(parse_result.IsError()) { + fprintf(stderr, "Failed to get message by id %s\n", event_id.c_str()); + room->fetched_messages_by_event_id.insert(std::make_pair(event_id, nullptr)); + return nullptr; + } + if(!json_root.IsObject()) { - fprintf(stderr, "Failed to get message by id %s, error: %s\n", event_id.c_str(), err_msg.c_str()); + fprintf(stderr, "Failed to get message by id %s\n", event_id.c_str()); room->fetched_messages_by_event_id.insert(std::make_pair(event_id, nullptr)); return nullptr; } -- cgit v1.2.3