aboutsummaryrefslogtreecommitdiff
path: root/plugins/Matrix.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-16 23:45:05 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-16 23:45:05 +0200
commit3f9185ad357fb70138d3ea301cd9ac0ee0de0704 (patch)
tree92f8b35b5f4334ebb1889a53fca811f21c094b20 /plugins/Matrix.hpp
parent0f6813a68d7f54c811b5040bdea37ca7b7e1b86e (diff)
Matrix: use room object instead of room id
Diffstat (limited to 'plugins/Matrix.hpp')
-rw-r--r--plugins/Matrix.hpp53
1 files changed, 31 insertions, 22 deletions
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<UserInfo> &user, const std::string &event_id);
std::string get_user_read_marker(std::shared_ptr<UserInfo> &user);
- // Ignores duplicates, returns the number of inserted elements
- size_t prepend_messages_reverse(std::vector<std::shared_ptr<Message>> new_messages);
- // Ignores duplicates, returns the number of inserted elements
- size_t append_messages(std::vector<std::shared_ptr<Message>> new_messages);
+ // Ignores duplicates
+ void prepend_messages_reverse(std::vector<std::shared_ptr<Message>> new_messages);
+ // Ignores duplicates
+ void append_messages(std::vector<std::shared_ptr<Message>> new_messages);
std::shared_ptr<Message> 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::shared_ptr<RoomData>, std::vector<std::shared_ptr<Message>>>;
+ using Messages = std::vector<std::shared_ptr<Message>>;
+ using RoomSyncMessages = std::unordered_map<std::shared_ptr<RoomData>, Messages>;
+ using Rooms = std::vector<std::shared_ptr<RoomData>>;
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<RoomData> room, Messages &messages);
+ PluginResult get_previous_room_messages(std::shared_ptr<RoomData> 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<UploadInfo> &file_info, const std::optional<UploadInfo> &thumbnail_info);
+ PluginResult post_message(std::shared_ptr<RoomData> room, const std::string &body, const std::optional<UploadInfo> &file_info, const std::optional<UploadInfo> &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<RoomData> 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<RoomData> 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<RoomData> 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<RoomData> 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<RoomData> room);
+ PluginResult on_stop_typing(std::shared_ptr<RoomData> room);
- PluginResult set_read_marker(const std::string &room_id, const Message *message);
+ PluginResult set_read_marker(std::shared_ptr<RoomData> 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<UserInfo> get_me(const std::string &room_id);
+ std::shared_ptr<UserInfo> get_me(std::shared_ptr<RoomData> 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<RoomData> &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<RoomData> room, const std::string &filepath, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg);
std::shared_ptr<Message> get_edited_message_original_message(RoomData *room_data, std::shared_ptr<Message> message);