aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-05-18 22:05:19 +0200
committerdec05eba <dec05eba@protonmail.com>2021-05-18 22:08:41 +0200
commitd123c41cd3ad4f0d55ae134be69e7ffd144dbb74 (patch)
treef46a8e6daea5b757f4b66363c64aea6269dd83a9 /plugins
parentf6a39afa8bfd869ba661799897ac37e7d1ff7c34 (diff)
Add mention autocomplete
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Matrix.hpp64
1 files changed, 55 insertions, 9 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 25b2633..0e96fd7 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -19,12 +19,7 @@ namespace QuickMedia {
std::string remove_reply_formatting(const std::string &str);
std::string message_get_body_remove_formatting(Message *message);
std::string extract_first_line_remove_newline_elipses(const std::string &str, size_t max_length);
-
- enum class UserResolveState {
- NOT_RESOLVED,
- RESOLVING,
- RESOLVED
- };
+ sf::Color user_id_to_color(const std::string &user_id);
struct UserInfo {
friend struct RoomData;
@@ -34,7 +29,6 @@ namespace QuickMedia {
RoomData *room;
const sf::Color display_name_color;
const std::string user_id;
- UserResolveState resolve_state;
private:
std::string display_name;
std::string avatar_url;
@@ -63,9 +57,42 @@ namespace QuickMedia {
REACTION
};
+ struct MatrixEventUserInfo {
+ std::string user_id;
+ std::optional<std::string> display_name;
+ std::optional<std::string> avatar_url;
+ };
+
class MatrixEvent {
public:
+ enum class Type {
+ ADD_USER,
+ REMOVE_USER,
+ USER_INFO
+ };
+
+ MatrixEvent(Type type) : type(type) {}
virtual ~MatrixEvent() = default;
+
+ const Type type;
+ };
+
+ class MatrixAddUserEvent : public MatrixEvent {
+ public:
+ MatrixAddUserEvent(MatrixEventUserInfo user_info) : MatrixEvent(Type::ADD_USER), user_info(std::move(user_info)) {}
+ const MatrixEventUserInfo user_info;
+ };
+
+ class MatrixRemoveUserEvent : public MatrixEvent {
+ public:
+ MatrixRemoveUserEvent(MatrixEventUserInfo user_info) : MatrixEvent(Type::REMOVE_USER), user_info(std::move(user_info)) {}
+ const MatrixEventUserInfo user_info;
+ };
+
+ class MatrixUserInfoEvent : public MatrixEvent {
+ public:
+ MatrixUserInfoEvent(MatrixEventUserInfo user_info) : MatrixEvent(Type::USER_INFO), user_info(std::move(user_info)) {}
+ const MatrixEventUserInfo user_info;
};
struct Message {
@@ -108,6 +135,7 @@ namespace QuickMedia {
std::shared_ptr<Message> get_message_by_id(const std::string &id);
+ std::vector<std::shared_ptr<UserInfo>> get_users();
std::vector<std::shared_ptr<UserInfo>> get_users_excluding_me(const std::string &my_user_id);
void acquire_room_lock();
@@ -543,9 +571,24 @@ namespace QuickMedia {
std::shared_ptr<Message> get_message_by_id(RoomData *room, const std::string &event_id);
RoomData* get_room_by_id(const std::string &id);
- void update_user_with_latest_state(RoomData *room, const std::string &user_id);
void update_room_users(RoomData *room);
+
+ // Only one room can have event queue enabled at once
+ void enable_event_queue(RoomData *room);
+ // Also clears the event queue
+ void disable_event_queue();
+
+ // Has to be called in the main thread.
+ // Returns nullptr if there are no new events.
+ std::unique_ptr<MatrixEvent> pop_event();
private:
+ // No-op if sync is cache or if |room| is not the currently enabled event queue room
+ void trigger_event(RoomData *room, std::unique_ptr<MatrixEvent> event);
+
+ void replace_mentions(RoomData *room, std::string &text);
+ std::string body_to_formatted_body(RoomData *room, const std::string &body);
+ std::string create_formatted_body_for_message_reply(RoomData *room, const Message *message, const std::string &body);
+
PluginResult set_qm_last_read_message_timestamp(RoomData *room, int64_t timestamp);
PluginResult parse_sync_response(const rapidjson::Document &root, bool is_additional_messages_sync, bool initial_sync);
@@ -575,9 +618,12 @@ namespace QuickMedia {
void set_next_batch(std::string new_next_batch);
std::string get_next_batch();
void clear_sync_cache_for_new_sync();
- std::shared_ptr<UserInfo> get_user_by_id(RoomData *room, const std::string &user_id);
+ std::shared_ptr<UserInfo> get_user_by_id(RoomData *room, const std::string &user_id, bool *is_new_user = nullptr, bool create_if_not_found = true);
std::string get_filter_cached();
private:
+ std::deque<std::unique_ptr<MatrixEvent>> event_queue;
+ std::mutex event_queue_mutex;
+ RoomData *current_event_queue_room = nullptr;
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;