aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-12-09 23:43:12 +0100
committerdec05eba <dec05eba@protonmail.com>2022-12-09 23:43:12 +0100
commit17f74130a93d5b5eb9fb33e453670e7247494104 (patch)
tree37571bbb0bdb4e5dd31e57bd5dc710f124515d06 /src/QuickMedia.cpp
parent49e8081794b50a2b05d9d3b78860e34659ade3fc (diff)
Matrix: continue from cache instead of initial sync everytime. Mainly improves pantalaimon sync speed
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp80
1 files changed, 20 insertions, 60 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 2c40580..0e9f152 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -39,6 +39,7 @@
#include "../include/Downloader.hpp"
#include "../include/Storage.hpp"
#include "../include/AsyncImageLoader.hpp"
+#include "../plugins/utils/UniqueProcess.hpp"
#include <mglpp/system/FloatRect.hpp>
#include "../include/gui/Button.hpp"
#include "../external/hash-library/sha256.h"
@@ -407,7 +408,7 @@ namespace QuickMedia {
video_max_height = 0;
std::vector<Tab> tabs;
const char *url = nullptr;
- std::string program_path = dirname(argv[0]);
+ std::string program_path = Path(argv[0]).parent().data;
std::string instance;
std::string download_filename;
bool no_dialog = false;
@@ -633,7 +634,7 @@ namespace QuickMedia {
chat_login_page();
}
after_matrix_login_page();
- return exit_code;
+ goto done;
}
page_loop(tabs, start_tab_index);
@@ -650,6 +651,10 @@ namespace QuickMedia {
}
}
+ done:
+ if(plugin_name && strcmp(plugin_name, "matrix") == 0)
+ remove_quickmedia_instance_lock(get_cache_dir().join("matrix").data.c_str(), "matrix");
+
return exit_code;
}
@@ -1327,7 +1332,7 @@ namespace QuickMedia {
page_stack.push(current_page);
current_page = PageType::IMAGE_BOARD_THREAD;
image_board_thread_page(thread_page.get(), body.get());
- exit(0);
+ exit(exit_code);
} else {
auto boards_page = std::make_unique<FourchanBoardsPage>(this, resources_root);
FourchanBoardsPage *boards_page_ptr = boards_page.get();
@@ -1424,10 +1429,22 @@ namespace QuickMedia {
tabs.push_back(Tab{create_body(false, true), std::make_unique<LbrySearchPage>(this), create_search_bar("Search...", 500)});
} else if(strcmp(plugin_name, "matrix") == 0) {
assert(!matrix);
+
if(create_directory_recursive(get_cache_dir().join("matrix").join("events")) != 0) {
show_notification("QuickMedia", "Failed to create events cache directory", Urgency::CRITICAL);
abort();
}
+
+ if(is_quickmedia_instance_already_running(get_cache_dir().join("matrix").data.c_str(), "matrix")) {
+ show_notification("QuickMedia", "Only one instance of matrix can be run. Change $XDG_CACHE_HOME if you want to run multiple instances", Urgency::CRITICAL);
+ exit(exit_code);
+ }
+
+ if(!set_quickmedia_instance_unique(get_cache_dir().join("matrix").data.c_str(), "matrix")) {
+ show_notification("QuickMedia", "Failed to set quickmedia process as unique", Urgency::CRITICAL);
+ exit(exit_code);
+ }
+
matrix = new Matrix();
} else {
assert(false);
@@ -7872,63 +7889,6 @@ namespace QuickMedia {
tabs[selected_tab].body->on_bottom_reached();
}
- if(matrix_chat_page->should_clear_data) {
- matrix_chat_page->should_clear_data = false;
-
- std::string err_msg;
- while(!matrix->is_initial_sync_finished()) {
- std::this_thread::sleep_for(std::chrono::milliseconds(10));
- if(matrix->did_initial_sync_fail(err_msg)) {
- matrix_chat_page->set_current_room(nullptr, nullptr, nullptr);
- fetch_messages_future.cancel();
- cleanup_tasks();
- tabs.clear();
- unreferenced_events.clear();
- unresolved_reactions.clear();
- all_messages.clear();
- show_notification("QuickMedia", "Initial matrix sync failed, error: " + err_msg, Urgency::CRITICAL);
- matrix->logout();
- delete matrix;
- matrix = new Matrix();
- current_page = PageType::CHAT_LOGIN;
- chat_login_page();
- after_matrix_login_page();
- window.close();
- goto chat_page_end;
- }
- }
-
- //all_messages.clear();
-
- tabs[MESSAGES_TAB_INDEX].body->clear_items();
-
- Messages all_messages_new;
- matrix->get_all_synced_room_messages(current_room, all_messages_new);
- for(auto &message : all_messages_new) {
- fetched_messages_set.insert(message->event_id);
- }
- all_messages.insert(all_messages.end(), all_messages_new.begin(), all_messages_new.end());
- //me = matrix->get_me(current_room);
- filter_provisional_messages(all_messages_new);
- add_new_messages_to_current_room(all_messages_new);
- modify_related_messages_in_current_room(all_messages_new);
- unresolved_reactions.clear();
- after_token.clear();
- before_token.clear(),
- fetched_enough_messages_top = false;
- fetched_enough_messages_bottom = false;
- fetch_messages_future.cancel();
- process_reactions(all_messages_new);
- if(current_room->initial_prev_messages_fetch) {
- current_room->initial_prev_messages_fetch = false;
- tabs[MESSAGES_TAB_INDEX].body->select_last_item();
- }
-
- std::vector<std::string> pinned_events;
- matrix->get_all_pinned_events(current_room, pinned_events);
- process_pinned_events(std::move(pinned_events));
- }
-
if(go_to_previous_page) {
go_to_previous_page = false;
goto chat_page_end;