aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-17 23:30:16 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-17 23:30:16 +0200
commit75e088746dbf3ab4cafd5ac16890b134d4b19d2a (patch)
treebabd67fbcbeb1f51dc9965ef1153d7b8a8c9833b /src
parentc903b63a470279525cfe87fbbcefce36986de387 (diff)
Matrix: update room list when joining a room (in another client) without restarting, and set sync retry to 1 sec instead of 50ms
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp14
-rw-r--r--src/plugins/Matrix.cpp15
2 files changed, 11 insertions, 18 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 4f2fa99..c533186 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3800,22 +3800,14 @@ namespace QuickMedia {
if(!sync_running && sync_timer.getElapsedTime().asMilliseconds() >= sync_min_time_ms) {
fprintf(stderr, "Time since last sync: %d ms\n", sync_timer.getElapsedTime().asMilliseconds());
- // TODO: What if the server just always responds immediately?
- sync_min_time_ms = 50;
+ sync_min_time_ms = 1000;
sync_running = true;
sync_timer.restart();
- sync_future = std::async(std::launch::async, [this, synced]() {
+ sync_future = std::async(std::launch::async, [this]() {
SyncFutureResult result;
if(matrix->sync(result.room_sync_messages) == PluginResult::OK) {
fprintf(stderr, "Synced matrix\n");
-
- if(!synced) {
- if(matrix->get_joined_rooms(result.rooms) != PluginResult::OK) {
- show_notification("QuickMedia", "Failed to get a list of joined rooms", Urgency::CRITICAL);
- current_page = PageType::EXIT;
- return result;
- }
- }
+ matrix->get_room_join_updates(result.rooms);
} else {
fprintf(stderr, "Failed to sync matrix\n");
}
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<std::mutex> 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<RoomData> 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<RoomData> room) {
std::lock_guard<std::mutex> 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<CommandArg> additional_args, bool use_browser_useragent, std::string *err_msg) const {