aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Matrix.hpp71
1 files changed, 66 insertions, 5 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 152c292..3613709 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -20,9 +20,12 @@ namespace QuickMedia {
static const int AUTHOR_MAX_LENGTH = 48;
+ class Matrix;
+
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);
- std::string formatted_text_to_qm_text(const char *str, size_t size, bool allow_formatted_text);
+ std::string formatted_text_to_qm_text(Matrix *matrix, const char *str, size_t size, bool allow_formatted_text);
+ std::string message_to_qm_text(Matrix *matrix, const Message *message, bool allow_formatted_text = true);
struct TimestampedDisplayData {
std::string data;
@@ -233,7 +236,7 @@ namespace QuickMedia {
using Rooms = std::vector<RoomData*>;
- bool message_contains_user_mention(const Message *message, const std::string &username, const std::string &user_id);
+ bool message_contains_user_mention(Matrix *matrix, const Message *message, const std::string &username, const std::string &user_id);
bool message_contains_user_mention(const BodyItem *body_item, const std::string &username, const std::string &user_id);
bool message_is_timeline(Message *message);
void body_set_selected_item_by_url(Body *body, const std::string &url);
@@ -450,6 +453,50 @@ namespace QuickMedia {
Matrix *matrix;
};
+ class MatrixCustomEmojiPage : public LazyFetchPage {
+ public:
+ MatrixCustomEmojiPage(Program *program, Matrix *matrix) : LazyFetchPage(program), matrix(matrix) {}
+ const char* get_title() const override { return "Custom emoji"; }
+ PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
+ PluginResult lazy_fetch(BodyItems &result_items) override;
+ bool is_ready() override;
+ private:
+ Matrix *matrix;
+ };
+
+ class MatrixCustomEmojiRenameSelectPage : public LazyFetchPage {
+ public:
+ MatrixCustomEmojiRenameSelectPage(Program *program, Matrix *matrix) : LazyFetchPage(program), matrix(matrix) {}
+ const char* get_title() const override { return "Select emoji to rename"; }
+ PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
+ PluginResult lazy_fetch(BodyItems &result_items) override;
+ bool submit_is_async() const override { return false; }
+ bool reload_on_page_change() override { return true; }
+ private:
+ Matrix *matrix;
+ };
+
+ class MatrixCustomEmojiRenamePage : public Page {
+ public:
+ MatrixCustomEmojiRenamePage(Program *program, Matrix *matrix, std::string emoji_key) : Page(program), matrix(matrix), emoji_key(std::move(emoji_key)) {}
+ const char* get_title() const override { return "Enter a new name for the emoji"; }
+ PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
+ bool allow_submit_no_selection() const override { return true; }
+ private:
+ Matrix *matrix;
+ std::string emoji_key;
+ };
+
+ class MatrixCustomEmojiDeletePage : public Page {
+ public:
+ MatrixCustomEmojiDeletePage(Program *program, Matrix *matrix, Body *body) : Page(program), matrix(matrix), body(body) {}
+ const char* get_title() const override { return "Select emoji to delete"; }
+ PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
+ private:
+ Matrix *matrix;
+ Body *body;
+ };
+
// Only play one video. TODO: Play all videos in room, as related videos?
class MatrixVideoPage : public VideoPage {
public:
@@ -559,12 +606,17 @@ namespace QuickMedia {
std::string room_id;
};
+ struct CustomEmoji {
+ std::string url;
+ mgl::vec2i size;
+ };
+
class Matrix {
public:
// TODO: Make this return the Matrix object instead, to force users to call start_sync
bool start_sync(MatrixDelegate *delegate, bool &cached);
void stop_sync();
- bool is_initial_sync_finished() const;
+ bool is_initial_sync_finished();
// 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);
bool has_finished_fetching_notifications() const;
@@ -590,6 +642,11 @@ namespace QuickMedia {
// If filename is empty then the filename is extracted from filepath
PluginResult post_file(RoomData *room, const std::string &filepath, std::string filename, std::string &event_id_response, std::string &err_msg, void *relates_to = nullptr);
+ PluginResult upload_custom_emoji(const std::string &filepath, const std::string &key, std::string &mxc_url, std::string &err_msg);
+ bool delete_custom_emoji(const std::string &key);
+ bool rename_custom_emoji(const std::string &key, const std::string &new_key);
+ bool does_custom_emoji_with_name_exist(const std::string &name);
+ std::unordered_map<std::string, CustomEmoji> get_custom_emojis();
PluginResult login(const std::string &username, const std::string &password, const std::string &homeserver, std::string &err_msg);
PluginResult logout();
@@ -636,6 +693,8 @@ namespace QuickMedia {
RoomData* get_room_by_id(const std::string &id);
void update_room_users(RoomData *room);
+ std::string get_media_url(const std::string &mxc_id);
+
void append_system_message(RoomData *room_data, std::shared_ptr<Message> message);
std::string body_to_formatted_body(RoomData *room, const std::string &body);
void on_exit_room(RoomData *room);
@@ -657,7 +716,7 @@ namespace QuickMedia {
PluginResult parse_sync_response(const rapidjson::Document &root, bool is_additional_messages_sync, bool initial_sync);
PluginResult parse_notifications(const rapidjson::Value &notifications_json, std::function<void(const MatrixNotification&)> callback_func);
- PluginResult parse_sync_account_data(const rapidjson::Value &account_data_json, std::optional<std::set<std::string>> &dm_rooms);
+ PluginResult parse_sync_account_data(const rapidjson::Value &account_data_json);
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, int64_t timestamp);
@@ -673,7 +732,7 @@ namespace QuickMedia {
void remove_rooms(const rapidjson::Value &leave_json);
PluginResult get_pinned_events(RoomData *room, std::vector<std::string> &pinned_events);
std::shared_ptr<Message> parse_message_event(const rapidjson::Value &event_item_json, RoomData *room_data);
- PluginResult upload_file(RoomData *room, const std::string &filepath, std::string filename, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg, bool upload_thumbnail = true);
+ PluginResult upload_file(const std::string &filepath, std::string filename, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg, bool upload_thumbnail = true);
void add_room(std::unique_ptr<RoomData> room);
void remove_room(const std::string &room_id);
// Returns false if an invite to the room already exists
@@ -701,6 +760,7 @@ namespace QuickMedia {
std::string next_batch;
std::string next_notifications_token;
std::mutex next_batch_mutex;
+ bool initial_sync_finished = false;
std::unordered_map<std::string, Invite> invites;
std::mutex invite_mutex;
@@ -724,5 +784,6 @@ namespace QuickMedia {
std::vector<std::unique_ptr<RoomData>> invite_rooms;
std::unordered_set<std::string> my_events_transaction_ids;
+ std::unordered_map<std::string, CustomEmoji> custom_emoji_by_key;
};
} \ No newline at end of file