backend: allow users to sort based on last activity

This MR allows an option to prefer the last activity as the most
favorable parameter for sorting.
This commit is contained in:
Soumyadeep Ghosh
2024-12-04 01:45:12 +05:30
committed by Tobias Fella
parent c585f3d8ae
commit 020385c850
3 changed files with 23 additions and 2 deletions

View File

@@ -64,8 +64,17 @@ static const QVector<RoomTreeModel::EventRoles> activitySortPriorities{
RoomTreeModel::HasHighlightNotificationsRole,
RoomTreeModel::ContextNotificationCountRole,
RoomTreeModel::FavouriteRole,
// Finally sort by last activity time
};
static const QVector<RoomTreeModel::EventRoles> lastMessageSortPriorities{
// Sort by last activity time
RoomTreeModel::LastActiveTimeRole,
// Anything useful at the top, quiet rooms at the bottom
RoomTreeModel::AttentionRole,
// Organize by highlights, notifications, unread favorites, all other unread, in that order
RoomTreeModel::HasHighlightNotificationsRole,
RoomTreeModel::ContextNotificationCountRole,
RoomTreeModel::FavouriteRole,
};
bool SortFilterRoomTreeModel::roleCmp(const QVariant &sortLeft, const QVariant &sortRight) const
@@ -110,8 +119,9 @@ bool SortFilterRoomTreeModel::lessThan(const QModelIndex &source_left, const QMo
return prioritiesCmp(alphabeticalSortPriorities, source_left, source_right);
case SortFilterRoomTreeModel::Activity:
return prioritiesCmp(activitySortPriorities, source_left, source_right);
case SortFilterRoomTreeModel::LastMessage:
return prioritiesCmp(lastMessageSortPriorities, source_left, source_right);
}
return QSortFilterProxyModel::lessThan(source_left, source_right);
}

View File

@@ -53,6 +53,7 @@ public:
enum RoomSortOrder {
Alphabetical,
Activity,
LastMessage,
};
Q_ENUM(RoomSortOrder)

View File

@@ -110,6 +110,16 @@ FormCard.FormCardPage {
NeoChatConfig.save()
}
}
FormCard.FormRadioDelegate {
text: i18nc("As in 'sort something based on the last message'", "Last Message Activity")
description: i18nc("@info", "Rooms with the newest activity will be shown first")
checked: NeoChatConfig.sortOrder === 2
enabled: !NeoChatConfig.isSortOrderImmutable
onToggled: {
NeoChatConfig.sortOrder = 2
NeoChatConfig.save()
}
}
}
FormCard.FormHeader {
title: i18n("Timeline Events")