From 75e088746dbf3ab4cafd5ac16890b134d4b19d2a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 17 Oct 2020 23:30:16 +0200 Subject: Matrix: update room list when joining a room (in another client) without restarting, and set sync retry to 1 sec instead of 50ms --- src/plugins/Matrix.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/plugins/Matrix.cpp') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 5dfd1d1..5cf4611 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -136,12 +136,11 @@ namespace QuickMedia { return PluginResult::OK; } - PluginResult Matrix::get_joined_rooms(Rooms &rooms) { + void Matrix::get_room_join_updates(Rooms &new_rooms) { std::lock_guard lock(room_data_mutex); - for(auto &it : room_data_by_id) { - rooms.push_back(it.second); - } - return PluginResult::OK; + new_rooms.insert(new_rooms.end(), rooms.begin() + room_list_read_index, rooms.end()); + size_t num_new_rooms = rooms.size() - room_list_read_index; + room_list_read_index += num_new_rooms; } PluginResult Matrix::get_all_synced_room_messages(std::shared_ptr room, Messages &messages) { @@ -1368,6 +1367,7 @@ namespace QuickMedia { return PluginResult::NET_ERR; // Make sure all fields are reset here! + rooms.clear(); room_data_by_id.clear(); user_id.clear(); username.clear(); @@ -1605,12 +1605,13 @@ namespace QuickMedia { auto room_it = room_data_by_id.find(id); if(room_it == room_data_by_id.end()) return nullptr; - return room_it->second; + return rooms[room_it->second]; } void Matrix::add_room(std::shared_ptr room) { std::lock_guard lock(room_data_mutex); - room_data_by_id.insert(std::make_pair(room->id, room)); + room_data_by_id.insert(std::make_pair(room->id, rooms.size())); + rooms.push_back(room); } DownloadResult Matrix::download_json(rapidjson::Document &result, const std::string &url, std::vector additional_args, bool use_browser_useragent, std::string *err_msg) const { -- cgit v1.2.3