aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-08-15 11:39:51 +0200
committerdec05eba <dec05eba@protonmail.com>2021-08-15 11:39:51 +0200
commit0009006c39ce4bfebc3c5260b83063c800cb4fdf (patch)
treef7e2631429daa59a04ac8b2bbac6ea3f672346b5
parent50f97448d25224dfe33624f74c6a77f23bf54289 (diff)
Matrix: use white avatar for users with no avatar, optimize notifications update
-rw-r--r--images/no_avatar.pngbin0 -> 574 bytes
-rw-r--r--plugins/Matrix.hpp1
-rw-r--r--src/QuickMedia.cpp20
-rw-r--r--src/plugins/Matrix.cpp27
4 files changed, 35 insertions, 13 deletions
diff --git a/images/no_avatar.png b/images/no_avatar.png
new file mode 100644
index 0000000..8965730
--- /dev/null
+++ b/images/no_avatar.png
Binary files differ
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 39e0a57..f589db5 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -493,6 +493,7 @@ namespace QuickMedia {
Matrix *matrix;
Body *notifications_body;
MatrixRoomsPage *all_rooms_page;
+ std::unordered_map<RoomData*, std::vector<std::shared_ptr<BodyItem>>> room_notifications;
};
class MatrixInviteUserPage : public Page {
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index a45da87..6a37b1d 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3124,6 +3124,8 @@ namespace QuickMedia {
}
AsyncImageLoader::get_instance().update();
+ if(matrix)
+ matrix->update();
if(!video_loaded) {
window.clear(get_current_theme().background_color);
@@ -4528,6 +4530,10 @@ namespace QuickMedia {
body_item->thumbnail_size = message->thumbnail_size;
} else {
body_item->thumbnail_url = room->get_user_avatar_url(message->user);
+ if(body_item->thumbnail_url.empty()) {
+ body_item->thumbnail_url = get_resource_loader_root_path() + std::string("images/no_avatar.png");
+ body_item->thumbnail_is_local = true;
+ }
body_item->thumbnail_mask_type = ThumbnailMaskType::CIRCLE;
// if construct is not configured to use ImageMagic then it wont give thumbnails of size 32x32 even when requested and the spec says that the server SHOULD do that
body_item->thumbnail_size = AVATAR_THUMBNAIL_SIZE;
@@ -4602,6 +4608,10 @@ namespace QuickMedia {
if(!is_visual_media_message_type(message->type)) {
body_item->thumbnail_url = room->get_user_avatar_url(message->user);
+ if(body_item->thumbnail_url.empty()) {
+ body_item->thumbnail_url = get_resource_loader_root_path() + std::string("images/no_avatar.png");
+ body_item->thumbnail_is_local = true;
+ }
body_item->thumbnail_mask_type = ThumbnailMaskType::CIRCLE;
// if construct is not configured to use ImageMagic then it wont give thumbnails of size 32x32 even when requested and the spec says that the server SHOULD do that
body_item->thumbnail_size = AVATAR_THUMBNAIL_SIZE;
@@ -4765,6 +4775,10 @@ namespace QuickMedia {
Message *original_message = static_cast<Message*>(body_item->userdata);
if(original_message && !is_system_message_type(original_message->type)) {
body_item->thumbnail_url = current_room->get_user_avatar_url(original_message->user);
+ if(body_item->thumbnail_url.empty()) {
+ body_item->thumbnail_url = get_resource_loader_root_path() + std::string("images/no_avatar.png");
+ body_item->thumbnail_is_local = true;
+ }
body_item->thumbnail_mask_type = ThumbnailMaskType::CIRCLE;
}
body_item->set_description("Message deleted");
@@ -5200,7 +5214,7 @@ namespace QuickMedia {
msgtype = "m.reaction";
text.erase(text.begin(), text.begin() + 7);
} else {
- show_notification("QuickMedia", "Error: invalid command: " + text + ", expected /upload, /join [room], /invite, /logout, /me [text] or /react [text]", Urgency::NORMAL);
+ show_notification("QuickMedia", "Error: invalid command: " + text + ", expected /upload, /join [room], /invite, /logout, /leave, /me [text] or /react [text]", Urgency::NORMAL);
return false;
}
} else if(chat_state == ChatState::REPLYING && text[0] == '/') {
@@ -6477,14 +6491,12 @@ namespace QuickMedia {
// TODO: Maybe set this instead when the mention is visible on the screen?
current_room->unread_notification_count = 0;
- matrix_chat_page->set_room_as_read(current_room);
-
Message *read_message = static_cast<Message*>(body_items[last_timeline_message]->userdata);
if(read_message->replaced_by)
read_message = read_message->replaced_by.get();
// TODO: What if two messages have the same timestamp?
if(!read_message->event_id.empty() && read_message->timestamp > current_room->last_read_message_timestamp) {
- //read_marker_timeout_ms = read_marker_timeout_ms_default;
+ matrix_chat_page->set_room_as_read(current_room);
current_room->last_read_message_timestamp = read_message->timestamp;
// TODO: What if the message is no longer valid?
setting_read_marker = true;
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index cb9bd69..fce4135 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -1044,7 +1044,6 @@ namespace QuickMedia {
extra_data->read = notification.read;
body_item->extra = std::move(extra_data);
- body->apply_search_filter_for_item(body_item.get());
return body_item;
}
@@ -1063,13 +1062,17 @@ namespace QuickMedia {
PluginResult MatrixNotificationsPage::get_page(const std::string&, int, BodyItems &result_items) {
return matrix->get_previous_notifications([this, &result_items](const MatrixNotification &notification) {
- result_items.push_back(notification_to_body_item(notifications_body, notification));
+ auto body_item = notification_to_body_item(notifications_body, notification);
+ room_notifications[notification.room].push_back(body_item);
+ result_items.push_back(body_item);
});
}
PluginResult MatrixNotificationsPage::lazy_fetch(BodyItems &result_items) {
matrix->get_cached_notifications([this, &result_items](const MatrixNotification &notification) {
- result_items.push_back(notification_to_body_item(notifications_body, notification));
+ auto body_item = notification_to_body_item(notifications_body, notification);
+ room_notifications[notification.room].push_back(body_item);
+ result_items.push_back(body_item);
});
return PluginResult::OK;
}
@@ -1082,20 +1085,26 @@ namespace QuickMedia {
//int prev_selected_item = notifications_body->get_selected_item();
//notifications_body->items.push_back(notification_to_body_item(notifications_body, notification));
//notifications_body->set_selected_item(prev_selected_item - 1);
- notifications_body->prepend_item(notification_to_body_item(notifications_body, notification));
+ auto body_item = notification_to_body_item(notifications_body, notification);
+ room_notifications[notification.room].push_back(body_item);
+ notifications_body->prepend_item(body_item);
notifications_body->select_next_item();
}
// TODO: Only loop unread items
void MatrixNotificationsPage::set_room_as_read(RoomData *room) {
- notifications_body->for_each_item([room](std::shared_ptr<BodyItem> &body_item) {
- NotificationsExtraData *extra_data = static_cast<NotificationsExtraData*>(body_item->extra.get());
+ auto it = room_notifications.find(room);
+ if(it == room_notifications.end())
+ return;
+
+ for(const auto &room_notification : it->second) {
+ NotificationsExtraData *extra_data = static_cast<NotificationsExtraData*>(room_notification->extra.get());
if(!extra_data->read && extra_data->room == room) {
extra_data->read = true;
- body_item->set_author_color(get_current_theme().text_color);
- body_item->set_description_color(get_current_theme().text_color);
+ room_notification->set_author_color(get_current_theme().text_color);
+ room_notification->set_description_color(get_current_theme().text_color);
}
- });
+ }
}
SearchResult MatrixInviteUserPage::search(const std::string &str, BodyItems &result_items) {