chore(ui): add support for presence.
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
+28
-8
@@ -12,13 +12,14 @@ typedef ChannelListEventHandler = void Function(
|
|||||||
StreamChannelListController controller,
|
StreamChannelListController controller,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// A controller for the channel list view.
|
///
|
||||||
class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
||||||
/// Creates a [StreamChannelListController].
|
/// Creates a new instance of [StreamChannelListController].
|
||||||
StreamChannelListController({
|
StreamChannelListController({
|
||||||
required this.client,
|
required this.client,
|
||||||
this.filter,
|
this.filter,
|
||||||
this.sort,
|
this.sort,
|
||||||
|
this.presence = true,
|
||||||
this.limit = defaultChannelPagedLimit,
|
this.limit = defaultChannelPagedLimit,
|
||||||
this.messageLimit,
|
this.messageLimit,
|
||||||
this.memberLimit,
|
this.memberLimit,
|
||||||
@@ -43,6 +44,7 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
required this.client,
|
required this.client,
|
||||||
this.filter,
|
this.filter,
|
||||||
this.sort,
|
this.sort,
|
||||||
|
this.presence = true,
|
||||||
this.limit = defaultChannelPagedLimit,
|
this.limit = defaultChannelPagedLimit,
|
||||||
this.messageLimit,
|
this.messageLimit,
|
||||||
this.memberLimit,
|
this.memberLimit,
|
||||||
@@ -64,21 +66,31 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
/// The client to use for the channel list.
|
/// The client to use for the channel list.
|
||||||
final StreamChatClient client;
|
final StreamChatClient client;
|
||||||
|
|
||||||
/// The filter to apply to the channel list.
|
/// The query filters to use.
|
||||||
|
/// You can query on any of the custom fields you've defined on the [Channel].
|
||||||
|
/// You can also filter other built-in channel fields.
|
||||||
final Filter? filter;
|
final Filter? filter;
|
||||||
|
|
||||||
/// The sort to apply to the channel list.
|
/// The sorting used for the channels matching the filters.
|
||||||
|
/// Sorting is based on field and direction, multiple sorting options
|
||||||
|
/// can be provided.
|
||||||
|
/// You can sort based on last_updated, last_message_at, updated_at,
|
||||||
|
/// created_at or member_count.
|
||||||
|
/// Direction can be ascending or descending.
|
||||||
final List<SortOption<ChannelModel>>? sort;
|
final List<SortOption<ChannelModel>>? sort;
|
||||||
|
|
||||||
|
/// If true you’ll receive user presence updates via the websocket events
|
||||||
|
final bool presence;
|
||||||
|
|
||||||
/// The limit to apply to the channel list.
|
/// The limit to apply to the channel list.
|
||||||
final int limit;
|
final int limit;
|
||||||
|
|
||||||
/// The limit to apply to the message list.
|
/// Number of members to fetch in each channel
|
||||||
final int? messageLimit;
|
|
||||||
|
|
||||||
/// The limit to apply to the member list.
|
|
||||||
final int? memberLimit;
|
final int? memberLimit;
|
||||||
|
|
||||||
|
/// Number of messages to fetch in each channel
|
||||||
|
final int? messageLimit;
|
||||||
|
|
||||||
/// Callback function which gets called for the event
|
/// Callback function which gets called for the event
|
||||||
/// [EventType.channelDeleted].
|
/// [EventType.channelDeleted].
|
||||||
///
|
///
|
||||||
@@ -164,6 +176,7 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
sort: sort,
|
sort: sort,
|
||||||
memberLimit: memberLimit,
|
memberLimit: memberLimit,
|
||||||
messageLimit: messageLimit,
|
messageLimit: messageLimit,
|
||||||
|
presence: presence,
|
||||||
paginationParams: PaginationParams(limit: limit),
|
paginationParams: PaginationParams(limit: limit),
|
||||||
)) {
|
)) {
|
||||||
final nextKey = channels.length < limit ? null : channels.length;
|
final nextKey = channels.length < limit ? null : channels.length;
|
||||||
@@ -176,6 +189,9 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
_subscribeToChannelListEvents();
|
_subscribeToChannelListEvents();
|
||||||
} on StreamChatError catch (error) {
|
} on StreamChatError catch (error) {
|
||||||
value = PagedValue.error(error);
|
value = PagedValue.error(error);
|
||||||
|
} catch (error) {
|
||||||
|
final chatError = StreamChatError(error.toString());
|
||||||
|
value = PagedValue.error(chatError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,6 +205,7 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
sort: sort,
|
sort: sort,
|
||||||
memberLimit: memberLimit,
|
memberLimit: memberLimit,
|
||||||
messageLimit: messageLimit,
|
messageLimit: messageLimit,
|
||||||
|
presence: presence,
|
||||||
paginationParams: PaginationParams(limit: limit, offset: nextPageKey),
|
paginationParams: PaginationParams(limit: limit, offset: nextPageKey),
|
||||||
)) {
|
)) {
|
||||||
final previousItems = previousValue.items;
|
final previousItems = previousValue.items;
|
||||||
@@ -201,6 +218,9 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
}
|
}
|
||||||
} on StreamChatError catch (error) {
|
} on StreamChatError catch (error) {
|
||||||
value = previousValue.copyWith(error: error);
|
value = previousValue.copyWith(error: error);
|
||||||
|
} catch (error) {
|
||||||
|
final chatError = StreamChatError(error.toString());
|
||||||
|
value = previousValue.copyWith(error: chatError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user