aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Matrix.hpp4
-rw-r--r--src/plugins/Matrix.cpp26
2 files changed, 22 insertions, 8 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 2fb0d86..bae6e40 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -496,10 +496,10 @@ namespace QuickMedia {
bool use_tor = false;
private:
- PluginResult parse_sync_response(const rapidjson::Document &root, bool is_additional_messages_sync);
+ PluginResult parse_sync_response(const rapidjson::Document &root, bool is_additional_messages_sync, bool initial_sync);
PluginResult parse_notifications(const rapidjson::Value &notifications_json);
PluginResult parse_sync_account_data(const rapidjson::Value &account_data_json, std::optional<std::set<std::string>> &dm_rooms);
- PluginResult parse_sync_room_data(const rapidjson::Value &rooms_json, bool is_additional_messages_sync);
+ PluginResult parse_sync_room_data(const rapidjson::Value &rooms_json, bool is_additional_messages_sync, bool initial_sync);
PluginResult get_previous_room_messages(RoomData *room_data, bool latest_messages, size_t &num_new_messages);
void events_add_user_info(const rapidjson::Value &events_json, RoomData *room_data);
std::shared_ptr<UserInfo> parse_user_info(const rapidjson::Value &json, const std::string &user_id, RoomData *room_data);
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;
}