aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-01 11:03:30 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-01 11:03:30 +0200
commitcb60c5304db0b25d6ce2460fded4cd42a1dcf0dc (patch)
tree6889b66b45838063ccd662be251b1aa749a262ea /src/plugins
parentae02ed04389117d100070c47f3ae69abb9080231 (diff)
Matrix: show indication for unread messages and show the last message in the rooms list
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index b5eb617..ed3b0af 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -34,7 +34,7 @@ namespace QuickMedia {
return PluginResult::OK;
}
- PluginResult Matrix::sync() {
+ PluginResult Matrix::sync(RoomSyncMessages &room_messages) {
std::vector<CommandArg> additional_args = {
{ "-H", "Authorization: Bearer " + access_token },
{ "-m", "35" }
@@ -73,7 +73,7 @@ namespace QuickMedia {
return PluginResult::ERR;
}
- PluginResult result = sync_response_to_body_items(json_root);
+ PluginResult result = sync_response_to_body_items(json_root, room_messages);
if(result != PluginResult::OK)
return result;
@@ -244,7 +244,7 @@ namespace QuickMedia {
return PluginResult::OK;
}
- PluginResult Matrix::sync_response_to_body_items(const Json::Value &root) {
+ PluginResult Matrix::sync_response_to_body_items(const Json::Value &root, RoomSyncMessages &room_messages) {
if(!root.isObject())
return PluginResult::ERR;
@@ -314,7 +314,7 @@ namespace QuickMedia {
const Json::Value &events_json = timeline_json["events"];
events_add_user_info(events_json, room_it->second.get());
- events_add_messages(events_json, room_it->second.get(), MessageDirection::AFTER);
+ events_add_messages(events_json, room_it->second.get(), MessageDirection::AFTER, &room_messages);
events_set_room_name(events_json, room_it->second.get());
}
@@ -400,10 +400,13 @@ namespace QuickMedia {
return "";
}
- void Matrix::events_add_messages(const Json::Value &events_json, RoomData *room_data, MessageDirection message_dir) {
+ void Matrix::events_add_messages(const Json::Value &events_json, RoomData *room_data, MessageDirection message_dir, RoomSyncMessages *room_messages) {
if(!events_json.isArray())
return;
+ std::vector<std::shared_ptr<Message>> *room_sync_messages = nullptr;
+ if(room_messages)
+ room_sync_messages = &(*room_messages)[room_data];
std::vector<std::shared_ptr<Message>> new_messages;
for(const Json::Value &event_item_json : events_json) {
@@ -484,6 +487,8 @@ namespace QuickMedia {
message->replaces_event_id = std::move(replaces_event_id);
new_messages.push_back(message);
room_data->message_by_event_id[event_id_str] = message;
+ if(room_sync_messages)
+ room_sync_messages->push_back(message);
}
// TODO: Loop and std::move instead? doesn't insert create copies?
@@ -626,7 +631,7 @@ namespace QuickMedia {
events_set_room_name(state_json, room_data);
const Json::Value &chunk_json = json_root["chunk"];
- events_add_messages(chunk_json, room_data, MessageDirection::BEFORE);
+ events_add_messages(chunk_json, room_data, MessageDirection::BEFORE, nullptr);
const Json::Value &end_json = json_root["end"];
if(!end_json.isString()) {
@@ -1431,4 +1436,12 @@ namespace QuickMedia {
Message *message_typed = (Message*)message;
return user_id == room_it->second->user_info[message_typed->user_id].user_id;
}
+
+ std::string Matrix::message_get_author_displayname(RoomData *room_data, Message *message) const {
+ if(message->user_id >= room_data->user_info.size()) {
+ fprintf(stderr, "Warning: no user with the index: %zu\n", message->user_id);
+ return "";
+ }
+ return room_data->user_info[message->user_id].display_name;
+ }
} \ No newline at end of file