aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-19 19:36:10 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-19 19:36:10 +0200
commit41fe990530c546b4cac7e000b40481f87fb33305 (patch)
treea93fa803b04e5e7efeeacb6d302f68a240188321 /plugins
parent878beb16ad10d1e1e44d51f3841d44a6836bb4e9 (diff)
shared_ptr<RoomData> -> unique_ptr<RoomData> and naked pointers
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Matrix.hpp44
1 files changed, 25 insertions, 19 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index c953364..a48cf69 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -93,6 +93,12 @@ namespace QuickMedia {
std::string prev_batch;
bool initial_fetch_finished = false;
+ // These 4 variables are set by QuickMedia, not the matrix plugin
+ bool last_message_read = true;
+ time_t last_read_message_timestamp = 0;
+ bool has_unread_mention = false;
+ void *userdata = nullptr; // Pointer to BodyItem. Note: this has to be valid as long as the room is valid
+
// These are messages fetched with |Matrix::get_message_by_id|. Needed to show replies, when replying to old message not part of /sync.
// The value is nullptr if the message is fetched and cached but the event if referenced an invalid message.
// TODO: Verify if replied to messages are also part of /sync; then this is not needed.
@@ -121,8 +127,8 @@ namespace QuickMedia {
};
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>>;
+ using RoomSyncMessages = std::unordered_map<RoomData*, Messages>;
+ using Rooms = std::vector<RoomData*>;
bool message_contains_user_mention(const std::string &msg, const std::string &username);
@@ -130,30 +136,30 @@ namespace QuickMedia {
public:
PluginResult sync(RoomSyncMessages &room_messages);
void get_room_join_updates(Rooms &new_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);
+ PluginResult get_all_synced_room_messages(RoomData *room, Messages &messages);
+ PluginResult get_previous_room_messages(RoomData *room, Messages &messages);
// |url| should only be set when uploading media.
// TODO: Make api better.
- PluginResult post_message(std::shared_ptr<RoomData> room, const std::string &body, const std::optional<UploadInfo> &file_info, const std::optional<UploadInfo> &thumbnail_info);
+ PluginResult post_message(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(std::shared_ptr<RoomData> room, const std::string &body, void *relates_to);
+ PluginResult post_reply(RoomData *room, const std::string &body, void *relates_to);
// |relates_to| is from |BodyItem.userdata| and is of type |Message*|
- PluginResult post_edit(std::shared_ptr<RoomData> room, const std::string &body, void *relates_to);
+ PluginResult post_edit(RoomData *room, const std::string &body, void *relates_to);
- PluginResult post_file(std::shared_ptr<RoomData> room, const std::string &filepath, std::string &err_msg);
+ PluginResult post_file(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(std::shared_ptr<RoomData> room, void *message, std::string &err_msg);
+ PluginResult delete_message(RoomData *room, void *message, std::string &err_msg);
PluginResult load_and_verify_cached_session();
- PluginResult on_start_typing(std::shared_ptr<RoomData> room);
- PluginResult on_stop_typing(std::shared_ptr<RoomData> room);
+ PluginResult on_start_typing(RoomData *room);
+ PluginResult on_stop_typing(RoomData *room);
- PluginResult set_read_marker(std::shared_ptr<RoomData> room, const Message *message);
+ PluginResult set_read_marker(RoomData *room, const Message *message);
// |message| is from |BodyItem.userdata| and is of type |Message*|
bool was_message_posted_by_me(void *message);
@@ -163,7 +169,7 @@ namespace QuickMedia {
// Cached
PluginResult get_config(int *upload_size);
- std::shared_ptr<UserInfo> get_me(std::shared_ptr<RoomData> room);
+ std::shared_ptr<UserInfo> get_me(RoomData *room);
// Returns nullptr if message cant be found. Note: cached
std::shared_ptr<Message> get_message_by_id(RoomData *room, const std::string &event_id);
@@ -171,21 +177,21 @@ namespace QuickMedia {
bool use_tor = false;
private:
PluginResult sync_response_to_body_items(const rapidjson::Document &root, RoomSyncMessages &room_messages);
- PluginResult get_previous_room_messages(std::shared_ptr<RoomData> &room_data);
+ PluginResult get_previous_room_messages(RoomData *room_data);
void events_add_user_info(const rapidjson::Value &events_json, RoomData *room_data);
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_add_messages(const rapidjson::Value &events_json, 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);
std::shared_ptr<Message> parse_message_event(const rapidjson::Value &event_item_json, RoomData *room_data);
- PluginResult upload_file(std::shared_ptr<RoomData> room, const std::string &filepath, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg);
+ PluginResult upload_file(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);
- std::shared_ptr<RoomData> get_room_by_id(const std::string &id);
- void add_room(std::shared_ptr<RoomData> room);
+ RoomData* get_room_by_id(const std::string &id);
+ void add_room(std::unique_ptr<RoomData> room);
DownloadResult download_json(rapidjson::Document &result, const std::string &url, std::vector<CommandArg> additional_args, bool use_browser_useragent = false, std::string *err_msg = nullptr) const;
private:
- std::vector<std::shared_ptr<RoomData>> rooms;
+ std::vector<std::unique_ptr<RoomData>> rooms;
std::unordered_map<std::string, size_t> room_data_by_id; // value is an index into |rooms|
size_t room_list_read_index = 0;
std::mutex room_data_mutex;