chore(repo): remove deprecated code.
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -251,39 +251,18 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
|
||||
@override
|
||||
Future<List<ChannelState>> getChannelStates({
|
||||
Filter? filter,
|
||||
@Deprecated('Use channelStateSort instead.')
|
||||
List<SortOption<ChannelModel>>? sort,
|
||||
List<SortOption<ChannelState>>? channelStateSort,
|
||||
PaginationParams? paginationParams,
|
||||
}) async {
|
||||
assert(_debugIsConnected, '');
|
||||
assert(
|
||||
sort == null || channelStateSort == null,
|
||||
'sort and channelStateSort cannot be used together',
|
||||
);
|
||||
_logger.info('getChannelStates');
|
||||
|
||||
final channels = await db!.channelQueryDao.getChannels(
|
||||
filter: filter,
|
||||
sort: sort,
|
||||
);
|
||||
final channels = await db!.channelQueryDao.getChannels(filter: filter);
|
||||
|
||||
final channelStates = await Future.wait(
|
||||
channels.map((e) => getChannelStateByCid(e.cid)),
|
||||
);
|
||||
|
||||
// Only sort the channel states if the channels are not already sorted.
|
||||
if (sort == null) {
|
||||
var comparator = _defaultChannelStateComparator;
|
||||
if (channelStateSort != null && channelStateSort.isNotEmpty) {
|
||||
comparator = _combineComparators(
|
||||
channelStateSort.map((it) => it.comparator).withNullifyer,
|
||||
);
|
||||
}
|
||||
|
||||
channelStates.sort(comparator);
|
||||
}
|
||||
|
||||
final offset = paginationParams?.offset;
|
||||
if (offset != null && offset > 0 && channelStates.isNotEmpty) {
|
||||
channelStates.removeRange(0, offset);
|
||||
@@ -421,35 +400,3 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Creates a new combined [Comparator] which sorts items
|
||||
// by the given [comparators].
|
||||
Comparator<T> _combineComparators<T>(Iterable<Comparator<T>> comparators) {
|
||||
return (T a, T b) {
|
||||
for (final comparator in comparators) {
|
||||
try {
|
||||
final result = comparator(a, b);
|
||||
if (result != 0) return result;
|
||||
} catch (e) {
|
||||
// If the comparator throws an exception, we ignore it and
|
||||
// continue with the next comparator.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
// The default [Comparator] used to sort [ChannelState]s.
|
||||
int _defaultChannelStateComparator(ChannelState a, ChannelState b) {
|
||||
final dateA = a.channel?.lastMessageAt ?? a.channel?.createdAt;
|
||||
final dateB = b.channel?.lastMessageAt ?? b.channel?.createdAt;
|
||||
|
||||
if (dateA == null && dateB == null) return 0;
|
||||
if (dateA == null) return 1;
|
||||
if (dateB == null) {
|
||||
return -1;
|
||||
} else {
|
||||
return dateB.compareTo(dateA);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,6 @@ void main() {
|
||||
// Should match with the inserted channels
|
||||
final updatedChannels = await channelQueryDao.getChannels(
|
||||
filter: filter,
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
sort: [
|
||||
SortOption(
|
||||
'member_count',
|
||||
@@ -196,7 +195,6 @@ void main() {
|
||||
// Should match with the inserted channels
|
||||
final updatedChannels = await channelQueryDao.getChannels(
|
||||
filter: filter,
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
sort: [SortOption('test_custom_field', comparator: sortComparator)],
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user