update ordering settings
This commit is contained in:
parent
701024b5f6
commit
f6b9deee86
4 changed files with 56 additions and 42 deletions
|
|
@ -256,7 +256,7 @@ class SettingsSectionsController
|
||||||
),
|
),
|
||||||
.new(
|
.new(
|
||||||
title: "Room Ordering",
|
title: "Room Ordering",
|
||||||
description: "Sort rooms and subspaces by recent activity, optionally showing mentioned or unread ones first, or keep the order their space sets.",
|
description: "Sort rooms and subspaces by recent activity or the order their space sets, optionally showing mentioned and unread ones first.",
|
||||||
icon: Icons.sort,
|
icon: Icons.sort,
|
||||||
builder: (title, description, icon) => DialogListTile<RoomOrder>(
|
builder: (title, description, icon) => DialogListTile<RoomOrder>(
|
||||||
icon: Icon(icon),
|
icon: Icon(icon),
|
||||||
|
|
@ -265,10 +265,11 @@ class SettingsSectionsController
|
||||||
value: settings.roomOrder,
|
value: settings.roomOrder,
|
||||||
options: RoomOrder.values,
|
options: RoomOrder.values,
|
||||||
getName: (option) => switch (option) {
|
getName: (option) => switch (option) {
|
||||||
.unreadFirst => "Mentioned, then unread",
|
.unreadFirst => "Mentioned, then unread, then recent",
|
||||||
.mentionedFirst => "Mentioned only",
|
.unreadFirstSpaceOrder =>
|
||||||
|
"Mentioned, then unread, then space order",
|
||||||
.recentActivity => "Recent activity only",
|
.recentActivity => "Recent activity only",
|
||||||
.spaceOrder => "Space order",
|
.spaceOrder => "Space order only",
|
||||||
},
|
},
|
||||||
onChanged: (value) => ref
|
onChanged: (value) => ref
|
||||||
.read(SettingsController.provider.notifier)
|
.read(SettingsController.provider.notifier)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ import "package:nexus/models/space.dart";
|
||||||
import "package:nexus/models/space_edge.dart";
|
import "package:nexus/models/space_edge.dart";
|
||||||
import "package:nexus/models/subspace.dart";
|
import "package:nexus/models/subspace.dart";
|
||||||
|
|
||||||
|
typedef _SortKey = ({int priority, DateTime activity, int index});
|
||||||
|
|
||||||
class SpacesController extends AsyncNotifier<IList<Space>> {
|
class SpacesController extends AsyncNotifier<IList<Space>> {
|
||||||
@override
|
@override
|
||||||
Future<IList<Space>> build() async {
|
Future<IList<Space>> build() async {
|
||||||
|
|
@ -162,58 +164,63 @@ class SpacesController extends AsyncNotifier<IList<Space>> {
|
||||||
SettingsController.provider.selectAsync((data) => data.roomOrder),
|
SettingsController.provider.selectAsync((data) => data.roomOrder),
|
||||||
);
|
);
|
||||||
|
|
||||||
int priority(Room room) => switch ((roomOrder, room.metadata)) {
|
int priority(Room? room) => switch (room?.metadata) {
|
||||||
(.recentActivity || .spaceOrder, _) => 0,
|
_ when !roomOrder.byUnread => 0,
|
||||||
(_, RoomMetadata(unreadHighlights: > 0)) => 0,
|
RoomMetadata(unreadHighlights: > 0) => 0,
|
||||||
(.mentionedFirst, _) => 1,
|
RoomMetadata(unreadNotifications: > 0) ||
|
||||||
(.unreadFirst, RoomMetadata(unreadNotifications: > 0)) ||
|
RoomMetadata(unreadMessages: > 0) => 1,
|
||||||
(.unreadFirst, RoomMetadata(unreadMessages: > 0)) => 1,
|
_ => 2,
|
||||||
(.unreadFirst, _) => 2,
|
|
||||||
};
|
};
|
||||||
DateTime activity(Room room) => room.metadata?.sortingTimestamp ?? .new(0);
|
DateTime activity(Room room) => room.metadata?.sortingTimestamp ?? .new(0);
|
||||||
|
|
||||||
// Higher priority first, then most recent activity first
|
return .new(
|
||||||
int compare(
|
allSpaces.map((space) {
|
||||||
({int priority, DateTime activity}) a,
|
final bySpace = roomOrder.bySpace && space.room != null;
|
||||||
({int priority, DateTime activity}) b,
|
int compare(_SortKey a, _SortKey b) =>
|
||||||
) => switch (a.priority.compareTo(b.priority)) {
|
switch (a.priority.compareTo(b.priority)) {
|
||||||
|
0 when bySpace => a.index.compareTo(b.index),
|
||||||
0 => b.activity.compareTo(a.activity),
|
0 => b.activity.compareTo(a.activity),
|
||||||
final byPriority => byPriority,
|
final byPriority => byPriority,
|
||||||
};
|
};
|
||||||
|
|
||||||
({int priority, DateTime activity}) roomKey(Room room) =>
|
_SortKey roomKey(int index, Room room) =>
|
||||||
(priority: priority(room), activity: activity(room));
|
(priority: priority(room), activity: activity(room), index: index);
|
||||||
|
|
||||||
({int priority, DateTime activity}) groupKey(IList<Room> rooms) => (
|
_SortKey groupKey(int index, IList<Room> rooms) => (
|
||||||
priority: rooms.map(priority).minOrNull ?? 2,
|
priority: rooms.map(priority).minOrNull ?? priority(null),
|
||||||
activity: rooms.map(activity).maxOrNull ?? .new(0),
|
activity: rooms.map(activity).maxOrNull ?? .new(0),
|
||||||
|
index: index,
|
||||||
);
|
);
|
||||||
|
|
||||||
IList<Room> sortRooms(IList<Room> rooms) =>
|
IList<Room> sortRooms(IList<Room> rooms) => .new(
|
||||||
rooms.sort((a, b) => compare(roomKey(a), roomKey(b)));
|
rooms.indexed
|
||||||
|
.sorted(
|
||||||
return .new(
|
(a, b) => compare(roomKey(a.$1, a.$2), roomKey(b.$1, b.$2)),
|
||||||
allSpaces.map((space) {
|
)
|
||||||
if (roomOrder == .spaceOrder && space.room != null) return space;
|
.map((entry) => entry.$2),
|
||||||
|
|
||||||
final subSpaces = space.subSpaces.sort(
|
|
||||||
(a, b) => compare(groupKey(a.children), groupKey(b.children)),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final childrenKey = groupKey(space.children);
|
final subSpaces = space.subSpaces.indexed
|
||||||
|
.map(
|
||||||
|
(entry) => (
|
||||||
|
subspace: entry.$2,
|
||||||
|
key: groupKey(entry.$1, entry.$2.children),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.sorted((a, b) => compare(a.key, b.key));
|
||||||
|
|
||||||
|
final childrenKey = groupKey(space.childrenIndex, space.children);
|
||||||
return space.copyWith(
|
return space.copyWith(
|
||||||
children: sortRooms(space.children),
|
children: sortRooms(space.children),
|
||||||
subSpaces: .new(
|
subSpaces: .new(
|
||||||
subSpaces.map(
|
subSpaces.map(
|
||||||
(subspace) =>
|
(entry) => entry.subspace.copyWith(
|
||||||
subspace.copyWith(children: sortRooms(subspace.children)),
|
children: sortRooms(entry.subspace.children),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
childrenIndex: subSpaces
|
childrenIndex: subSpaces
|
||||||
.where(
|
.where((entry) => compare(entry.key, childrenKey) < 0)
|
||||||
(subspace) =>
|
|
||||||
compare(groupKey(subspace.children), childrenKey) < 0,
|
|
||||||
)
|
|
||||||
.length,
|
.length,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -1 +1,6 @@
|
||||||
enum RoomOrder { unreadFirst, mentionedFirst, recentActivity, spaceOrder }
|
enum RoomOrder({required final bool byUnread, required final bool bySpace}) {
|
||||||
|
unreadFirst(byUnread: true, bySpace: false),
|
||||||
|
unreadFirstSpaceOrder(byUnread: true, bySpace: true),
|
||||||
|
recentActivity(byUnread: false, bySpace: false),
|
||||||
|
spaceOrder(byUnread: false, bySpace: true),
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ class const Settings({
|
||||||
final bool swipeToReply = false,
|
final bool swipeToReply = false,
|
||||||
final bool hideMembershipEvents = false,
|
final bool hideMembershipEvents = false,
|
||||||
final bool hideServerAclEvents = true,
|
final bool hideServerAclEvents = true,
|
||||||
|
@JsonKey(unknownEnumValue: RoomOrder.unreadFirst)
|
||||||
final RoomOrder roomOrder = .unreadFirst,
|
final RoomOrder roomOrder = .unreadFirst,
|
||||||
final NameColor nameColor = .powerLevel,
|
final NameColor nameColor = .powerLevel,
|
||||||
final ShowAndSend typingIndicators = .showAndSend,
|
final ShowAndSend typingIndicators = .showAndSend,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue