From 528e312f2528237fb236cd336bbc6f865da9116a Mon Sep 17 00:00:00 2001 From: Green Sky Date: Mon, 24 Mar 2025 12:28:03 +0100 Subject: [PATCH] force a contact sort every 29sec (when available) this is mostly because we dont throw events on new messages for contacts --- src/chat_gui/contact_list_sorter.cpp | 7 +++++-- src/chat_gui/contact_list_sorter.hpp | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/chat_gui/contact_list_sorter.cpp b/src/chat_gui/contact_list_sorter.cpp index e58e03c..549dad4 100644 --- a/src/chat_gui/contact_list_sorter.cpp +++ b/src/chat_gui/contact_list_sorter.cpp @@ -2,6 +2,8 @@ #include +#include + ContactListSorter::comperator_fn ContactListSorter::getSortGroupsOverPrivates(void) { return [](const ContactRegistry4& cr, const Contact4 lhs, const Contact4 rhs) -> std::optional { @@ -97,8 +99,8 @@ ContactListSorter::~ContactListSorter(void) { } void ContactListSorter::sort(void) { - // TODO: timer - if (!_dirty) { + const uint64_t now = getTimeMS(); + if ((now > _last_sort && now - _last_sort < 1000*29) && !_dirty) { return; } @@ -119,6 +121,7 @@ void ContactListSorter::sort(void) { entt::insertion_sort{} // o(n) in >90% of cases ); + _last_sort = now; _dirty = false; } diff --git a/src/chat_gui/contact_list_sorter.hpp b/src/chat_gui/contact_list_sorter.hpp index 5505e0b..82f866c 100644 --- a/src/chat_gui/contact_list_sorter.hpp +++ b/src/chat_gui/contact_list_sorter.hpp @@ -30,6 +30,7 @@ class ContactListSorter : public ContactStore4EventI { ContactStore4I::SubscriptionReference _cs_sr; std::vector _sort_stack; + uint64_t _last_sort {0}; bool _dirty {true}; // TODO: timer, to guarantie a sort ever X seconds? // (turns out we dont throw on new messages <.<)