Skip to content

Commit dcbdf9b

Browse files
committed
Update sorting
1 parent b2c28f5 commit dcbdf9b

File tree

3 files changed

+11
-25
lines changed

3 files changed

+11
-25
lines changed

packages/stream_chat/lib/src/core/models/channel_state.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class ChannelState implements ComparableFieldProvider {
8585
ChannelSortKey.lastMessageAt => channel?.lastMessageAt,
8686
ChannelSortKey.memberCount => channel?.memberCount,
8787
ChannelSortKey.pinnedAt => membership?.pinnedAt,
88+
ChannelSortKey.archivedAt => membership?.archivedAt,
8889
// TODO: Support providing default value for hasUnread, unreadCount
8990
ChannelSortKey.hasUnread => null,
9091
ChannelSortKey.unreadCount => null,
@@ -125,4 +126,7 @@ extension type const ChannelSortKey(String key) implements String {
125126

126127
/// Sort channels by the date they were pinned.
127128
static const pinnedAt = ChannelSortKey('pinned_at');
129+
130+
/// Sort channels by the date they were archived.
131+
static const archivedAt = ChannelSortKey('archived_at');
128132
}

packages/stream_chat_flutter_core/lib/src/stream_channel_list_controller.dart

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,6 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
196196
}
197197
}
198198

199-
/// Sorts the channels based on [channelStateSort] and sets the [channels].
200-
void setAndSortChannels(List<Channel> channels) {
201-
_sortChannels(channels);
202-
this.channels = channels;
203-
}
204-
205199
/// Returns/Creates a new Channel and starts watching it.
206200
Future<Channel> getChannel({
207201
required String id,
@@ -304,18 +298,6 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
304298
_channelEventSubscription?.resume();
305299
}
306300

307-
void _sortChannels(List<Channel> channels) {
308-
if (channelStateSort case final sortOrder?) {
309-
channels.sort((a, b) {
310-
final stateA = a.state?.channelState;
311-
final stateB = b.state?.channelState;
312-
if (stateA == null || stateB == null) return 0;
313-
314-
return sortOrder.compare(stateA, stateB);
315-
});
316-
}
317-
}
318-
319301
@override
320302
void dispose() {
321303
_unsubscribeFromChannelListEvents();

packages/stream_chat_flutter_core/lib/src/stream_channel_list_event_handler.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mixin class StreamChannelListEventHandler {
2020
(it) => it.cid == (event.cid ?? event.channel?.cid),
2121
);
2222

23-
controller.setAndSortChannels(updatedChannels);
23+
controller.channels = updatedChannels;
2424
}
2525

2626
/// Function which gets called for the event
@@ -50,7 +50,7 @@ mixin class StreamChannelListEventHandler {
5050
///
5151
/// By default, this updates the channel received in the event.
5252
void onChannelUpdated(Event event, StreamChannelListController controller) {
53-
controller.setAndSortChannels([...controller.currentItems]);
53+
controller.channels = [...controller.currentItems];
5454
}
5555

5656
/// Function which gets called for the event
@@ -60,7 +60,7 @@ mixin class StreamChannelListEventHandler {
6060
///
6161
/// By default, this sorts the channels.
6262
void onMemberUpdated(Event event, StreamChannelListController controller) {
63-
controller.setAndSortChannels([...controller.currentItems]);
63+
controller.channels = [...controller.currentItems];
6464
}
6565

6666
/// Function which gets called for the event
@@ -90,7 +90,7 @@ mixin class StreamChannelListEventHandler {
9090
...currentChannels..removeWhere((it) => it.cid == channel.cid),
9191
];
9292

93-
controller.setAndSortChannels(updatedChannels);
93+
controller.channels = updatedChannels;
9494
}
9595

9696
/// Function which gets called for the event
@@ -129,7 +129,7 @@ mixin class StreamChannelListEventHandler {
129129
final channel = channels.removeAt(channelIndex);
130130
channels.insert(0, channel);
131131

132-
controller.setAndSortChannels(channels);
132+
controller.channels = [...channels];
133133
}
134134

135135
/// Function which gets called for the event
@@ -177,7 +177,7 @@ mixin class StreamChannelListEventHandler {
177177

178178
if (!listChanged) return;
179179

180-
controller.setAndSortChannels([...updatedChannels]);
180+
controller.channels = [...updatedChannels];
181181
}
182182

183183
/// Function which gets called for the event
@@ -220,6 +220,6 @@ mixin class StreamChannelListEventHandler {
220220
return channel;
221221
});
222222

223-
controller.setAndSortChannels([...updatedChannels]);
223+
controller.channels = [...updatedChannels];
224224
}
225225
}

0 commit comments

Comments
 (0)