aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp2
-rw-r--r--src/plugins/Matrix.cpp33
2 files changed, 26 insertions, 9 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 7c9b348..0ec8d1d 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -1906,7 +1906,7 @@ namespace QuickMedia {
current_page = previous_page;
break;
} else if(update_err != VideoPlayer::Error::OK) {
- show_notification("QuickMedia", "The video player failed to play the video (error code " + std::to_string((int)update_err) + ")", Urgency::CRITICAL);
+ show_notification("QuickMedia", "Failed to play the video (error code " + std::to_string((int)update_err) + ")", Urgency::CRITICAL);
current_page = previous_page;
break;
}
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index c1f2b3c..7c170c9 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -373,6 +373,12 @@ namespace QuickMedia {
unread_notifications.clear();
}
+ static std::shared_ptr<Message> get_last_message_by_timestamp(const Messages &messages) {
+ return *std::max_element(messages.begin(), messages.end(), [](const std::shared_ptr<Message> &message1, const std::shared_ptr<Message> &message2) {
+ return message1->timestamp < message2->timestamp;
+ });
+ }
+
void MatrixQuickMedia::update_room_description(RoomData *room, bool is_initial_sync) {
room->acquire_room_lock();
const Messages &messages = room->get_messages_thread_unsafe();
@@ -385,10 +391,25 @@ namespace QuickMedia {
read_marker_message_timestamp = read_marker_message->timestamp;
}
- // TODO: this wont always work because we dont display all types of messages from server, such as "joined", "left", "kicked", "banned", "changed avatar", "changed display name", etc.
+ std::shared_ptr<Message> last_message = get_last_message_by_timestamp(messages);
+ if(!last_message) {
+ room->release_room_lock();
+ return;
+ }
+
+ auto last_message_it = last_message_by_room.find(room);
+ if(last_message_it != last_message_by_room.end()) {
+ if(last_message->timestamp > last_message_it->second->timestamp)
+ last_message_it->second = last_message;
+ else
+ last_message = last_message_it->second;
+ } else {
+ last_message_by_room[room] = last_message;
+ }
+
Message *last_unread_message = nullptr;
- if(!messages.empty() && messages.back()->timestamp > read_marker_message_timestamp)
- last_unread_message = messages.back().get();
+ if(last_message->timestamp > read_marker_message_timestamp)
+ last_unread_message = last_message.get();
BodyItem *room_body_item = static_cast<BodyItem*>(room->userdata);
assert(room_body_item);
@@ -405,11 +426,7 @@ namespace QuickMedia {
rooms_page->move_room_to_top(room);
room_tags_page->move_room_to_top(room);
} else if(is_initial_sync) {
- Message *last_message = nullptr;
- if(!messages.empty())
- last_message = messages.back().get();
- if(last_message)
- room_body_item->set_description(matrix->message_get_author_displayname(last_message) + ": " + extract_first_line_elipses(last_message->body, 150));
+ room_body_item->set_description(matrix->message_get_author_displayname(last_message.get()) + ": " + extract_first_line_elipses(last_message->body, 150));
}
room->release_room_lock();