From ceddf6d67b43a99c774132baf099f4a58daa613e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 16 Nov 2022 00:49:15 +0100 Subject: Matrix: fix read marker when running multiple instances of quickmedia on the same account at the same time --- src/plugins/Matrix.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index ec883df..186be72 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -5189,9 +5189,14 @@ namespace QuickMedia { PluginResult Matrix::set_qm_last_read_message_timestamp(RoomData *room, int64_t timestamp) { rapidjson::Document request_data(rapidjson::kObjectType); - qm_read_markers_by_room_cache[room->id] = timestamp; - for(const auto &[key, val] : qm_read_markers_by_room_cache) { - request_data.AddMember(rapidjson::Value(key.c_str(), request_data.GetAllocator()).Move(), val, request_data.GetAllocator()); + { + std::lock_guard lock(room_data_mutex); + load_qm_read_markers_from_account_data(); // TODO: Only do this if multiple instances of quickmedia matrix is running (on the same account) + qm_read_markers_by_room_cache[room->id] = timestamp; + room->read_marker_event_timestamp = timestamp; + for(const auto &[key, val] : qm_read_markers_by_room_cache) { + request_data.AddMember(rapidjson::Value(key.c_str(), request_data.GetAllocator()).Move(), val, request_data.GetAllocator()); + } } rapidjson::StringBuffer buffer; @@ -5210,8 +5215,6 @@ namespace QuickMedia { if(download_result != DownloadResult::OK) return download_result_to_plugin_result(download_result); - room->read_marker_event_timestamp = timestamp; - qm_read_markers_by_room_cache[room->id] = timestamp; return PluginResult::OK; } @@ -5232,8 +5235,8 @@ namespace QuickMedia { if(!json_root.IsObject()) return; - qm_read_markers_by_room_cache.clear(); std::lock_guard lock(room_data_mutex); + qm_read_markers_by_room_cache.clear(); for(auto const &obj : json_root.GetObject()) { if(!obj.name.IsString() || !obj.value.IsInt64()) continue; -- cgit v1.2.3