aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-11-11 21:01:10 +0100
committerdec05eba <dec05eba@protonmail.com>2022-11-11 21:01:10 +0100
commit68528e19c46946e1a7e03353893b59b2e2a49559 (patch)
tree2b5d54289f3fa6630767aad06676c96881e465df /src
parent2bddad9701422b9fcf01c547a10054eb17ccdceb (diff)
Show unread mentions number at top of message
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp12
-rw-r--r--src/plugins/Matrix.cpp29
2 files changed, 22 insertions, 19 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index c94951d..57f54a4 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -7596,17 +7596,7 @@ namespace QuickMedia {
}
if(last_timeline_message != -1) {
- std::string room_desc = current_room->body_item->get_description();
- if(strncmp(room_desc.c_str(), "Unread: ", 8) == 0)
- room_desc = room_desc.substr(8);
- size_t last_line_start = room_desc.rfind('\n');
- if(last_line_start != std::string::npos && last_line_start != room_desc.size()) {
- ++last_line_start;
- size_t last_line_size = room_desc.size() - last_line_start;
- if(last_line_size >= 23 && memcmp(&room_desc[last_line_start], "** ", 3) == 0 && memcmp(&room_desc[room_desc.size() - 20], "unread mention(s) **", 20) == 0)
- room_desc.erase(room_desc.begin() + last_line_start - 1, room_desc.end());
- }
- current_room->body_item->set_description(std::move(room_desc));
+ current_room->body_item->set_description(current_room->latest_message);
current_room->body_item->set_description_color(get_theme().faded_text_color);
// TODO: Show a line like nheko instead for unread messages, or something else
current_room->body_item->set_title_color(get_theme().text_color);
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 1e8ee99..65e29a3 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -724,22 +724,34 @@ namespace QuickMedia {
Body *chat_body = chat_page ? chat_page->chat_body : nullptr;
bool set_room_as_unread = !is_window_focused || room != current_room || (!chat_body || chat_body->is_bottom_cut_off()) || (chat_page && !chat_page->messages_tab_visible);
+ bool unread_mentions = false;
std::string room_desc;
- if(set_room_as_unread)
- room_desc += "Unread: ";
- if(last_unread_message)
- room_desc += extract_first_line_remove_newline_elipses(matrix->message_get_author_displayname(last_unread_message), AUTHOR_MAX_LENGTH) + ": " + message_to_room_description_text(matrix, last_unread_message, custom_emoji_max_size);
-
- int unread_notification_count = room->unread_notification_count;
+ const int unread_notification_count = room->unread_notification_count;
if(unread_notification_count > 0 && set_room_as_unread) {
- if(!room_desc.empty())
- room_desc += '\n';
+ unread_mentions = true;
room_desc += "** " + std::to_string(unread_notification_count) + " unread mention(s) **"; // TODO: Better notification?
room->body_item->set_description_color(get_theme().attention_alert_text_color, true);
} else {
room->body_item->set_description_color(get_theme().faded_text_color);
}
+
+ if(last_unread_message) {
+ if(!room_desc.empty())
+ room_desc += '\n';
+ }
+
+ if(!unread_mentions && set_room_as_unread)
+ room_desc += "Unread: ";
+
+ if(last_unread_message) {
+ room->latest_message = extract_first_line_remove_newline_elipses(matrix->message_get_author_displayname(last_unread_message), AUTHOR_MAX_LENGTH) + ": " + message_to_room_description_text(matrix, last_unread_message, custom_emoji_max_size);
+ } else {
+ room->latest_message.clear();
+ }
+
+ room_desc += room->latest_message;
+
room->body_item->set_description(std::move(room_desc));
room->body_item->set_description_max_lines(3);
if(set_room_as_unread)
@@ -752,6 +764,7 @@ namespace QuickMedia {
room->body_item->set_description(extract_first_line_remove_newline_elipses(matrix->message_get_author_displayname(last_new_message.get()), AUTHOR_MAX_LENGTH) + ": " + message_to_room_description_text(matrix, last_new_message.get(), custom_emoji_max_size));
room->body_item->set_description_color(get_theme().faded_text_color);
room->body_item->set_description_max_lines(3);
+ room->latest_message = room->body_item->get_description();
rooms_page->move_room_to_top(room);
room_tags_page->move_room_to_top(room);