From 30d23a4fb9ad20bff7d7d31c914e9900b1bdf94c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 4 Oct 2020 15:48:21 +0200 Subject: Matrix: sort messages by timestamp --- src/Body.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/Body.cpp') 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 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(); } -- cgit v1.2.3