aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Matrix.hpp6
-rw-r--r--src/plugins/Matrix.cpp23
2 files changed, 19 insertions, 10 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 6af1bb8..903215b 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -183,7 +183,7 @@ namespace QuickMedia {
virtual void room_add_tag(RoomData *room, const std::string &tag) = 0;
// Note: calling |room| methods inside this function is not allowed
virtual void room_remove_tag(RoomData *room, const std::string &tag) = 0;
- virtual void room_add_new_messages(RoomData *room, const Messages &messages, bool is_initial_sync) = 0;
+ virtual void room_add_new_messages(RoomData *room, const Messages &messages, bool is_initial_sync, bool sync_is_cache) = 0;
virtual void add_invite(const std::string &room_id, const Invite &invite) = 0;
virtual void remove_invite(const std::string &room_id) = 0;
@@ -207,7 +207,7 @@ namespace QuickMedia {
void leave_room(RoomData *room, LeaveType leave_type, const std::string &reason) override;
void room_add_tag(RoomData *room, const std::string &tag) override;
void room_remove_tag(RoomData *room, const std::string &tag) override;
- void room_add_new_messages(RoomData *room, const Messages &messages, bool is_initial_sync) override;
+ void room_add_new_messages(RoomData *room, const Messages &messages, bool is_initial_sync, bool sync_is_cache) override;
void add_invite(const std::string &room_id, const Invite &invite) override;
void remove_invite(const std::string &room_id) override;
@@ -227,6 +227,7 @@ namespace QuickMedia {
struct RoomMessagesData {
Messages messages;
bool is_initial_sync;
+ bool sync_is_cache;
};
std::map<RoomData*, std::shared_ptr<BodyItem>> room_body_item_by_room;
@@ -464,6 +465,7 @@ namespace QuickMedia {
std::thread sync_thread;
bool sync_running = false;
bool sync_failed = false;
+ bool sync_is_cache = false;
std::string sync_fail_reason;
MatrixDelegate *delegate = nullptr;
};
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) {