From 3dad7a548751b43b0e06e3bd6e869feec4c500f0 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 4 Nov 2020 17:40:18 +0100 Subject: Matrix: do not post filter on first sync, show loading animation if sync cache is removed without login --- src/plugins/Matrix.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/plugins/Matrix.cpp') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 6d0e095..9cfc1bb 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -20,6 +20,7 @@ static const char* SERVICE_NAME = "matrix"; static const char* OTHERS_ROOM_TAG = "tld.name.others"; +// Filter without account data static const char* FILTER = "{\"presence\":{\"limit\":0,\"types\":[\"\"]},\"account_data\":{\"limit\":0,\"types\":[\"\"]},\"room\":{\"state\":{\"not_types\":[\"m.room.related_groups\",\"m.room.power_levels\",\"m.room.join_rules\",\"m.room.history_visibility\"],\"lazy_load_members\":true},\"timeline\":{\"limit\":1,\"lazy_load_members\":true},\"ephemeral\":{\"limit\":0,\"types\":[\"\"],\"lazy_load_members\":true},\"account_data\":{\"limit\":1,\"types\":[\"m.fully_read\",\"m.tag\"],\"lazy_load_members\":true}}}"; static rapidjson::Value nullValue(rapidjson::kNullType); @@ -814,7 +815,8 @@ namespace QuickMedia { } } - void Matrix::start_sync(MatrixDelegate *delegate) { + void Matrix::start_sync(MatrixDelegate *delegate, bool &cached) { + cached = true; if(sync_running) return; @@ -827,13 +829,17 @@ namespace QuickMedia { fprintf(stderr, "Failed to create matrix cache directory\n"); matrix_cache_dir.join("sync_data.json"); + cached = (get_file_type(matrix_cache_dir) == FileType::REGULAR); + sync_is_cache = false; sync_running = true; sync_thread = std::thread([this, matrix_cache_dir]() { sync_is_cache = true; + bool cache_available = false; FILE *sync_cache_file = fopen(matrix_cache_dir.data.c_str(), "rb"); if(sync_cache_file) { + cache_available = true; rapidjson::Document doc; char read_buffer[8192]; rapidjson::FileReadStream is(sync_cache_file, read_buffer, sizeof(read_buffer)); @@ -850,9 +856,20 @@ namespace QuickMedia { // Filter with account data // {"presence":{"limit":0,"types":[""]},"account_data":{"not_types":["im.vector.setting.breadcrumbs","m.push_rules","im.vector.setting.allowed_widgets","io.element.recent_emoji"]},"room":{"state":{"limit":1,"not_types":["m.room.related_groups","m.room.power_levels","m.room.join_rules","m.room.history_visibility"],"lazy_load_members":true},"timeline":{"limit":3,"lazy_load_members":true},"ephemeral":{"limit":0,"types":[""],"lazy_load_members":true},"account_data":{"limit":1,"types":["m.fully_read"],"lazy_load_members":true}}} - // Filter without account data - std::string filter = get_filter_cached(); - const std::string filter_encoded = url_param_encode(filter); + + bool filter_cached = false; + Path filter_path = get_storage_dir().join("matrix").join("filter"); + if(get_file_type(filter_path) == FileType::REGULAR) + filter_cached = true; + + // We dont want to POST filter for initial login sync and instead do it after sync. + // This should improve initial sync by around 600ms + std::string filter; + if(filter_cached) + filter = get_filter_cached(); + else + filter = FILTER; + std::string filter_encoded = url_param_encode(filter); std::vector additional_args = { { "-H", "Authorization: Bearer " + access_token }, @@ -937,6 +954,11 @@ namespace QuickMedia { }); } + if(!filter_cached) { + filter_cached = true; + filter_encoded = url_param_encode(get_filter_cached()); + } + sync_end: if(sync_running) std::this_thread::sleep_for(std::chrono::milliseconds(500)); -- cgit v1.2.3