summary refs log tree commit diff
path: root/src/timeline/RoomlistModel.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-04-14 19:14:28 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2023-04-14 19:21:40 +0200
commit1af83bb4cc734563156c1afe4b37b760ec4d63e8 (patch)
tree6e5584f967c9bf451237c9b5154e69e7a9feebc7 /src/timeline/RoomlistModel.cpp
parentAlphabetical ordering option (diff)
downloadnheko-1af83bb4cc734563156c1afe4b37b760ec4d63e8.tar.xz
Optimize alphabetical sorting a bit
fixes #1272
Diffstat (limited to '')
-rw-r--r--src/timeline/RoomlistModel.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp
index 0801289c..909a6bf8 100644
--- a/src/timeline/RoomlistModel.cpp
+++ b/src/timeline/RoomlistModel.cpp
@@ -889,20 +889,19 @@ FilteredRoomlistModel::lessThan(const QModelIndex &left, const QModelIndex &righ
     // Now sort by recency or room name
     // Zero if empty, otherwise the time that the event occured
 
-    if (!this->sortByAlphabet) {
+    if (this->sortByAlphabet) {
+        QString a_order = sourceModel()->data(left_idx, RoomlistModel::RoomName).toString();
+        QString b_order = sourceModel()->data(right_idx, RoomlistModel::RoomName).toString();
+
+        auto comp = a_order.compare(b_order, Qt::CaseInsensitive);
+        if (comp != 0)
+            return comp < 0;
+    } else {
         uint64_t a_order = sourceModel()->data(left_idx, RoomlistModel::Timestamp).toULongLong();
         uint64_t b_order = sourceModel()->data(right_idx, RoomlistModel::Timestamp).toULongLong();
 
         if (a_order != b_order)
             return a_order > b_order;
-    } else {
-        QString a_order =
-          sourceModel()->data(left_idx, RoomlistModel::RoomName).toString().toLower();
-        QString b_order =
-          sourceModel()->data(right_idx, RoomlistModel::RoomName).toString().toLower();
-
-        if (a_order != b_order)
-            return a_order < b_order;
     }
 
     return left.row() < right.row();