From 7045953e428076b0f07dc8043a5a1a0ac3d4bec5 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 1 Nov 2020 23:39:40 +0100 Subject: Matrix: do not show notification for cache sync messages --- src/plugins/Matrix.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index de33c3c..b7f911f 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -267,11 +267,12 @@ namespace QuickMedia { room_tags_page->remove_room_body_item_from_tag(room_body_item_by_room[room], tag); } - void MatrixQuickMedia::room_add_new_messages(RoomData *room, const Messages &messages, bool is_initial_sync) { + void MatrixQuickMedia::room_add_new_messages(RoomData *room, const Messages &messages, bool is_initial_sync, bool sync_is_cache) { std::lock_guard lock(pending_room_messages_mutex); auto &room_messages_data = pending_room_messages[room]; room_messages_data.messages.insert(room_messages_data.messages.end(), messages.begin(), messages.end()); room_messages_data.is_initial_sync = is_initial_sync; + room_messages_data.sync_is_cache = sync_is_cache; } void MatrixQuickMedia::add_invite(const std::string &room_id, const Invite &invite) { @@ -345,12 +346,14 @@ namespace QuickMedia { //std::string room_desc = matrix->message_get_author_displayname(it.second.back().get()) + ": " + extract_first_line_elipses(it.second.back()->body, 150); //room_body_item->set_description(std::move(room_desc)); - for(auto &message : messages) { - if(message->mentions_me) { - room->has_unread_mention = true; - // TODO: What if the message or username begins with "-"? also make the notification image be the avatar of the user - if(! is_window_focused || room != current_room || is_initial_sync || page_type == MatrixPageType::ROOM_LIST) - show_notification("QuickMedia matrix - " + matrix->message_get_author_displayname(message.get()) + " (" + room->get_name() + ")", message->body); + if(!it.second.sync_is_cache) { + for(auto &message : messages) { + if(message->mentions_me) { + room->has_unread_mention = true; + // TODO: What if the message or username begins with "-"? also make the notification image be the avatar of the user + if(!is_window_focused || room != current_room || is_initial_sync || page_type == MatrixPageType::ROOM_LIST) + show_notification("QuickMedia matrix - " + matrix->message_get_author_displayname(message.get()) + " (" + room->get_name() + ")", message->body); + } } } @@ -769,8 +772,11 @@ namespace QuickMedia { fprintf(stderr, "Failed to create matrix cache directory\n"); matrix_cache_dir.join("sync_data.json"); + sync_is_cache = false; sync_running = true; + sync_thread = std::thread([this, delegate, matrix_cache_dir]() { + sync_is_cache = true; FILE *sync_cache_file = fopen(matrix_cache_dir.data.c_str(), "rb"); if(sync_cache_file) { rapidjson::Document doc; @@ -785,6 +791,7 @@ namespace QuickMedia { } fclose(sync_cache_file); } + sync_is_cache = false; const rapidjson::Value *next_batch_json; PluginResult result; @@ -1354,7 +1361,7 @@ namespace QuickMedia { } if(delegate) - delegate->room_add_new_messages(room_data, new_messages, next_batch.empty()); + delegate->room_add_new_messages(room_data, new_messages, next_batch.empty(), sync_is_cache); } std::shared_ptr Matrix::parse_message_event(const rapidjson::Value &event_item_json, RoomData *room_data) { -- cgit v1.2.3