aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp15
-rw-r--r--src/plugins/Matrix.cpp99
2 files changed, 74 insertions, 40 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 54308a4..842ecbe 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3684,12 +3684,16 @@ namespace QuickMedia {
logo_sprite.setScale(0.8f * get_ui_scale(), 0.8f * get_ui_scale());
sf::Vector2f logo_size(plugin_logo.getSize().x * logo_sprite.getScale().x, plugin_logo.getSize().y * logo_sprite.getScale().y);
- sf::Text room_name_text("", *FontLoader::get_font(FontLoader::FontType::LATIN_BOLD), std::floor(18 * get_ui_scale()));
const float room_name_text_height = std::floor(18.0f * get_ui_scale());
+ sf::Text room_name_text("", *FontLoader::get_font(FontLoader::FontType::LATIN_BOLD), room_name_text_height);
const float room_name_text_padding_y = std::floor(10.0f * get_ui_scale());
const float room_name_total_height = room_name_text_height + room_name_text_padding_y * 2.0f;
const float room_avatar_height = 32.0f;
+ const float room_topic_text_height = std::floor(12.0f * get_ui_scale());
+ sf::Text room_topic_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), room_topic_text_height);
+ room_topic_text.setFillColor(sf::Color(179, 179, 179));
+
sf::Text room_label(room_tabs[room_selected_tab].page->get_title(), *FontLoader::get_font(FontLoader::FontType::LATIN_BOLD), std::floor(18 * get_ui_scale()));
room_label.setPosition(15.0f, room_name_text_padding_y + 4.0f);
@@ -3913,7 +3917,8 @@ namespace QuickMedia {
process_pinned_events(std::move(pinned_events));
tabs[PINNED_TAB_INDEX].body->select_last_item();
- room_name_text.setString(current_room->body_item->get_title());
+ room_name_text.setString(current_room->get_name());
+ room_topic_text.setString(current_room->get_topic());
room_avatar_thumbnail_data = std::make_shared<ThumbnailData>();
read_marker_timeout_ms = 0;
@@ -5135,8 +5140,12 @@ namespace QuickMedia {
window.draw(room_avatar_sprite, &circle_mask_shader);
room_name_text_offset_x += room_avatar_texture_size.x + 10.0f;
}
- room_name_text.setPosition(body_pos.x + room_name_text_offset_x, room_name_text_padding_y + 4.0f);
+
+ room_name_text.setPosition(body_pos.x + room_name_text_offset_x, room_name_text_padding_y);
window.draw(room_name_text);
+
+ room_topic_text.setPosition(room_name_text.getPosition().x + room_name_text.getLocalBounds().width + 15.0f, room_name_text_padding_y + 2.0f + room_name_text_height * 0.5f - room_topic_text_height * 0.5f);
+ window.draw(room_topic_text);
}
if(draw_room_list) {
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);