aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO3
-rw-r--r--plugins/Matrix.hpp6
-rw-r--r--src/QuickMedia.cpp14
-rw-r--r--src/plugins/Matrix.cpp15
4 files changed, 17 insertions, 21 deletions
diff --git a/TODO b/TODO
index 1dcae1f..a93fc58 100644
--- a/TODO
+++ b/TODO
@@ -108,4 +108,5 @@ Show redacted messages even when part of the initial sync in matrix. Right now t
Update displayname/avatar in matrix when updated in /sync.
Fix inconsistent behavior when editing a message that is replied to in matrix. Right now if the replied to message already exits in the body then its used directly and when editing that message the reply message shows the edit embedded, but not if the edit is of an body item that is created because we dont already have it,
to fix this we could perhaps replace the newly created body items for replies when loading old messages and one of the old messages is also one of the embedded messages (by event id).
-Add button to skip to next video. MPV has this feature when setting "next" video (can be done over IPC). \ No newline at end of file
+Add button to skip to next video. MPV has this feature when setting "next" video (can be done over IPC).
+Handle room leave in matrix and remove rooms from the list. \ No newline at end of file
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 3cb974f..135549f 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -128,7 +128,7 @@ namespace QuickMedia {
class Matrix {
public:
PluginResult sync(RoomSyncMessages &room_messages);
- PluginResult get_joined_rooms(Rooms &rooms);
+ void get_room_join_updates(Rooms &new_rooms);
PluginResult get_all_synced_room_messages(std::shared_ptr<RoomData> room, Messages &messages);
PluginResult get_previous_room_messages(std::shared_ptr<RoomData> room, Messages &messages);
@@ -184,7 +184,9 @@ namespace QuickMedia {
void add_room(std::shared_ptr<RoomData> room);
DownloadResult download_json(rapidjson::Document &result, const std::string &url, std::vector<CommandArg> additional_args, bool use_browser_useragent = false, std::string *err_msg = nullptr) const;
private:
- std::unordered_map<std::string, std::shared_ptr<RoomData>> room_data_by_id;
+ std::vector<std::shared_ptr<RoomData>> rooms;
+ std::unordered_map<std::string, size_t> room_data_by_id; // value is an index into |rooms|
+ size_t room_list_read_index = 0;
std::mutex room_data_mutex;
std::string user_id;
std::string username;
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 {