aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-11-04 17:40:18 +0100
committerdec05eba <dec05eba@protonmail.com>2020-11-04 17:40:18 +0100
commit3dad7a548751b43b0e06e3bd6e869feec4c500f0 (patch)
tree65da48fc1ccc79ae8f4badae48b7ff6dbe009e7c /src
parentab81d68d7e9a8624dae1d5ad879f67aebb211069 (diff)
Matrix: do not post filter on first sync, show loading animation if sync cache is removed without login
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp63
-rw-r--r--src/plugins/Matrix.cpp30
2 files changed, 30 insertions, 63 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 1ef6025..7ff05cf 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -840,21 +840,6 @@ namespace QuickMedia {
body_size = sf::Vector2f(body_width, window_size.y - search_bottom - body_padding_vertical - tab_h);
}
- static const float RELATED_MEDIA_WINDOW_WIDTH = 1.0f;
- static void get_related_media_body_dimensions(const sf::Vector2f &window_size, sf::Vector2f &body_pos, sf::Vector2f &body_size, float related_videos_text_height) {
- float body_padding_horizontal = 25.0f;
- float body_padding_vertical = 25.0f;
- float body_width = (window_size.x * RELATED_MEDIA_WINDOW_WIDTH) - body_padding_horizontal * 2.0f;
- if(body_width <= 480.0f) {
- body_width = (window_size.x * RELATED_MEDIA_WINDOW_WIDTH);
- body_padding_horizontal = 0.0f;
- body_padding_vertical = 10.0f;
- }
-
- body_pos = sf::Vector2f(body_padding_horizontal, body_padding_vertical + related_videos_text_height);
- body_size = sf::Vector2f(body_width, window_size.y - body_padding_vertical - related_videos_text_height);
- }
-
bool Program::is_tor_enabled() {
return use_tor;
}
@@ -3010,8 +2995,6 @@ namespace QuickMedia {
window.draw(status_text);
window.display();
}
-
- is_login_sync = true;
}
struct ChatTab {
@@ -4335,57 +4318,19 @@ namespace QuickMedia {
auto matrix_invites_page = std::make_unique<MatrixInvitesPage>(this, matrix, invites_body.get());
MatrixQuickMedia matrix_handler(this, matrix, matrix_rooms_page.get(), matrix_rooms_tag_page.get(), matrix_invites_page.get());
- matrix->start_sync(&matrix_handler);
+ bool sync_cached = false;
+ matrix->start_sync(&matrix_handler, sync_cached);
+ is_login_sync = !sync_cached;
std::vector<Tab> tabs;
tabs.push_back(Tab{std::move(rooms_body), std::move(matrix_rooms_page), std::move(matrix_rooms_page_search_bar)});
tabs.push_back(Tab{std::move(rooms_tags_body), std::move(matrix_rooms_tag_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
tabs.push_back(Tab{std::move(invites_body), std::move(matrix_invites_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
- sf::Event event;
- std::string sync_err_msg;
-#if 0
- while(window.isOpen()) {
- if(matrix->is_initial_sync_finished())
- break;
- else if(matrix->did_initial_sync_fail(sync_err_msg)) {
- show_notification("QuickMedia", "Initial sync failed, reason: " + sync_err_msg, Urgency::CRITICAL);
- matrix->stop_sync();
- matrix->logout();
- // TODO: Instead of doing this, exit this current function and navigate to chat login page instead.
- //delete current_plugin;
- //current_plugin = new Matrix();
- current_page = PageType::CHAT_LOGIN;
- chat_login_page();
- if(current_page == PageType::CHAT)
- after_matrix_login_page();
- exit(0);
- break;
- }
-
- while(window.pollEvent(event)) {
- if(event.type == sf::Event::Closed)
- window.close();
- else if(event.type == sf::Event::Resized) {
- window_size.x = event.size.width;
- window_size.y = event.size.height;
- sf::FloatRect visible_area(0, 0, window_size.x, window_size.y);
- window.setView(sf::View(visible_area));
- } else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
- window.close();
- }
- }
-
- window.clear(back_color);
- load_sprite.setPosition(window_size.x * 0.5f, window_size.y * 0.5f);
- load_sprite.setRotation(load_sprite_timer.getElapsedTime().asSeconds() * 400.0);
- window.draw(load_sprite);
- window.display();
- }
-#endif
while(window.isOpen()) {
page_loop(tabs);
}
+
matrix->stop_sync();
}
}
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<CommandArg> 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));