aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Matrix.hpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 6a876d0..6af1bb8 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -189,6 +189,8 @@ namespace QuickMedia {
virtual void remove_invite(const std::string &room_id) = 0;
virtual void update(MatrixPageType page_type) { (void)page_type; }
+
+ virtual void clear_data() = 0;
};
class Matrix;
@@ -212,6 +214,8 @@ namespace QuickMedia {
void update(MatrixPageType page_type) override;
+ void clear_data() override;
+
Program *program;
Matrix *matrix;
MatrixRoomsPage *rooms_page;
@@ -226,6 +230,7 @@ namespace QuickMedia {
};
std::map<RoomData*, std::shared_ptr<BodyItem>> room_body_item_by_room;
+ std::mutex room_body_items_mutex;
std::map<RoomData*, RoomMessagesData> pending_room_messages;
std::mutex pending_room_messages_mutex;
};
@@ -246,15 +251,18 @@ namespace QuickMedia {
void set_current_chat_page(MatrixChatPage *chat_page);
+ void clear_data();
+
MatrixQuickMedia *matrix_delegate = nullptr;
private:
std::mutex mutex;
std::vector<std::shared_ptr<BodyItem>> room_body_items;
std::vector<std::string> pending_remove_body_items;
- Body *body;
+ Body *body = nullptr;
std::string title;
- MatrixRoomTagsPage *room_tags_page;
- MatrixChatPage *current_chat_page;
+ MatrixRoomTagsPage *room_tags_page = nullptr;
+ MatrixChatPage *current_chat_page = nullptr;
+ bool clear_data_on_update = false;
};
class MatrixRoomTagsPage : public Page {
@@ -272,6 +280,8 @@ namespace QuickMedia {
void set_current_rooms_page(MatrixRoomsPage *rooms_page);
+ void clear_data();
+
MatrixQuickMedia *matrix_delegate = nullptr;
private:
struct TagData {
@@ -285,6 +295,7 @@ namespace QuickMedia {
std::map<std::string, std::vector<std::shared_ptr<BodyItem>>> add_room_body_items_by_tags;
std::map<std::string, std::vector<std::shared_ptr<BodyItem>>> remove_room_body_items_by_tags;
MatrixRoomsPage *current_rooms_page = nullptr;
+ bool clear_data_on_update = false;
};
class MatrixInvitesPage : public Page {
@@ -297,6 +308,8 @@ namespace QuickMedia {
void update() override;
void add_body_item(std::shared_ptr<BodyItem> body_item);
void remove_body_item_by_room_id(const std::string &room_id);
+
+ void clear_data();
private:
Matrix *matrix;
std::mutex mutex;
@@ -305,6 +318,7 @@ namespace QuickMedia {
Body *body;
std::string title = "Invites (0)";
size_t prev_invite_count = 0;
+ bool clear_data_on_update = false;
};
class MatrixInviteDetailsPage : public Page {
@@ -352,6 +366,7 @@ namespace QuickMedia {
const std::string room_id;
MatrixQuickMedia *matrix_delegate = nullptr;
MatrixRoomsPage *rooms_page = nullptr;
+ bool should_clear_data = false;
};
class Matrix {
@@ -359,6 +374,8 @@ namespace QuickMedia {
void start_sync(MatrixDelegate *delegate);
void stop_sync();
bool is_initial_sync_finished() const;
+ // Returns true if initial sync failed, and |err_msg| is set to the error reason in that case
+ bool did_initial_sync_fail(std::string &err_msg);
void get_room_sync_data(RoomData *room, SyncData &sync_data);
void get_all_synced_room_messages(RoomData *room, Messages &messages);
@@ -380,7 +397,7 @@ namespace QuickMedia {
// |message| is from |BodyItem.userdata| and is of type |Message*|
PluginResult delete_message(RoomData *room, void *message, std::string &err_msg);
- PluginResult load_and_verify_cached_session();
+ PluginResult load_cached_session();
PluginResult on_start_typing(RoomData *room);
PluginResult on_stop_typing(RoomData *room);
@@ -426,23 +443,28 @@ namespace QuickMedia {
void set_invite(const std::string &room_id, Invite invite);
// Returns true if an invite for |room_id| exists
bool remove_invite(const std::string &room_id);
+ void set_next_batch(std::string new_next_batch);
+ std::string get_next_batch();
+ void clear_sync_cache_for_new_sync();
DownloadResult download_json(rapidjson::Document &result, const std::string &url, std::vector<CommandArg> additional_args, bool use_browser_useragent = false, std::string *err_msg = nullptr) const;
private:
std::vector<std::unique_ptr<RoomData>> rooms;
std::unordered_map<std::string, size_t> room_data_by_id; // value is an index into |rooms|
std::recursive_mutex room_data_mutex;
std::string user_id;
- std::string username;
std::string access_token;
std::string homeserver;
std::optional<int> upload_limit;
std::string next_batch;
+ std::mutex next_batch_mutex;
std::unordered_map<std::string, Invite> invites;
std::mutex invite_mutex;
std::thread sync_thread;
bool sync_running = false;
+ bool sync_failed = false;
+ std::string sync_fail_reason;
MatrixDelegate *delegate = nullptr;
};
} \ No newline at end of file