diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-11-01 23:39:40 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-11-01 23:39:40 +0100 |
commit | 7045953e428076b0f07dc8043a5a1a0ac3d4bec5 (patch) | |
tree | f24971207e05d0b4691414e20009a254763fb25e /src | |
parent | 4262ae6c87b4c11f7fe958a91fdd3333a8c5138c (diff) |
Matrix: do not show notification for cache sync messages
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/Matrix.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
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<std::mutex> 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<Message> Matrix::parse_message_event(const rapidjson::Value &event_item_json, RoomData *room_data) { |