parent
b63fcc30b7
commit
432064e111
6 changed files with 99 additions and 60 deletions
|
|
@ -256,7 +256,7 @@ class SettingsSectionsController
|
||||||
),
|
),
|
||||||
.new(
|
.new(
|
||||||
title: "Room Ordering",
|
title: "Room Ordering",
|
||||||
description: "Sort rooms by recent activity, optionally showing mentioned and unread rooms first.",
|
description: "Sort rooms and subspaces by recent activity, optionally showing mentioned or 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),
|
||||||
|
|
@ -266,6 +266,7 @@ class SettingsSectionsController
|
||||||
options: RoomOrder.values,
|
options: RoomOrder.values,
|
||||||
getName: (option) => switch (option) {
|
getName: (option) => switch (option) {
|
||||||
.unreadFirst => "Mentioned, then unread",
|
.unreadFirst => "Mentioned, then unread",
|
||||||
|
.mentionedFirst => "Mentioned only",
|
||||||
.recentActivity => "Recent activity only",
|
.recentActivity => "Recent activity only",
|
||||||
},
|
},
|
||||||
onChanged: (value) => ref
|
onChanged: (value) => ref
|
||||||
|
|
|
||||||
|
|
@ -139,31 +139,57 @@ class SpacesController extends AsyncNotifier<IList<Space>> {
|
||||||
SettingsController.provider.selectAsync((data) => data.roomOrder),
|
SettingsController.provider.selectAsync((data) => data.roomOrder),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Mentioned -> Unread -> Other
|
int priority(Room room) => switch ((roomOrder, room.metadata)) {
|
||||||
int unreadPriority(Room room) => switch (room.metadata) {
|
(.recentActivity, _) => 0,
|
||||||
RoomMetadata(unreadHighlights: > 0) => 0,
|
(_, RoomMetadata(unreadHighlights: > 0)) => 0,
|
||||||
RoomMetadata(unreadNotifications: > 0) ||
|
(.mentionedFirst, _) => 1,
|
||||||
RoomMetadata(unreadMessages: > 0) => 1,
|
(.unreadFirst, RoomMetadata(unreadNotifications: > 0)) ||
|
||||||
_ => 2,
|
(.unreadFirst, RoomMetadata(unreadMessages: > 0)) => 1,
|
||||||
|
(.unreadFirst, _) => 2,
|
||||||
|
};
|
||||||
|
DateTime activity(Room room) => room.metadata?.sortingTimestamp ?? .new(0);
|
||||||
|
|
||||||
|
// Higher priority first, then most recent activity first
|
||||||
|
int compare(
|
||||||
|
({int priority, DateTime activity}) a,
|
||||||
|
({int priority, DateTime activity}) b,
|
||||||
|
) => switch (a.priority.compareTo(b.priority)) {
|
||||||
|
0 => b.activity.compareTo(a.activity),
|
||||||
|
final byPriority => byPriority,
|
||||||
};
|
};
|
||||||
|
|
||||||
return allSpaces
|
({int priority, DateTime activity}) roomKey(Room room) =>
|
||||||
.map(
|
(priority: priority(room), activity: activity(room));
|
||||||
(space) => space.copyWith(
|
|
||||||
children: space.children.sort((a, b) {
|
|
||||||
if (roomOrder == .unreadFirst) {
|
|
||||||
final byUnread = unreadPriority(a).compareTo(unreadPriority(b));
|
|
||||||
if (byUnread != 0) return byUnread;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Most recent activity first
|
({int priority, DateTime activity}) groupKey(IList<Room> rooms) => (
|
||||||
return (b.metadata?.sortingTimestamp ?? DateTime(0)).compareTo(
|
priority: rooms.map(priority).minOrNull ?? 2,
|
||||||
a.metadata?.sortingTimestamp ?? DateTime(0),
|
activity: rooms.map(activity).maxOrNull ?? .new(0),
|
||||||
);
|
);
|
||||||
}),
|
|
||||||
),
|
IList<Room> sortRooms(IList<Room> rooms) =>
|
||||||
|
rooms.sort((a, b) => compare(roomKey(a), roomKey(b)));
|
||||||
|
|
||||||
|
return allSpaces.map((space) {
|
||||||
|
final subSpaces = space.subSpaces
|
||||||
|
.map(
|
||||||
|
(subspace) =>
|
||||||
|
subspace.copyWith(children: sortRooms(subspace.children)),
|
||||||
)
|
)
|
||||||
.toIList();
|
.toIList()
|
||||||
|
.sort((a, b) => compare(groupKey(a.children), groupKey(b.children)));
|
||||||
|
|
||||||
|
final childrenKey = groupKey(space.children);
|
||||||
|
return space.copyWith(
|
||||||
|
children: sortRooms(space.children),
|
||||||
|
subSpaces: subSpaces,
|
||||||
|
childrenIndex: subSpaces
|
||||||
|
.where(
|
||||||
|
(subspace) =>
|
||||||
|
compare(groupKey(subspace.children), childrenKey) < 0,
|
||||||
|
)
|
||||||
|
.length,
|
||||||
|
);
|
||||||
|
}).toIList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static final provider = AsyncNotifierProvider<SpacesController, IList<Space>>(
|
static final provider = AsyncNotifierProvider<SpacesController, IList<Space>>(
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ import "package:nexus/models/room.dart";
|
||||||
import "package:nexus/models/space.dart";
|
import "package:nexus/models/space.dart";
|
||||||
|
|
||||||
extension GetAllChildRooms on Space {
|
extension GetAllChildRooms on Space {
|
||||||
IList<Room> get allChildRooms =>
|
IList<Room> get allChildRooms => subSpaces
|
||||||
children.addAll(subSpaces.expand((s) => s.children));
|
.map((subspace) => subspace.children)
|
||||||
|
.toIList()
|
||||||
|
.insert(childrenIndex, children)
|
||||||
|
.expand((rooms) => rooms)
|
||||||
|
.toIList();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
enum RoomOrder { unreadFirst, recentActivity }
|
enum RoomOrder { unreadFirst, mentionedFirst, recentActivity }
|
||||||
|
|
|
||||||
|
|
@ -14,4 +14,5 @@ class const Space({
|
||||||
final Room? room,
|
final Room? room,
|
||||||
required final IList<Room> children,
|
required final IList<Room> children,
|
||||||
required final IList<Subspace> subSpaces,
|
required final IList<Subspace> subSpaces,
|
||||||
|
final int childrenIndex = 0,
|
||||||
}) with _$Space;
|
}) with _$Space;
|
||||||
|
|
|
||||||
|
|
@ -94,16 +94,8 @@ class const RoomsPane({super.key}) extends ConsumerWidget {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (selectedSpace.children.isNotEmpty)
|
...selectedSpace.subSpaces
|
||||||
.new(
|
.map(
|
||||||
header: selectedSpace.room == null
|
|
||||||
? null
|
|
||||||
: const DividerWidget(Text("Rooms")),
|
|
||||||
destinations: selectedSpace.children.toDestinations(
|
|
||||||
isDm: isDm,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...selectedSpace.subSpaces.map(
|
|
||||||
(subSpace) => NavigationRailM3ESection(
|
(subSpace) => NavigationRailM3ESection(
|
||||||
header: DividerWidget(
|
header: DividerWidget(
|
||||||
Row(
|
Row(
|
||||||
|
|
@ -126,9 +118,24 @@ class const RoomsPane({super.key}) extends ConsumerWidget {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
destinations: subSpace.children.toDestinations(isDm: isDm),
|
destinations: subSpace.children.toDestinations(
|
||||||
|
isDm: isDm,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
.toIList()
|
||||||
|
// Sorted among the subspaces, matching allChildRooms
|
||||||
|
.insertAll(selectedSpace.childrenIndex, [
|
||||||
|
if (selectedSpace.children.isNotEmpty)
|
||||||
|
NavigationRailM3ESection(
|
||||||
|
header: selectedSpace.room == null
|
||||||
|
? null
|
||||||
|
: const DividerWidget(Text("Rooms")),
|
||||||
|
destinations: selectedSpace.children.toDestinations(
|
||||||
|
isDm: isDm,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]),
|
||||||
],
|
],
|
||||||
onDestinationSelected: (value) {
|
onDestinationSelected: (value) {
|
||||||
ref
|
ref
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue