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 --- README.md | 2 -- TODO | 4 ++-- generate-emoji-sprite.py | 35 +++++++++++++++++++++++++++++++++++ images/sprites-small.png | Bin 1566335 -> 0 bytes plugins/Matrix.hpp | 5 +++++ src/QuickMedia.cpp | 5 ++++- src/plugins/Matrix.cpp | 19 +++++++++++++------ 7 files changed, 59 insertions(+), 11 deletions(-) create mode 100755 generate-emoji-sprite.py delete mode 100644 images/sprites-small.png diff --git a/README.md b/README.md index 9319e6f..93144ec 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,6 @@ See project.conf \[dependencies]. `waifu2x-ncnn-vulkan` needs to be installed when using the `--upscale-images` or `--upscale-images-always` option.\ `xdg-utils` which provides `xdg-open` needs to be installed when downloading torrents with `nyaa.si` plugin.\ `ffmpeg (and ffprobe which is included in ffmpeg)` needs to be installed to upload videos with thumbnails on matrix. -## License -QuickMedia is free software licensed under GPL 3.0. See the `LICENSE` file for more information. `images/sprites-small.png` is licensed under CC BY 4.0 and is available at https://github.com/EmojiTwo/emojitwo/ # Screenshots ## Youtube search ![](https://www.dec05eba.com/images/youtube.jpg) diff --git a/TODO b/TODO index 7291a6e..aebc2cd 100644 --- a/TODO +++ b/TODO @@ -96,7 +96,6 @@ Maybe dont clear cache for body items when filtering. Change scroll in body when previous items change size (such as when thumbnail has finished loading). Load and show replied-to message in the pinned messages tab. Pressing enter on a pinned message should go to the message in the messages tab. -Cache pinned messages on disk (messages by event id), but take into consider edits? for example if one message is pinned in the room and then edited multiple times (such as room rules). In that case cache the pinned message to quickly display it and then fetch the latest version from the server and then replace the message with the latest version. Display file list for nyaa. Remove reply formatting for NOTICE in matrix as well. Scroll body when adding new items and the selected item fits after the scroll (needed for matrix where we want to see new messages when the last item is not selected). Or show the last item when its not visible in matrix (at the bottom, just like when replying/editing). @@ -136,4 +135,5 @@ then add a gap between old messages from before sync and after sync so we can fe Fetching of previous messages should also be saved in the /sync file and messages fetched with get_message_by_id, which would cache embedded items and pinned messages; also cache users. If manga page fails to download then show "failed to download image" as text and bind F5 to refresh (retry download). Use user; std::string event_id; 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