From c903b63a470279525cfe87fbbcefce36986de387 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 17 Oct 2020 19:46:31 +0200 Subject: Matrix: use cached joined_rooms instead of calling to server. Construct doesn't seem to implement /joined_rooms --- src/plugins/Matrix.cpp | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) (limited to 'src/plugins') 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 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(); - 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 lock(room_data_mutex); + for(auto &it : room_data_by_id) { + rooms.push_back(it.second); } - return PluginResult::OK; } -- cgit v1.2.3