Merge pull request #765 from GetStream/feat/queryAround
feat(llc, ui): Added a queryAround implementation
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
## Upcoming
|
||||
|
||||
✅ Added
|
||||
|
||||
- Extra properties added to `PaginationParams` to aid in fetching messages.
|
||||
|
||||
🐞 Fixed
|
||||
|
||||
- `closeConnection()` now uses `normalClosure` status when closing websocket.
|
||||
|
||||
@@ -60,8 +60,11 @@ class PaginationParams extends Equatable {
|
||||
/// ```
|
||||
const PaginationParams({
|
||||
this.limit = 10,
|
||||
this.before = 10,
|
||||
this.after = 10,
|
||||
this.offset,
|
||||
this.next,
|
||||
this.idAround,
|
||||
this.greaterThan,
|
||||
this.greaterThanOrEqual,
|
||||
this.lessThan,
|
||||
@@ -78,12 +81,22 @@ class PaginationParams extends Equatable {
|
||||
/// The amount of items requested from the APIs.
|
||||
final int limit;
|
||||
|
||||
/// The amount of items requested before message ID from the APIs.
|
||||
final int before;
|
||||
|
||||
/// The amount of items requested after message ID from the APIs.
|
||||
final int after;
|
||||
|
||||
/// The offset of requesting items.
|
||||
final int? offset;
|
||||
|
||||
/// A key used to paginate.
|
||||
final String? next;
|
||||
|
||||
/// Message ID to fetch messages around
|
||||
@JsonKey(name: 'id_around')
|
||||
final String? idAround;
|
||||
|
||||
/// Filter on ids greater than the given value.
|
||||
@JsonKey(name: 'id_gt')
|
||||
final String? greaterThan;
|
||||
@@ -106,7 +119,10 @@ class PaginationParams extends Equatable {
|
||||
/// Creates a copy of [PaginationParams] with specified attributes overridden.
|
||||
PaginationParams copyWith({
|
||||
int? limit,
|
||||
int? before,
|
||||
int? after,
|
||||
int? offset,
|
||||
String? idAround,
|
||||
String? next,
|
||||
String? greaterThan,
|
||||
String? greaterThanOrEqual,
|
||||
@@ -115,7 +131,10 @@ class PaginationParams extends Equatable {
|
||||
}) =>
|
||||
PaginationParams(
|
||||
limit: limit ?? this.limit,
|
||||
before: before ?? this.before,
|
||||
after: limit ?? this.after,
|
||||
offset: offset ?? this.offset,
|
||||
idAround: idAround ?? this.idAround,
|
||||
next: next ?? this.next,
|
||||
greaterThan: greaterThan ?? this.greaterThan,
|
||||
greaterThanOrEqual: greaterThanOrEqual ?? this.greaterThanOrEqual,
|
||||
@@ -126,8 +145,11 @@ class PaginationParams extends Equatable {
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
limit,
|
||||
before,
|
||||
after,
|
||||
offset,
|
||||
next,
|
||||
idAround,
|
||||
greaterThan,
|
||||
greaterThanOrEqual,
|
||||
lessThan,
|
||||
|
||||
@@ -21,8 +21,11 @@ Map<String, dynamic> _$SortOptionToJson<T>(SortOption<T> instance) =>
|
||||
PaginationParams _$PaginationParamsFromJson(Map<String, dynamic> json) =>
|
||||
PaginationParams(
|
||||
limit: json['limit'] as int? ?? 10,
|
||||
before: json['before'] as int? ?? 10,
|
||||
after: json['after'] as int? ?? 10,
|
||||
offset: json['offset'] as int?,
|
||||
next: json['next'] as String?,
|
||||
idAround: json['id_around'] as String?,
|
||||
greaterThan: json['id_gt'] as String?,
|
||||
greaterThanOrEqual: json['id_gte'] as String?,
|
||||
lessThan: json['id_lt'] as String?,
|
||||
@@ -32,6 +35,8 @@ PaginationParams _$PaginationParamsFromJson(Map<String, dynamic> json) =>
|
||||
Map<String, dynamic> _$PaginationParamsToJson(PaginationParams instance) {
|
||||
final val = <String, dynamic>{
|
||||
'limit': instance.limit,
|
||||
'before': instance.before,
|
||||
'after': instance.after,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
@@ -42,6 +47,7 @@ Map<String, dynamic> _$PaginationParamsToJson(PaginationParams instance) {
|
||||
|
||||
writeNotNull('offset', instance.offset);
|
||||
writeNotNull('next', instance.next);
|
||||
writeNotNull('id_around', instance.idAround);
|
||||
writeNotNull('id_gt', instance.greaterThan);
|
||||
writeNotNull('id_gte', instance.greaterThanOrEqual);
|
||||
writeNotNull('id_lt', instance.lessThan);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
✅ Added
|
||||
|
||||
- `MessageListView` now allows more better control over spacing after messages using `spacingWidgetBuilder`.
|
||||
- `StreamChannel` can now fetch messages around a message ID with the `queryAroundMessage` call.
|
||||
|
||||
🐞 Fixed
|
||||
|
||||
|
||||
@@ -227,13 +227,13 @@ class StreamChannelState extends State<StreamChannel> {
|
||||
preferOffline: preferOffline,
|
||||
);
|
||||
|
||||
Future<List<ChannelState>> _queryAtMessage({
|
||||
Future<ChannelState?> _queryAtMessage({
|
||||
String? messageId,
|
||||
int before = 20,
|
||||
int after = 20,
|
||||
bool preferOffline = false,
|
||||
}) async {
|
||||
if (channel.state == null) return [];
|
||||
if (channel.state == null) return null;
|
||||
channel.state!.isUpToDate = false;
|
||||
channel.state!.truncate();
|
||||
|
||||
@@ -245,23 +245,33 @@ class StreamChannelState extends State<StreamChannel> {
|
||||
preferOffline: preferOffline,
|
||||
);
|
||||
channel.state!.isUpToDate = true;
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
|
||||
return Future.wait([
|
||||
queryBeforeMessage(
|
||||
messageId,
|
||||
limit: before,
|
||||
preferOffline: preferOffline,
|
||||
),
|
||||
queryAfterMessage(
|
||||
messageId,
|
||||
limit: after,
|
||||
preferOffline: preferOffline,
|
||||
),
|
||||
]);
|
||||
return queryAroundMessage(
|
||||
messageId,
|
||||
before: before,
|
||||
after: after,
|
||||
preferOffline: preferOffline,
|
||||
);
|
||||
}
|
||||
|
||||
///
|
||||
Future<ChannelState> queryAroundMessage(
|
||||
String messageId, {
|
||||
int before = 20,
|
||||
int after = 20,
|
||||
bool preferOffline = false,
|
||||
}) =>
|
||||
channel.query(
|
||||
messagesPagination: PaginationParams(
|
||||
idAround: messageId,
|
||||
before: before,
|
||||
after: after,
|
||||
),
|
||||
preferOffline: preferOffline,
|
||||
);
|
||||
|
||||
///
|
||||
Future<ChannelState> queryBeforeMessage(
|
||||
String messageId, {
|
||||
|
||||
Reference in New Issue
Block a user