aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 95ce1dc..ffe28c2 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -989,7 +989,7 @@ namespace QuickMedia {
rapidjson::ParseResult parse_result = doc.ParseStream<rapidjson::kParseStopWhenDoneFlag>(is);
if(parse_result.IsError())
break;
- if(parse_sync_response(doc, false) != PluginResult::OK)
+ if(parse_sync_response(doc, false, false) != PluginResult::OK)
fprintf(stderr, "Failed to parse cached sync response\n");
}
fclose(sync_cache_file);
@@ -1043,7 +1043,7 @@ namespace QuickMedia {
// clear_sync_cache_for_new_sync();
additional_messages_queue.pop_wait();
- parse_sync_response(json_root, true);
+ parse_sync_response(json_root, true, false);
});
const rapidjson::Value *next_batch_json;
@@ -1086,7 +1086,7 @@ namespace QuickMedia {
if(next_batch.empty())
clear_sync_cache_for_new_sync();
- result = parse_sync_response(json_root, false);
+ result = parse_sync_response(json_root, false, initial_sync);
if(result != PluginResult::OK) {
fprintf(stderr, "Failed to parse sync response\n");
goto sync_end;
@@ -1243,7 +1243,7 @@ namespace QuickMedia {
return PluginResult::OK;
}
- PluginResult Matrix::parse_sync_response(const rapidjson::Document &root, bool is_additional_messages_sync) {
+ PluginResult Matrix::parse_sync_response(const rapidjson::Document &root, bool is_additional_messages_sync, bool initial_sync) {
if(!root.IsObject())
return PluginResult::ERR;
@@ -1253,7 +1253,7 @@ namespace QuickMedia {
// TODO: Include "Direct messages" as a tag using |dm_rooms| above
const rapidjson::Value &rooms_json = GetMember(root, "rooms");
- parse_sync_room_data(rooms_json, is_additional_messages_sync);
+ parse_sync_room_data(rooms_json, is_additional_messages_sync, initial_sync);
return PluginResult::OK;
}
@@ -1351,10 +1351,12 @@ namespace QuickMedia {
return PluginResult::OK;
}
- PluginResult Matrix::parse_sync_room_data(const rapidjson::Value &rooms_json, bool is_additional_messages_sync) {
+ PluginResult Matrix::parse_sync_room_data(const rapidjson::Value &rooms_json, bool is_additional_messages_sync, bool initial_sync) {
if(!rooms_json.IsObject())
return PluginResult::OK;
+ std::unordered_set<RoomData*> existing_rooms;
+
const rapidjson::Value &join_json = GetMember(rooms_json, "join");
if(join_json.IsObject()) {
for(auto const &it : join_json.GetObject()) {
@@ -1376,6 +1378,8 @@ namespace QuickMedia {
add_room(std::move(new_room));
is_new_room = true;
}
+ if(initial_sync)
+ existing_rooms.insert(room);
const rapidjson::Value &state_json = GetMember(it.value, "state");
if(state_json.IsObject()) {
@@ -1466,6 +1470,16 @@ namespace QuickMedia {
add_invites(invite_json);
}
+ if(initial_sync) {
+ std::lock_guard<std::recursive_mutex> lock(room_data_mutex);
+ for(auto &room : rooms) {
+ if(existing_rooms.find(room.get()) == existing_rooms.end()) {
+ delegate->leave_room(room.get(), LeaveType::LEAVE, "");
+ remove_room(room->id);
+ }
+ }
+ }
+
return PluginResult::OK;
}