aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO4
-rw-r--r--include/Body.hpp5
-rw-r--r--src/Body.cpp25
-rw-r--r--src/QuickMedia.cpp21
4 files changed, 48 insertions, 7 deletions
diff --git a/TODO b/TODO
index c5ca1d1..adb2d36 100644
--- a/TODO
+++ b/TODO
@@ -65,7 +65,6 @@ Support peertube (works with mpv, but need to implement search and related video
Scroll to bottom when receiving a new message even if the selected message is not the last one. It should instead school if the last message is visible on the screen.
Add ".." directory to file-manager, to go up one directory. Also add a tab for common directories and recently accessed files/directories (the directories would be the directory of used files).
Provide a way to go to the first unread message in matrix and also show a marker in the body (maybe a red line?) where the first unread message is.
-Sort matrix messages by timestamp. This may be needed to make notification messages show properly in the timeline?
Load already downloaded images/thumbnails in a separate thread, to instantly load them instead of waiting for new downloads...
Make text that mentions us red in matrix.
Allow scrolling body item. A body item can be long and we wont be able to read all of it otherwise (such as a message on matrix). Pressing up/down should scroll such a large body item rather than moving to another one.
@@ -88,4 +87,5 @@ Add option to sort by other than timestamp for nyaa.si.
Add url preview for matrix (using matrix api, fallback to client url preview (using our own url preview project)).
Cleanup old messages in matrix (from matrix plugin), and instead either save them to disk or refetch them from server when going up to read old messages.
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. \ No newline at end of file
+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. \ No newline at end of file
diff --git a/include/Body.hpp b/include/Body.hpp
index 5ee93fc..3d5c870 100644
--- a/include/Body.hpp
+++ b/include/Body.hpp
@@ -114,6 +114,9 @@ namespace QuickMedia {
// Select next item, ignoring invisible items. Returns true if the item was changed. This can be used to check if the bottom was hit when wrap_around is set to false
bool select_next_item();
void set_selected_item(int item);
+
+ // Returns -1 if item can't be found
+ int get_index_by_body_item(BodyItem *body_item);
void select_first_item();
void select_last_item();
@@ -121,6 +124,8 @@ namespace QuickMedia {
void clear_items();
void prepend_items(BodyItems new_items);
void append_items(BodyItems new_items);
+ void insert_item_by_timestamp(std::shared_ptr<BodyItem> body_item);
+ void insert_items_by_timestamps(BodyItems new_items);
void clear_thumbnails();
BodyItem* get_selected() const;
diff --git a/src/Body.cpp b/src/Body.cpp
index 2134a44..260e90d 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -186,6 +186,14 @@ namespace QuickMedia {
//page_scroll = 0.0f;
}
+ int Body::get_index_by_body_item(BodyItem *body_item) {
+ for(int i = 0; i < (int)items.size(); ++i) {
+ if(items[i].get() == body_item)
+ return i;
+ }
+ return -1;
+ }
+
void Body::select_first_item() {
selected_item = 0;
prev_selected_item = selected_item;
@@ -225,6 +233,23 @@ namespace QuickMedia {
}
}
+ void Body::insert_item_by_timestamp(std::shared_ptr<BodyItem> body_item) {
+ for(size_t i = 0; i < items.size(); ++i) {
+ if(body_item->get_timestamp() < items[i]->get_timestamp()) {
+ items.insert(items.begin() + i, std::move(body_item));
+ return;
+ }
+ }
+ items.push_back(std::move(body_item));
+ }
+
+ // TODO: Optimize by resizing |items| before insert
+ void Body::insert_items_by_timestamps(BodyItems new_items) {
+ for(auto &new_item : new_items) {
+ insert_item_by_timestamp(std::move(new_item));
+ }
+ }
+
void Body::clear_thumbnails() {
item_thumbnail_textures.clear();
}
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index f18c0ce..776093d 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -4071,9 +4071,16 @@ namespace QuickMedia {
if(sync_future_room_id == current_room_id || !synced) {
int num_items = tabs[MESSAGES_TAB_INDEX].body->items.size();
bool scroll_to_end = (num_items == 0 || (num_items > 0 && tabs[MESSAGES_TAB_INDEX].body->get_selected_item() == num_items - 1));
- tabs[MESSAGES_TAB_INDEX].body->append_items(std::move(sync_result.body_items));
- if(scroll_to_end)
+
+ BodyItem *selected_item = tabs[MESSAGES_TAB_INDEX].body->get_selected();
+ tabs[MESSAGES_TAB_INDEX].body->insert_items_by_timestamps(std::move(sync_result.body_items));
+ if(selected_item && !scroll_to_end) {
+ int selected_item_index = tabs[MESSAGES_TAB_INDEX].body->get_index_by_body_item(selected_item);
+ if(selected_item_index != -1)
+ tabs[MESSAGES_TAB_INDEX].body->set_selected_item(selected_item_index);
+ } else if(scroll_to_end) {
tabs[MESSAGES_TAB_INDEX].body->select_last_item();
+ }
}
// Initial sync
@@ -4112,9 +4119,13 @@ namespace QuickMedia {
// Ignore finished fetch of messages if it happened in another room. When we navigate back to the room we will get the messages again
size_t num_new_messages = new_body_items.size();
if(previous_messages_future_room_id == current_room_id && num_new_messages > 0) {
- int selected_item_index = tabs[MESSAGES_TAB_INDEX].body->get_selected_item();
- tabs[MESSAGES_TAB_INDEX].body->prepend_items(std::move(new_body_items));
- tabs[MESSAGES_TAB_INDEX].body->set_selected_item(selected_item_index + num_new_messages);
+ BodyItem *selected_item = tabs[MESSAGES_TAB_INDEX].body->get_selected();
+ tabs[MESSAGES_TAB_INDEX].body->insert_items_by_timestamps(std::move(new_body_items));
+ if(selected_item) {
+ int selected_item_index = tabs[MESSAGES_TAB_INDEX].body->get_index_by_body_item(selected_item);
+ if(selected_item_index != -1)
+ tabs[MESSAGES_TAB_INDEX].body->set_selected_item(selected_item_index);
+ }
}
fetching_previous_messages_running = false;
}