aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Matrix.hpp1
-rw-r--r--src/QuickMedia.cpp12
-rw-r--r--src/plugins/Matrix.cpp29
3 files changed, 23 insertions, 19 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 1744ce0..ac4487c 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -177,6 +177,7 @@ namespace QuickMedia {
bool users_fetched = false;
time_t last_read_message_timestamp = 0;
std::shared_ptr<BodyItem> body_item;
+ std::string latest_message;
// These are messages fetched with |Matrix::get_message_by_id|. Needed to show replies, when replying to old message not part of /sync.
// The value is nullptr if the message is fetched and cached but the event if referenced an invalid message.
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);