aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-04-28 18:46:15 +0200
committerdec05eba <dec05eba@protonmail.com>2021-04-28 18:46:15 +0200
commit3b0d367c6b70f88e5fa01a1813f9487c37401050 (patch)
treed5998b88d8835de5cc159e7e105c25576e7320d6 /src/plugins
parent7d0d8a1bf0ffbaf073303efc7d7bfc58177277a6 (diff)
Update emoji, add room topic to matrix
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp99
1 files changed, 62 insertions, 37 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 6af5e6e..77d8f32 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -278,6 +278,16 @@ namespace QuickMedia {
return name;
}
+ void RoomData::set_topic(const std::string &new_topic) {
+ std::lock_guard<std::recursive_mutex> lock(room_mutex);
+ topic = new_topic;
+ }
+
+ std::string RoomData::get_topic() {
+ std::lock_guard<std::recursive_mutex> lock(room_mutex);
+ return topic;
+ }
+
bool RoomData::has_avatar_url() {
std::lock_guard<std::recursive_mutex> lock(room_mutex);
return !avatar_url.empty();
@@ -1535,7 +1545,7 @@ namespace QuickMedia {
if(state_json.IsObject()) {
const rapidjson::Value &events_json = GetMember(state_json, "events");
events_add_user_info(events_json, room);
- events_set_room_name(events_json, room);
+ events_set_room_info(events_json, room);
if(!is_additional_messages_sync)
events_add_pinned_events(events_json, room);
}
@@ -1564,8 +1574,8 @@ namespace QuickMedia {
const rapidjson::Value &events_json = GetMember(timeline_json, "events");
events_add_user_info(events_json, room);
- events_set_room_name(events_json, room);
- set_room_name_to_users_if_empty(room, my_user_id);
+ events_set_room_info(events_json, room);
+ set_room_info_to_users_if_empty(room, my_user_id);
if(account_data_json.IsObject()) {
const rapidjson::Value &events_json = GetMember(account_data_json, "events");
@@ -1580,7 +1590,7 @@ namespace QuickMedia {
if(!is_additional_messages_sync)
events_add_pinned_events(events_json, room);
} else {
- set_room_name_to_users_if_empty(room, my_user_id);
+ set_room_info_to_users_if_empty(room, my_user_id);
if(account_data_json.IsObject()) {
const rapidjson::Value &events_json = GetMember(account_data_json, "events");
auto me = get_me(room);
@@ -2239,7 +2249,7 @@ namespace QuickMedia {
return result;
}
- void Matrix::events_set_room_name(const rapidjson::Value &events_json, RoomData *room_data) {
+ void Matrix::events_set_room_info(const rapidjson::Value &events_json, RoomData *room_data) {
if(!events_json.IsArray())
return;
@@ -2248,44 +2258,59 @@ namespace QuickMedia {
continue;
const rapidjson::Value &type_json = GetMember(event_item_json, "type");
- if(!type_json.IsString() || strcmp(type_json.GetString(), "m.room.name") != 0)
- continue;
-
- const rapidjson::Value &content_json = GetMember(event_item_json, "content");
- if(!content_json.IsObject())
+ if(!type_json.IsString())
continue;
- const rapidjson::Value &name_json = GetMember(content_json, "name");
- if(!name_json.IsString())
- continue;
+ if(strcmp(type_json.GetString(), "m.room.name") == 0) {
+ const rapidjson::Value &content_json = GetMember(event_item_json, "content");
+ if(!content_json.IsObject())
+ continue;
- room_data->set_name(name_json.GetString());
- room_data->name_is_fallback = false;
- }
+ const rapidjson::Value &name_json = GetMember(content_json, "name");
+ if(!name_json.IsString())
+ continue;
- for(const rapidjson::Value &event_item_json : events_json.GetArray()) {
- if(!event_item_json.IsObject())
- continue;
+ room_data->set_name(name_json.GetString());
+ room_data->name_is_fallback = false;
+ } else if(strcmp(type_json.GetString(), "m.room.avatar") == 0) {
+ const rapidjson::Value &content_json = GetMember(event_item_json, "content");
+ if(!content_json.IsObject())
+ continue;
- const rapidjson::Value &type_json = GetMember(event_item_json, "type");
- if(!type_json.IsString() || strcmp(type_json.GetString(), "m.room.avatar") != 0)
- continue;
-
- const rapidjson::Value &content_json = GetMember(event_item_json, "content");
- if(!content_json.IsObject())
- continue;
+ const rapidjson::Value &url_json = GetMember(content_json, "url");
+ if(!url_json.IsString())
+ continue;
- const rapidjson::Value &url_json = GetMember(content_json, "url");
- if(!url_json.IsString())
- continue;
+ std::string url_json_str = url_json.GetString() + 6;
+ room_data->set_avatar_url(get_thumbnail_url(homeserver, thumbnail_url_extract_media_id(url_json_str)));
+ room_data->avatar_is_fallback = false;
+ } else if(strcmp(type_json.GetString(), "m.room.avatar") == 0) {
+ const rapidjson::Value &content_json = GetMember(event_item_json, "content");
+ if(!content_json.IsObject())
+ continue;
+
+ const rapidjson::Value &url_json = GetMember(content_json, "url");
+ if(!url_json.IsString())
+ continue;
- std::string url_json_str = url_json.GetString() + 6;
- room_data->set_avatar_url(get_thumbnail_url(homeserver, thumbnail_url_extract_media_id(url_json_str)));
- room_data->avatar_is_fallback = false;
+ std::string url_json_str = url_json.GetString() + 6;
+ room_data->set_avatar_url(get_thumbnail_url(homeserver, thumbnail_url_extract_media_id(url_json_str)));
+ room_data->avatar_is_fallback = false;
+ } else if(strcmp(type_json.GetString(), "m.room.topic") == 0) {
+ const rapidjson::Value &content_json = GetMember(event_item_json, "content");
+ if(!content_json.IsObject())
+ continue;
+
+ const rapidjson::Value &topic_json = GetMember(content_json, "topic");
+ if(!topic_json.IsString())
+ continue;
+
+ room_data->set_topic(topic_json.GetString());
+ }
}
}
- void Matrix::set_room_name_to_users_if_empty(RoomData *room, const std::string &room_creator_user_id) {
+ void Matrix::set_room_info_to_users_if_empty(RoomData *room, const std::string &room_creator_user_id) {
bool has_room_name = room->has_name();
bool has_room_avatar_url = room->has_avatar_url();
@@ -2459,7 +2484,7 @@ namespace QuickMedia {
Invite invite;
RoomData invite_room;
events_add_user_info(events_json, &invite_room);
- events_set_room_name(events_json, &invite_room);
+ events_set_room_info(events_json, &invite_room);
std::string sender_json_str(sender_json.GetString(), sender_json.GetStringLength());
auto invited_by = get_user_by_id(&invite_room, sender_json_str);
@@ -2468,7 +2493,7 @@ namespace QuickMedia {
break;
}
- set_room_name_to_users_if_empty(&invite_room, sender_json_str);
+ set_room_info_to_users_if_empty(&invite_room, sender_json_str);
invite.room_name = invite_room.get_name();
invite.room_avatar_url = invite_room.get_avatar_url();
@@ -2598,7 +2623,7 @@ namespace QuickMedia {
const rapidjson::Value &state_json = GetMember(json_root, "state");
events_add_user_info(state_json, room_data);
- //events_set_room_name(state_json, room_data);
+ //events_set_room_info(state_json, room_data);
const rapidjson::Value &chunk_json = GetMember(json_root, "chunk");
num_new_messages = events_add_messages(chunk_json, room_data, MessageDirection::BEFORE, false);
@@ -3164,7 +3189,7 @@ namespace QuickMedia {
const rapidjson::Value &state_json = GetMember(json_root, "state");
events_add_user_info(state_json, room);
#endif
- //events_set_room_name(state_json, room);
+ //events_set_room_info(state_json, room);
#if 0
const rapidjson::Value &event_json = GetMember(json_root, "event");
std::shared_ptr<Message> new_message = parse_message_event(event_json, room);