aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-11-08 16:35:30 +0100
committerdec05eba <dec05eba@protonmail.com>2020-11-08 16:35:30 +0100
commitf8748d14ea11d6d53ad46aee2832180daf05fb77 (patch)
tree9a3e0d04042f347675a5db8f827f3ec961417ab0
parent240767f49483672466de638e93aaa8cb47f2f854 (diff)
Matrix: show last message sorted by timestamp in room description
-rw-r--r--TODO2
-rw-r--r--plugins/Matrix.hpp1
-rw-r--r--src/QuickMedia.cpp2
-rw-r--r--src/plugins/Matrix.cpp33
4 files changed, 27 insertions, 11 deletions
diff --git a/TODO b/TODO
index 63e059e..7eb4689 100644
--- a/TODO
+++ b/TODO
@@ -69,10 +69,8 @@ IMPORTANT: Cleanup old messages in matrix (from matrix plugin), and instead eith
Use memberName() instead of key() when iterating json object. key() creates a copy, memberName() doesn't.
Do not try to reload/redownload thumbnail that fails to download after its cleared when its no longer visible on screen and then becomes visible.
Sort matrix events by timestamp (not messages). This affects the applying of certain actions, such as changing avatar, room name, etc.
-Some services such as 4chan, youtube, matrix and nyaa supports knowing the size of an image before it has downloaded. Use that to deal with pop-in of images because the image fallback size is not the same as the image size.
Show google recaptcha on youtube when search/play fails, which can happen when using tor.
Show notifications when we receive a message in a matrix room even if we are not mentioned. This happens when we have set to receive notifications for all messages.
-Some mp4 videos fail to play because +faststart is not set, so the metadata is not at the beginning of the file. In such cases the video needs to be fully downloaded before it can play. QuickMedia should detect such files and download them (with progress bar) and then play them.
If there are multiple users with the same name in a matrix room, then display the user id beside the displayname.
Show 4chan warnings as warnings instead of ban when posting a message (show the warning message) and then post the message.
Add tabs. Using tabs with tabbed is not as good of a solution as it would use much more memory (opengl context cost) and with our own tabs, we can clear thumbnails and other cache when a tab is in the background. Changing tab either with ctrl+tab or mouse click. ctrl+enter to open a new tab. Ctrl+q or ctrl+w to close a tab.
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index e4e1583..0248e09 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -250,6 +250,7 @@ namespace QuickMedia {
std::mutex pending_room_messages_mutex;
std::unordered_map<RoomData*, std::vector<Notification>> unread_notifications;
+ std::map<RoomData*, std::shared_ptr<Message>> last_message_by_room;
};
class MatrixRoomsPage : public Page {
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();