From 3f9185ad357fb70138d3ea301cd9ac0ee0de0704 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 16 Oct 2020 23:45:05 +0200 Subject: Matrix: use room object instead of room id --- plugins/Matrix.hpp | 53 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'plugins/Matrix.hpp') diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index 09895b0..8d078a0 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -41,7 +41,15 @@ namespace QuickMedia { IMAGE, VIDEO, AUDIO, - FILE + FILE, + REDACTION + }; + + enum class RelatedEventType { + NONE, + REPLY, + EDIT, + REDACTION }; struct Message { @@ -50,7 +58,8 @@ namespace QuickMedia { std::string body; std::string url; std::string thumbnail_url; - std::string replaces_event_id; + std::string related_event_id; + RelatedEventType related_event_type; bool mentions_me = false; time_t timestamp = 0; MessageType type; @@ -63,10 +72,10 @@ namespace QuickMedia { void set_user_read_marker(std::shared_ptr &user, const std::string &event_id); std::string get_user_read_marker(std::shared_ptr &user); - // Ignores duplicates, returns the number of inserted elements - size_t prepend_messages_reverse(std::vector> new_messages); - // Ignores duplicates, returns the number of inserted elements - size_t append_messages(std::vector> new_messages); + // Ignores duplicates + void prepend_messages_reverse(std::vector> new_messages); + // Ignores duplicates + void append_messages(std::vector> new_messages); std::shared_ptr get_message_by_id(const std::string &id); @@ -82,7 +91,6 @@ namespace QuickMedia { std::string avatar_url; std::string prev_batch; bool initial_fetch_finished = false; - size_t last_read_index = 0; private: std::mutex user_mutex; std::mutex room_mutex; @@ -106,37 +114,38 @@ namespace QuickMedia { std::string content_uri; }; - using RoomSyncMessages = std::unordered_map, std::vector>>; + using Messages = std::vector>; + using RoomSyncMessages = std::unordered_map, Messages>; + using Rooms = std::vector>; class Matrix { public: PluginResult sync(RoomSyncMessages &room_messages); - PluginResult get_joined_rooms(BodyItems &result_items); - PluginResult get_all_synced_room_messages(const std::string &room_id, BodyItems &result_items); - PluginResult get_new_room_messages(const std::string &room_id, BodyItems &result_items); - PluginResult get_previous_room_messages(const std::string &room_id, BodyItems &result_items); + PluginResult get_joined_rooms(Rooms &rooms); + PluginResult get_all_synced_room_messages(std::shared_ptr room, Messages &messages); + PluginResult get_previous_room_messages(std::shared_ptr room, Messages &messages); // |url| should only be set when uploading media. // TODO: Make api better. - PluginResult post_message(const std::string &room_id, const std::string &body, const std::optional &file_info, const std::optional &thumbnail_info); + PluginResult post_message(std::shared_ptr room, const std::string &body, const std::optional &file_info, const std::optional &thumbnail_info); // |relates_to| is from |BodyItem.userdata| and is of type |Message*| - PluginResult post_reply(const std::string &room_id, const std::string &body, void *relates_to); + PluginResult post_reply(std::shared_ptr room, const std::string &body, void *relates_to); // |relates_to| is from |BodyItem.userdata| and is of type |Message*| - PluginResult post_edit(const std::string &room_id, const std::string &body, void *relates_to); + PluginResult post_edit(std::shared_ptr room, const std::string &body, void *relates_to); - PluginResult post_file(const std::string &room_id, const std::string &filepath, std::string &err_msg); + PluginResult post_file(std::shared_ptr room, const std::string &filepath, std::string &err_msg); PluginResult login(const std::string &username, const std::string &password, const std::string &homeserver, std::string &err_msg); PluginResult logout(); // |message| is from |BodyItem.userdata| and is of type |Message*| - PluginResult delete_message(const std::string &room_id, void *message, std::string &err_msg); + PluginResult delete_message(std::shared_ptr room, void *message, std::string &err_msg); PluginResult load_and_verify_cached_session(); - PluginResult on_start_typing(const std::string &room_id); - PluginResult on_stop_typing(const std::string &room_id); + PluginResult on_start_typing(std::shared_ptr room); + PluginResult on_stop_typing(std::shared_ptr room); - PluginResult set_read_marker(const std::string &room_id, const Message *message); + PluginResult set_read_marker(std::shared_ptr room, const Message *message); // |message| is from |BodyItem.userdata| and is of type |Message*| bool was_message_posted_by_me(void *message); @@ -146,7 +155,7 @@ namespace QuickMedia { // Cached PluginResult get_config(int *upload_size); - std::shared_ptr get_me(const std::string &room_id); + std::shared_ptr get_me(std::shared_ptr room); bool use_tor = false; private: @@ -156,7 +165,7 @@ namespace QuickMedia { void events_add_user_read_markers(const rapidjson::Value &events_json, RoomData *room_data); void events_add_messages(const rapidjson::Value &events_json, std::shared_ptr &room_data, MessageDirection message_dir, RoomSyncMessages *room_messages, bool has_unread_notifications); void events_set_room_name(const rapidjson::Value &events_json, RoomData *room_data); - PluginResult upload_file(const std::string &room_id, const std::string &filepath, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg); + PluginResult upload_file(std::shared_ptr room, const std::string &filepath, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg); std::shared_ptr get_edited_message_original_message(RoomData *room_data, std::shared_ptr message); -- cgit v1.2.3