Add custom sort support for offline channels

Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
Sahil Kumar
2021-02-26 18:30:22 +05:30
parent aeecc71154
commit 623d48e32b
13 changed files with 394 additions and 442 deletions
@@ -1245,7 +1245,9 @@ class ChannelClientState {
_channel._client.chatPersistenceClient
?.getChannelStateByCid(_channel.cid)
?.then((state) {
updateChannelState(state);
// Replacing the persistence state members with the latest `channelState.members`
// as they may have changes over the time.
updateChannelState(state.copyWith(members: channelState.members));
retryFailedMessages();
});
});
+11 -3
View File
@@ -4,7 +4,7 @@ part 'requests.g.dart';
/// Sorting options
@JsonSerializable(createFactory: false)
class SortOption {
class SortOption<T> {
/// Ascending order
static const ASC = 1;
@@ -17,6 +17,10 @@ class SortOption {
/// A sorting direction
final int direction;
/// Sorting field Comparator required for offline sorting
@JsonKey(ignore: true)
final Comparator<T> comparator;
/// Creates a new SortOption instance
///
/// For example:
@@ -24,7 +28,11 @@ class SortOption {
/// // Sort channels by the last message date:
/// final sorting = SortOption("last_message_at")
/// ```
const SortOption(this.field, {this.direction = DESC});
const SortOption(
this.field, {
this.direction = DESC,
this.comparator,
});
/// Serialize model to json
Map<String, dynamic> toJson() => _$SortOptionToJson(this);
@@ -67,7 +75,7 @@ class PaginationParams {
/// ```
const PaginationParams({
this.limit = 10,
this.offset,
this.offset = 0,
this.greaterThan,
this.greaterThanOrEqual,
this.lessThan,