fix(llc, ui): message search pagination
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -36,6 +36,10 @@ class GeneralApi {
|
||||
PaginationParams? pagination,
|
||||
Filter? messageFilters,
|
||||
}) async {
|
||||
assert(
|
||||
pagination?.offset == null || pagination?.offset == 0 || sort == null,
|
||||
'Cannot specify `offset` with `sort` parameter',
|
||||
);
|
||||
assert(() {
|
||||
if (query == null && messageFilters == null) {
|
||||
throw ArgumentError('Provide at least `query` or `messageFilters`');
|
||||
|
||||
@@ -60,12 +60,16 @@ class PaginationParams extends Equatable {
|
||||
/// ```
|
||||
const PaginationParams({
|
||||
this.limit = 10,
|
||||
this.offset = 0,
|
||||
this.offset,
|
||||
this.next,
|
||||
this.greaterThan,
|
||||
this.greaterThanOrEqual,
|
||||
this.lessThan,
|
||||
this.lessThanOrEqual,
|
||||
});
|
||||
}) : assert(
|
||||
offset == null || offset == 0 || next == null,
|
||||
'Cannot specify non-zero `offset` with `next` parameter',
|
||||
);
|
||||
|
||||
/// Create a new instance from a json
|
||||
factory PaginationParams.fromJson(Map<String, dynamic> json) =>
|
||||
@@ -75,7 +79,10 @@ class PaginationParams extends Equatable {
|
||||
final int limit;
|
||||
|
||||
/// The offset of requesting items.
|
||||
final int offset;
|
||||
final int? offset;
|
||||
|
||||
/// A key used to paginate.
|
||||
final String? next;
|
||||
|
||||
/// Filter on ids greater than the given value.
|
||||
@JsonKey(name: 'id_gt')
|
||||
@@ -100,6 +107,7 @@ class PaginationParams extends Equatable {
|
||||
PaginationParams copyWith({
|
||||
int? limit,
|
||||
int? offset,
|
||||
String? next,
|
||||
String? greaterThan,
|
||||
String? greaterThanOrEqual,
|
||||
String? lessThan,
|
||||
@@ -108,6 +116,7 @@ class PaginationParams extends Equatable {
|
||||
PaginationParams(
|
||||
limit: limit ?? this.limit,
|
||||
offset: offset ?? this.offset,
|
||||
next: next ?? this.next,
|
||||
greaterThan: greaterThan ?? this.greaterThan,
|
||||
greaterThanOrEqual: greaterThanOrEqual ?? this.greaterThanOrEqual,
|
||||
lessThan: lessThan ?? this.lessThan,
|
||||
@@ -118,6 +127,7 @@ class PaginationParams extends Equatable {
|
||||
List<Object?> get props => [
|
||||
limit,
|
||||
offset,
|
||||
next,
|
||||
greaterThan,
|
||||
greaterThanOrEqual,
|
||||
lessThan,
|
||||
|
||||
@@ -23,6 +23,7 @@ PaginationParams _$PaginationParamsFromJson(Map<String, dynamic> json) {
|
||||
return PaginationParams(
|
||||
limit: json['limit'] as int,
|
||||
offset: json['offset'] as int,
|
||||
next: json['next'] as String?,
|
||||
greaterThan: json['id_gt'] as String?,
|
||||
greaterThanOrEqual: json['id_gte'] as String?,
|
||||
lessThan: json['id_lt'] as String?,
|
||||
@@ -42,6 +43,7 @@ Map<String, dynamic> _$PaginationParamsToJson(PaginationParams instance) {
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('next', instance.next);
|
||||
writeNotNull('id_gt', instance.greaterThan);
|
||||
writeNotNull('id_gte', instance.greaterThanOrEqual);
|
||||
writeNotNull('id_lt', instance.lessThan);
|
||||
|
||||
@@ -253,6 +253,12 @@ class SearchMessagesResponse extends _BaseResponse {
|
||||
@JsonKey(defaultValue: [])
|
||||
late List<GetMessageResponse> results;
|
||||
|
||||
/// Message id of where to start searching from for next [results]
|
||||
late String? next;
|
||||
|
||||
/// Message id of where to start searching from for previous [results]
|
||||
late String? previous;
|
||||
|
||||
/// Create a new instance from a json
|
||||
static SearchMessagesResponse fromJson(Map<String, dynamic> json) =>
|
||||
_$SearchMessagesResponseFromJson(json);
|
||||
|
||||
@@ -161,7 +161,9 @@ SearchMessagesResponse _$SearchMessagesResponseFromJson(
|
||||
..results = (json['results'] as List<dynamic>?)
|
||||
?.map((e) => GetMessageResponse.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[];
|
||||
[]
|
||||
..next = json['next'] as String?
|
||||
..previous = json['previous'] as String?;
|
||||
}
|
||||
|
||||
GetMessagesByIdResponse _$GetMessagesByIdResponseFromJson(
|
||||
|
||||
Reference in New Issue
Block a user