aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-12-10 01:47:43 +0100
committerdec05eba <dec05eba@protonmail.com>2022-12-10 01:47:43 +0100
commit333ad96a703668f5a1392ee38b739bf393907221 (patch)
tree482d9127239e657fdff94f8636fd09a9e8c8be3b /src/QuickMedia.cpp
parent247d83b1eaa64dd28900f90763dd02e71d5bd3f6 (diff)
Revert matrix sync changes until tabs are added
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp80
1 files changed, 60 insertions, 20 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 0e9f152..2c40580 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -39,7 +39,6 @@
#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"
@@ -408,7 +407,7 @@ namespace QuickMedia {
video_max_height = 0;
std::vector<Tab> tabs;
const char *url = nullptr;
- std::string program_path = Path(argv[0]).parent().data;
+ std::string program_path = dirname(argv[0]);
std::string instance;
std::string download_filename;
bool no_dialog = false;
@@ -634,7 +633,7 @@ namespace QuickMedia {
chat_login_page();
}
after_matrix_login_page();
- goto done;
+ return exit_code;
}
page_loop(tabs, start_tab_index);
@@ -651,10 +650,6 @@ 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;
}
@@ -1332,7 +1327,7 @@ namespace QuickMedia {
page_stack.push(current_page);
current_page = PageType::IMAGE_BOARD_THREAD;
image_board_thread_page(thread_page.get(), body.get());
- exit(exit_code);
+ exit(0);
} else {
auto boards_page = std::make_unique<FourchanBoardsPage>(this, resources_root);
FourchanBoardsPage *boards_page_ptr = boards_page.get();
@@ -1429,22 +1424,10 @@ 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);
@@ -7889,6 +7872,63 @@ 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;