diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Matrix.hpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index 36188f0..bf4ef94 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -25,17 +25,25 @@ namespace QuickMedia { std::string extract_first_line_remove_newline_elipses(const std::string &str, size_t max_length); mgl::Color user_id_to_color(const std::string &user_id); + struct TimestampedDisplayData { + std::string data; + time_t timestamp = 0; // In milliseconds + + // Force update by settings |new_timestamp| to 0 + bool set_data_if_newer(std::string new_data, time_t new_timestamp); + }; + struct UserInfo { friend struct RoomData; UserInfo(RoomData *room, std::string user_id); - UserInfo(RoomData *room, std::string user_id, std::string display_name, std::string avatar_url); + UserInfo(RoomData *room, std::string user_id, std::string display_name, std::string avatar_url, time_t update_timestamp_ms); RoomData *room; const mgl::Color display_name_color; const std::string user_id; private: - std::string display_name; - std::string avatar_url; + TimestampedDisplayData display_name; + TimestampedDisplayData avatar_url; std::string read_marker_event_id; }; @@ -108,8 +116,8 @@ namespace QuickMedia { std::string get_user_avatar_url(const std::shared_ptr<UserInfo> &user); // Set to empty to remove (in which case the display name will be the user id) - void set_user_display_name(std::shared_ptr<UserInfo> &user, std::string display_name); - void set_user_avatar_url(std::shared_ptr<UserInfo> &user, std::string avatar_url); + bool set_user_display_name(std::shared_ptr<UserInfo> &user, std::string display_name, time_t update_timestamp_ms); + bool set_user_avatar_url(std::shared_ptr<UserInfo> &user, std::string avatar_url, time_t update_timestamp_ms); // Ignores duplicates, returns the number of added messages size_t prepend_messages_reverse(const Messages &new_messages); @@ -132,14 +140,14 @@ namespace QuickMedia { std::string get_prev_batch(); bool has_name(); - void set_name(const std::string &new_name); + bool set_name(const std::string &new_name, time_t update_timestamp_ms); // TODO: Remove this std::string get_name(); - void set_topic(const std::string &new_topic); + bool set_topic(const std::string &new_topic, time_t update_timestamp_ms); std::string get_topic(); bool has_avatar_url(); - void set_avatar_url(const std::string &new_avatar_url); + bool set_avatar_url(const std::string &new_avatar_url, time_t update_timestamp_ms); std::string get_avatar_url(); void set_pinned_events(std::vector<std::string> new_pinned_events); @@ -175,9 +183,9 @@ namespace QuickMedia { std::mutex user_mutex; std::recursive_mutex room_mutex; - std::string name; - std::string topic; - std::string avatar_url; + TimestampedDisplayData name; + TimestampedDisplayData topic; + TimestampedDisplayData avatar_url; std::string prev_batch; // Each room has its own list of user data, even if multiple rooms has the same user @@ -616,12 +624,12 @@ namespace QuickMedia { PluginResult parse_sync_account_data(const rapidjson::Value &account_data_json, std::optional<std::set<std::string>> &dm_rooms); PluginResult parse_sync_room_data(const rapidjson::Value &rooms_json, bool is_additional_messages_sync, bool initial_sync); PluginResult get_previous_room_messages(RoomData *room_data, bool latest_messages, size_t &num_new_messages, bool *reached_end = nullptr); - void events_add_user_info(const rapidjson::Value &events_json, RoomData *room_data); - std::shared_ptr<UserInfo> parse_user_info(const rapidjson::Value &json, const std::string &user_id, RoomData *room_data); + void events_add_user_info(const rapidjson::Value &events_json, RoomData *room_data, int64_t timestamp); + std::shared_ptr<UserInfo> parse_user_info(const rapidjson::Value &json, const std::string &user_id, RoomData *room_data, int64_t timestamp); void events_set_user_read_marker(const rapidjson::Value &events_json, RoomData *room_data, std::shared_ptr<UserInfo> &me); // Returns the number of messages added size_t events_add_messages(const rapidjson::Value &events_json, RoomData *room_data, MessageDirection message_dir, bool has_unread_notifications); - void events_set_room_info(const rapidjson::Value &events_json, RoomData *room_data); + void events_set_room_info(const rapidjson::Value &events_json, RoomData *room_data, int64_t timestamp); void set_room_info_to_users_if_empty(RoomData *room, const std::string &room_creator_user_id); void events_add_pinned_events(const rapidjson::Value &events_json, RoomData *room_data); void events_add_room_to_tags(const rapidjson::Value &events_json, RoomData *room_data); |