aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-17 19:46:31 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-17 19:46:31 +0200
commitc903b63a470279525cfe87fbbcefce36986de387 (patch)
treee353d6cf98568ca4b5823f5f81fa52d3c5c6b8c4
parent12cdc09759edf506fbafe051895343b20a67798c (diff)
Matrix: use cached joined_rooms instead of calling to server. Construct doesn't seem to implement /joined_rooms
-rw-r--r--src/plugins/Matrix.cpp33
1 files changed, 3 insertions, 30 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index f9bfe30..5dfd1d1 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -137,37 +137,10 @@ namespace QuickMedia {
}
PluginResult Matrix::get_joined_rooms(Rooms &rooms) {
- std::vector<CommandArg> additional_args = {
- { "-H", "Authorization: Bearer " + access_token }
- };
-
- rapidjson::Document json_root;
- DownloadResult download_result = download_json(json_root, homeserver + "/_matrix/client/r0/joined_rooms", std::move(additional_args), true);
- if(download_result != DownloadResult::OK) return download_result_to_plugin_result(download_result);
-
- if(!json_root.IsObject())
- return PluginResult::ERR;
-
- const rapidjson::Value &joined_rooms_json = GetMember(json_root, "joined_rooms");
- if(!joined_rooms_json.IsArray())
- return PluginResult::ERR;
-
- for(const rapidjson::Value &room_id_json : joined_rooms_json.GetArray()) {
- if(!room_id_json.IsString())
- continue;
-
- std::string room_id_str = room_id_json.GetString();
- auto room = get_room_by_id(room_id_str);
- if(!room) {
- room = std::make_shared<RoomData>();
- room->id = room_id_json.GetString();
- add_room(std::move(room));
- fprintf(stderr, "Missing room %s from /sync, adding in joined_rooms\n", room_id_str.c_str());
- }
-
- rooms.push_back(room);
+ std::lock_guard<std::mutex> lock(room_data_mutex);
+ for(auto &it : room_data_by_id) {
+ rooms.push_back(it.second);
}
-
return PluginResult::OK;
}