refactor(llc): minor event handler changes.
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
-123
@@ -1,123 +0,0 @@
|
|||||||
import 'package:stream_chat/stream_chat.dart' hide Success;
|
|
||||||
import 'package:stream_chat_flutter/src/v4/channel_list_view/stream_channel_list_controller.dart';
|
|
||||||
import 'package:stream_chat_flutter/src/v4/channel_list_view/stream_channel_list_event_handler.dart'
|
|
||||||
as event_handler;
|
|
||||||
|
|
||||||
/// Contains handlers that are called from [StreamChannelListController] for
|
|
||||||
/// certain [Event]s.
|
|
||||||
///
|
|
||||||
/// This class can be mixed in or extended to create custom overrides.
|
|
||||||
class ChannelEventHandlers {
|
|
||||||
/// Function which gets called for the event
|
|
||||||
/// [EventType.channelDeleted].
|
|
||||||
///
|
|
||||||
/// By default, calls [event_handler.onChannelDeleted]
|
|
||||||
/// with the [Event] and the [StreamChannelListController].
|
|
||||||
void onChannelDeleted(Event event, StreamChannelListController controller) {
|
|
||||||
event_handler.onChannelDeleted(event, controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Function which gets called for the event
|
|
||||||
/// [EventType.channelHidden].
|
|
||||||
///
|
|
||||||
/// By default, calls [event_handler.onChannelHidden]
|
|
||||||
/// with the [Event] and the [StreamChannelListController].
|
|
||||||
void onChannelHidden(Event event, StreamChannelListController controller) {
|
|
||||||
event_handler.onChannelHidden(event, controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Function which gets called for the event
|
|
||||||
/// [EventType.channelTruncated].
|
|
||||||
///
|
|
||||||
/// By default, calls [event_handler.onChannelTruncated]
|
|
||||||
/// with the [Event] and the [StreamChannelListController].
|
|
||||||
void onChannelTruncated(Event event, StreamChannelListController controller) {
|
|
||||||
event_handler.onChannelTruncated(event, controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Function which gets called for the event
|
|
||||||
/// [EventType.channelUpdated].
|
|
||||||
///
|
|
||||||
/// By default, calls [event_handler.onChannelUpdated]
|
|
||||||
/// with the [Event] and the [StreamChannelListController].
|
|
||||||
void onChannelUpdated(Event event, StreamChannelListController controller) {
|
|
||||||
event_handler.onChannelUpdated(event, controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Function which gets called for the event
|
|
||||||
/// [EventType.channelVisible].
|
|
||||||
///
|
|
||||||
/// By default, calls [event_handler.onChannelVisible]
|
|
||||||
/// with the [Event] and the [StreamChannelListController].
|
|
||||||
void onChannelVisible(Event event, StreamChannelListController controller) {
|
|
||||||
event_handler.onChannelVisible(event, controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Function which gets called for the event
|
|
||||||
/// [EventType.connectionRecovered].
|
|
||||||
///
|
|
||||||
/// By default, calls [event_handler.onConnectionRecovered]
|
|
||||||
/// with the [Event] and the [StreamChannelListController].
|
|
||||||
void onConnectionRecovered(
|
|
||||||
Event event,
|
|
||||||
StreamChannelListController controller,
|
|
||||||
) {
|
|
||||||
event_handler.onConnectionRecovered(event, controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Function which gets called for the event [EventType.messageNew].
|
|
||||||
///
|
|
||||||
/// By default, calls [event_handler.onMessageNew]
|
|
||||||
/// with the [Event] and the [StreamChannelListController].
|
|
||||||
void onMessageNew(Event event, StreamChannelListController controller) {
|
|
||||||
event_handler.onMessageNew(event, controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Function which gets called for the event
|
|
||||||
/// [EventType.notificationAddedToChannel].
|
|
||||||
///
|
|
||||||
/// By default, calls [event_handler.onNotificationAddedToChannel]
|
|
||||||
/// with the [Event] and the [StreamChannelListController].
|
|
||||||
void onNotificationAddedToChannel(
|
|
||||||
Event event,
|
|
||||||
StreamChannelListController controller,
|
|
||||||
) {
|
|
||||||
event_handler.onNotificationAddedToChannel(event, controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Function which gets called for the event
|
|
||||||
/// [EventType.notificationMessageNew].
|
|
||||||
///
|
|
||||||
/// By default, calls [event_handler.onNotificationMessageNew]
|
|
||||||
/// with the [Event] and the [StreamChannelListController].
|
|
||||||
void onNotificationMessageNew(
|
|
||||||
Event event,
|
|
||||||
StreamChannelListController controller,
|
|
||||||
) {
|
|
||||||
event_handler.onNotificationMessageNew(event, controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Function which gets called for the event
|
|
||||||
/// [EventType.notificationRemovedFromChannel].
|
|
||||||
///
|
|
||||||
/// By default, calls [event_handler.onNotificationRemovedFromChannel]
|
|
||||||
/// with the [Event] and the [StreamChannelListController].
|
|
||||||
void onNotificationRemovedFromChannel(
|
|
||||||
Event event,
|
|
||||||
StreamChannelListController controller,
|
|
||||||
) {
|
|
||||||
event_handler.onNotificationRemovedFromChannel(event, controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Function which gets called for the event
|
|
||||||
/// 'user.presence.changed' and [EventType.userUpdated].
|
|
||||||
///
|
|
||||||
/// By default, calls [event_handler.onUserPresenceChanged]
|
|
||||||
/// with the [Event] and the [StreamChannelListController].
|
|
||||||
void onUserPresenceChanged(
|
|
||||||
Event event,
|
|
||||||
StreamChannelListController controller,
|
|
||||||
) {
|
|
||||||
event_handler.onUserPresenceChanged(event, controller);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+26
-22
@@ -2,7 +2,7 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:stream_chat/stream_chat.dart' hide Success;
|
import 'package:stream_chat/stream_chat.dart' hide Success;
|
||||||
import 'package:stream_chat_flutter/src/paged_value_notifier.dart';
|
import 'package:stream_chat_flutter/src/paged_value_notifier.dart';
|
||||||
import 'package:stream_chat_flutter/src/v4/channel_list_view/channel_event_handlers.dart';
|
import 'package:stream_chat_flutter/src/v4/channel_list_view/stream_channel_list_event_handler.dart';
|
||||||
|
|
||||||
/// The default channel page limit to load.
|
/// The default channel page limit to load.
|
||||||
const defaultChannelPagedLimit = 10;
|
const defaultChannelPagedLimit = 10;
|
||||||
@@ -15,7 +15,6 @@ const defaultChannelPagedLimit = 10;
|
|||||||
/// * Load more data using [loadMore].
|
/// * Load more data using [loadMore].
|
||||||
/// * Replace the previously loaded channels.
|
/// * Replace the previously loaded channels.
|
||||||
/// * Return/Create a new channel and start watching it.
|
/// * Return/Create a new channel and start watching it.
|
||||||
/// * Unsubscribe from all channel list events.
|
|
||||||
/// * Pause and Resume all subscriptions added to this composite.
|
/// * Pause and Resume all subscriptions added to this composite.
|
||||||
class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
||||||
/// Creates a Stream channel list controller.
|
/// Creates a Stream channel list controller.
|
||||||
@@ -24,7 +23,7 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
///
|
///
|
||||||
/// * `channelEventHandlers` is the channel events to use for the channels
|
/// * `channelEventHandlers` is the channel events to use for the channels
|
||||||
/// list. This class can be mixed in or extended to create custom overrides.
|
/// list. This class can be mixed in or extended to create custom overrides.
|
||||||
/// See [ChannelEventHandlers] for advice.
|
/// See [StreamChannelListEventHandler] for advice.
|
||||||
///
|
///
|
||||||
/// * `filter` is the query filters to use.
|
/// * `filter` is the query filters to use.
|
||||||
///
|
///
|
||||||
@@ -40,46 +39,51 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
/// * `memberLimit` is the number of members to fetch in each channel.
|
/// * `memberLimit` is the number of members to fetch in each channel.
|
||||||
StreamChannelListController({
|
StreamChannelListController({
|
||||||
required this.client,
|
required this.client,
|
||||||
ChannelEventHandlers? channelEventHandlers,
|
StreamChannelListEventHandler? eventHandler,
|
||||||
this.filter,
|
this.filter,
|
||||||
this.sort,
|
this.sort,
|
||||||
this.presence = true,
|
this.presence = true,
|
||||||
this.limit = defaultChannelPagedLimit,
|
this.limit = defaultChannelPagedLimit,
|
||||||
this.messageLimit,
|
this.messageLimit,
|
||||||
this.memberLimit,
|
this.memberLimit,
|
||||||
}) : _channelEventHandlers = channelEventHandlers ?? ChannelEventHandlers(),
|
}) : _eventHandler = eventHandler ?? StreamChannelListEventHandler(),
|
||||||
super(const PagedValue.loading());
|
super(const PagedValue.loading());
|
||||||
|
|
||||||
/// Creates a [StreamChannelListController] from the passed [value].
|
/// Creates a [StreamChannelListController] from the passed [value].
|
||||||
StreamChannelListController.fromValue(
|
StreamChannelListController.fromValue(
|
||||||
PagedValue<int, Channel> value, {
|
PagedValue<int, Channel> value, {
|
||||||
required this.client,
|
required this.client,
|
||||||
ChannelEventHandlers? channelEventHandlers,
|
StreamChannelListEventHandler? eventHandler,
|
||||||
this.filter,
|
this.filter,
|
||||||
this.sort,
|
this.sort,
|
||||||
this.presence = true,
|
this.presence = true,
|
||||||
this.limit = defaultChannelPagedLimit,
|
this.limit = defaultChannelPagedLimit,
|
||||||
this.messageLimit,
|
this.messageLimit,
|
||||||
this.memberLimit,
|
this.memberLimit,
|
||||||
}) : _channelEventHandlers = channelEventHandlers ?? ChannelEventHandlers(),
|
}) : _eventHandler = eventHandler ?? StreamChannelListEventHandler(),
|
||||||
super(value);
|
super(value);
|
||||||
|
|
||||||
/// The channel events to use for the channels list.
|
|
||||||
final ChannelEventHandlers _channelEventHandlers;
|
|
||||||
|
|
||||||
/// The client to use for the channels list.
|
/// The client to use for the channels list.
|
||||||
final StreamChatClient client;
|
final StreamChatClient client;
|
||||||
|
|
||||||
|
/// The channel event handlers to use for the channels list.
|
||||||
|
final StreamChannelListEventHandler _eventHandler;
|
||||||
|
|
||||||
/// The query filters to use.
|
/// The query filters to use.
|
||||||
|
///
|
||||||
/// You can query on any of the custom fields you've defined on the [Channel].
|
/// You can query on any of the custom fields you've defined on the [Channel].
|
||||||
|
///
|
||||||
/// You can also filter other built-in channel fields.
|
/// You can also filter other built-in channel fields.
|
||||||
final Filter? filter;
|
final Filter? filter;
|
||||||
|
|
||||||
/// The sorting used for the channels matching the filters.
|
/// The sorting used for the channels matching the filters.
|
||||||
|
///
|
||||||
/// Sorting is based on field and direction, multiple sorting options
|
/// Sorting is based on field and direction, multiple sorting options
|
||||||
/// can be provided.
|
/// can be provided.
|
||||||
|
///
|
||||||
/// You can sort based on last_updated, last_message_at, updated_at,
|
/// You can sort based on last_updated, last_message_at, updated_at,
|
||||||
/// created_at or member_count.
|
/// created_at or member_count.
|
||||||
|
///
|
||||||
/// Direction can be ascending or descending.
|
/// Direction can be ascending or descending.
|
||||||
final List<SortOption<ChannelModel>>? sort;
|
final List<SortOption<ChannelModel>>? sort;
|
||||||
|
|
||||||
@@ -183,32 +187,32 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
_channelEventSubscription = client.on().listen((event) {
|
_channelEventSubscription = client.on().listen((event) {
|
||||||
final eventType = event.type;
|
final eventType = event.type;
|
||||||
if (eventType == EventType.channelDeleted) {
|
if (eventType == EventType.channelDeleted) {
|
||||||
_channelEventHandlers.onChannelDeleted(event, this);
|
_eventHandler.onChannelDeleted(event, this);
|
||||||
} else if (eventType == EventType.channelHidden) {
|
} else if (eventType == EventType.channelHidden) {
|
||||||
_channelEventHandlers.onChannelHidden(event, this);
|
_eventHandler.onChannelHidden(event, this);
|
||||||
} else if (eventType == EventType.channelTruncated) {
|
} else if (eventType == EventType.channelTruncated) {
|
||||||
_channelEventHandlers.onChannelTruncated(event, this);
|
_eventHandler.onChannelTruncated(event, this);
|
||||||
} else if (eventType == EventType.channelUpdated) {
|
} else if (eventType == EventType.channelUpdated) {
|
||||||
_channelEventHandlers.onChannelUpdated(event, this);
|
_eventHandler.onChannelUpdated(event, this);
|
||||||
} else if (eventType == EventType.channelVisible) {
|
} else if (eventType == EventType.channelVisible) {
|
||||||
_channelEventHandlers.onChannelVisible(event, this);
|
_eventHandler.onChannelVisible(event, this);
|
||||||
} else if (eventType == EventType.connectionRecovered) {
|
} else if (eventType == EventType.connectionRecovered) {
|
||||||
_channelEventHandlers.onConnectionRecovered(event, this);
|
_eventHandler.onConnectionRecovered(event, this);
|
||||||
} else if (eventType == EventType.connectionChanged) {
|
} else if (eventType == EventType.connectionChanged) {
|
||||||
if (event.online != null) {
|
if (event.online != null) {
|
||||||
_channelEventHandlers.onConnectionRecovered(event, this);
|
_eventHandler.onConnectionRecovered(event, this);
|
||||||
}
|
}
|
||||||
} else if (eventType == EventType.messageNew) {
|
} else if (eventType == EventType.messageNew) {
|
||||||
_channelEventHandlers.onMessageNew(event, this);
|
_eventHandler.onMessageNew(event, this);
|
||||||
} else if (eventType == EventType.notificationAddedToChannel) {
|
} else if (eventType == EventType.notificationAddedToChannel) {
|
||||||
_channelEventHandlers.onNotificationAddedToChannel(event, this);
|
_eventHandler.onNotificationAddedToChannel(event, this);
|
||||||
} else if (eventType == EventType.notificationMessageNew) {
|
} else if (eventType == EventType.notificationMessageNew) {
|
||||||
_channelEventHandlers.onNotificationMessageNew(event, this);
|
_eventHandler.onNotificationMessageNew(event, this);
|
||||||
} else if (eventType == EventType.notificationRemovedFromChannel) {
|
} else if (eventType == EventType.notificationRemovedFromChannel) {
|
||||||
_channelEventHandlers.onNotificationRemovedFromChannel(event, this);
|
_eventHandler.onNotificationRemovedFromChannel(event, this);
|
||||||
} else if (eventType == 'user.presence.changed' ||
|
} else if (eventType == 'user.presence.changed' ||
|
||||||
eventType == EventType.userUpdated) {
|
eventType == EventType.userUpdated) {
|
||||||
_channelEventHandlers.onUserPresenceChanged(event, this);
|
_eventHandler.onUserPresenceChanged(event, this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-133
@@ -1,25 +1,18 @@
|
|||||||
import 'package:stream_chat/stream_chat.dart' show Event;
|
import 'package:stream_chat/stream_chat.dart' hide Success;
|
||||||
import 'package:stream_chat_flutter/src/v4/channel_list_view/stream_channel_list_controller.dart';
|
import 'package:stream_chat_flutter/src/v4/channel_list_view/stream_channel_list_controller.dart';
|
||||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
|
||||||
|
|
||||||
/// Handles [EventType.channelDeleted] event.
|
/// Contains handlers that are called from [StreamChannelListController] for
|
||||||
|
/// certain [Event]s.
|
||||||
|
///
|
||||||
|
/// This class can be mixed in or extended to create custom overrides.
|
||||||
|
class StreamChannelListEventHandler {
|
||||||
|
/// Function which gets called for the event
|
||||||
|
/// [EventType.channelDeleted].
|
||||||
///
|
///
|
||||||
/// This event is fired when a channel is deleted.
|
/// This event is fired when a channel is deleted.
|
||||||
///
|
///
|
||||||
/// By default, this removes the channel from the list of channels.
|
/// By default, this removes the channel from the list of channels.
|
||||||
///
|
void onChannelDeleted(Event event, StreamChannelListController controller) {
|
||||||
/// ```dart
|
|
||||||
/// StreamChannelListController(
|
|
||||||
/// client: client,
|
|
||||||
/// onChannelDeleted: (event, controller) {
|
|
||||||
/// // Do something
|
|
||||||
/// },
|
|
||||||
/// );
|
|
||||||
/// ```
|
|
||||||
void onChannelDeleted(
|
|
||||||
Event event,
|
|
||||||
StreamChannelListController controller,
|
|
||||||
) {
|
|
||||||
final channels = [...controller.currentItems];
|
final channels = [...controller.currentItems];
|
||||||
|
|
||||||
final updatedChannels = channels
|
final updatedChannels = channels
|
||||||
@@ -30,66 +23,33 @@ void onChannelDeleted(
|
|||||||
controller.channels = updatedChannels;
|
controller.channels = updatedChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [EventType.channelHidden] event.
|
/// Function which gets called for the event
|
||||||
|
/// [EventType.channelHidden].
|
||||||
///
|
///
|
||||||
/// This event is fired when a channel is hidden.
|
/// This event is fired when a channel is hidden.
|
||||||
///
|
///
|
||||||
/// By default, this removes the channel from the list of channels.
|
/// By default, this removes the channel from the list of channels.
|
||||||
///
|
void onChannelHidden(Event event, StreamChannelListController controller) {
|
||||||
/// ```dart
|
|
||||||
/// StreamChannelListController(
|
|
||||||
/// client: client,
|
|
||||||
/// onChannelHidden: (event, controller) {
|
|
||||||
/// // Do something
|
|
||||||
/// },
|
|
||||||
/// );
|
|
||||||
/// ```
|
|
||||||
void onChannelHidden(
|
|
||||||
Event event,
|
|
||||||
StreamChannelListController controller,
|
|
||||||
) {
|
|
||||||
onChannelDeleted(event, controller);
|
onChannelDeleted(event, controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [EventType.channelTruncated] event.
|
/// Function which gets called for the event
|
||||||
|
/// [EventType.channelTruncated].
|
||||||
///
|
///
|
||||||
/// This event is fired when a channel is truncated.
|
/// This event is fired when a channel is truncated.
|
||||||
///
|
///
|
||||||
/// By default, this refreshes the whole channel list.
|
/// By default, this refreshes the whole channel list.
|
||||||
///
|
void onChannelTruncated(Event event, StreamChannelListController controller) {
|
||||||
/// ```dart
|
|
||||||
/// StreamChannelListController(
|
|
||||||
/// client: client,
|
|
||||||
/// onChannelTruncated: (event, controller) {
|
|
||||||
/// // Do something
|
|
||||||
/// },
|
|
||||||
/// );
|
|
||||||
/// ```
|
|
||||||
void onChannelTruncated(
|
|
||||||
Event event,
|
|
||||||
StreamChannelListController controller,
|
|
||||||
) {
|
|
||||||
controller.refresh();
|
controller.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [EventType.channelUpdated] event.
|
/// Function which gets called for the event
|
||||||
|
/// [EventType.channelUpdated].
|
||||||
///
|
///
|
||||||
/// This event is fired when a channel is updated.
|
/// This event is fired when a channel is updated.
|
||||||
///
|
///
|
||||||
/// By default, this updates the channel received in the event.
|
/// By default, this updates the channel received in the event.
|
||||||
///
|
void onChannelUpdated(Event event, StreamChannelListController controller) {
|
||||||
/// ```dart
|
|
||||||
/// StreamChannelListController(
|
|
||||||
/// client: client,
|
|
||||||
/// onChannelUpdated: (event, controller) {
|
|
||||||
/// // Do something
|
|
||||||
/// },
|
|
||||||
/// );
|
|
||||||
/// ```
|
|
||||||
void onChannelUpdated(
|
|
||||||
Event event,
|
|
||||||
StreamChannelListController controller,
|
|
||||||
) {
|
|
||||||
final eventChannel = event.channel;
|
final eventChannel = event.channel;
|
||||||
if (eventChannel == null) return;
|
if (eventChannel == null) return;
|
||||||
|
|
||||||
@@ -106,20 +66,12 @@ void onChannelUpdated(
|
|||||||
controller.channels = channels;
|
controller.channels = channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [EventType.channelVisible] event.
|
/// Function which gets called for the event
|
||||||
|
/// [EventType.channelVisible].
|
||||||
///
|
///
|
||||||
/// This event is fired when a channel is made visible.
|
/// This event is fired when a channel is made visible.
|
||||||
///
|
///
|
||||||
/// By default, this adds the channel to the list of channels.
|
/// By default, this adds the channel to the list of channels.
|
||||||
///
|
|
||||||
/// ```dart
|
|
||||||
/// StreamChannelListController(
|
|
||||||
/// client: client,
|
|
||||||
/// onChannelVisible: (event, controller) {
|
|
||||||
/// // Do something
|
|
||||||
/// },
|
|
||||||
/// );
|
|
||||||
/// ```
|
|
||||||
void onChannelVisible(
|
void onChannelVisible(
|
||||||
Event event,
|
Event event,
|
||||||
StreamChannelListController controller,
|
StreamChannelListController controller,
|
||||||
@@ -144,20 +96,12 @@ void onChannelVisible(
|
|||||||
controller.channels = updatedChannels;
|
controller.channels = updatedChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [EventType.connectionRecovered] event.
|
/// Function which gets called for the event
|
||||||
|
/// [EventType.connectionRecovered].
|
||||||
///
|
///
|
||||||
/// This event is fired when the client web-socket connection recovers.
|
/// This event is fired when the client web-socket connection recovers.
|
||||||
///
|
///
|
||||||
/// By default, this refreshes the whole channel list.
|
/// By default, this refreshes the whole channel list.
|
||||||
///
|
|
||||||
/// ```dart
|
|
||||||
/// StreamChannelListController(
|
|
||||||
/// client: client,
|
|
||||||
/// onConnectionRecovered: (event, controller) {
|
|
||||||
/// // Do something
|
|
||||||
/// },
|
|
||||||
/// );
|
|
||||||
/// ```
|
|
||||||
void onConnectionRecovered(
|
void onConnectionRecovered(
|
||||||
Event event,
|
Event event,
|
||||||
StreamChannelListController controller,
|
StreamChannelListController controller,
|
||||||
@@ -165,25 +109,13 @@ void onConnectionRecovered(
|
|||||||
controller.refresh();
|
controller.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [EventType.messageNew] event.
|
/// Function which gets called for the event [EventType.messageNew].
|
||||||
///
|
///
|
||||||
/// This event is fired when a new message is created in one of the channels
|
/// This event is fired when a new message is created in one of the channels
|
||||||
/// we are currently watching.
|
/// we are currently watching.
|
||||||
///
|
///
|
||||||
/// By default, this moves the channel to the top of the list.
|
/// By default, this moves the channel to the top of the list.
|
||||||
///
|
void onMessageNew(Event event, StreamChannelListController controller) {
|
||||||
/// ```dart
|
|
||||||
/// StreamChannelListController(
|
|
||||||
/// client: client,
|
|
||||||
/// onMessageNew: (event, controller) {
|
|
||||||
/// // Do something
|
|
||||||
/// },
|
|
||||||
/// );
|
|
||||||
/// ```
|
|
||||||
void onMessageNew(
|
|
||||||
Event event,
|
|
||||||
StreamChannelListController controller,
|
|
||||||
) {
|
|
||||||
final channelCid = event.cid;
|
final channelCid = event.cid;
|
||||||
if (channelCid == null) return;
|
if (channelCid == null) return;
|
||||||
|
|
||||||
@@ -198,20 +130,12 @@ void onMessageNew(
|
|||||||
controller.channels = [...channels];
|
controller.channels = [...channels];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [EventType.notificationAddedToChannel] event.
|
/// Function which gets called for the event
|
||||||
|
/// [EventType.notificationAddedToChannel].
|
||||||
///
|
///
|
||||||
/// This event is fired when a channel is added which we are not watching.
|
/// This event is fired when a channel is added which we are not watching.
|
||||||
///
|
///
|
||||||
/// By default, this adds the channel and moves it to the top of list.
|
/// By default, this adds the channel and moves it to the top of list.
|
||||||
///
|
|
||||||
/// ```dart
|
|
||||||
/// StreamChannelListController(
|
|
||||||
/// client: client,
|
|
||||||
/// onNotificationAddedToChannel: (event, controller) {
|
|
||||||
/// // Do something
|
|
||||||
/// },
|
|
||||||
/// );
|
|
||||||
/// ```
|
|
||||||
void onNotificationAddedToChannel(
|
void onNotificationAddedToChannel(
|
||||||
Event event,
|
Event event,
|
||||||
StreamChannelListController controller,
|
StreamChannelListController controller,
|
||||||
@@ -219,21 +143,13 @@ void onNotificationAddedToChannel(
|
|||||||
onChannelVisible(event, controller);
|
onChannelVisible(event, controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [EventType.notificationMessageNew] event.
|
/// Function which gets called for the event
|
||||||
|
/// [EventType.notificationMessageNew].
|
||||||
///
|
///
|
||||||
/// This event is fired when a new message is created in a channel which we are
|
/// This event is fired when a new message is created in a channel which we are
|
||||||
/// not currently watching.
|
/// not currently watching.
|
||||||
///
|
///
|
||||||
/// By default, this adds the channel and moves it to the top of list.
|
/// By default, this adds the channel and moves it to the top of list.
|
||||||
///
|
|
||||||
/// ```dart
|
|
||||||
/// StreamChannelListController(
|
|
||||||
/// client: client,
|
|
||||||
/// onNotificationMessageNew: (event, controller) {
|
|
||||||
/// // Do something
|
|
||||||
/// },
|
|
||||||
/// );
|
|
||||||
/// ```
|
|
||||||
void onNotificationMessageNew(
|
void onNotificationMessageNew(
|
||||||
Event event,
|
Event event,
|
||||||
StreamChannelListController controller,
|
StreamChannelListController controller,
|
||||||
@@ -241,27 +157,20 @@ void onNotificationMessageNew(
|
|||||||
onChannelVisible(event, controller);
|
onChannelVisible(event, controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [EventType.notificationRemovedFromChannel] event.
|
/// Function which gets called for the event
|
||||||
|
/// [EventType.notificationRemovedFromChannel].
|
||||||
///
|
///
|
||||||
/// This event is fired when a user is removed from a channel which we are
|
/// This event is fired when a user is removed from a channel which we are
|
||||||
/// not currently watching.
|
/// not currently watching.
|
||||||
///
|
///
|
||||||
/// By default, this removes the event channel from the list.
|
/// By default, this removes the event channel from the list.
|
||||||
///
|
|
||||||
/// ```dart
|
|
||||||
/// StreamChannelListController(
|
|
||||||
/// client: client,
|
|
||||||
/// onNotificationRemovedFromChannel: (event, controller) {
|
|
||||||
/// // Do something
|
|
||||||
/// },
|
|
||||||
/// );
|
|
||||||
/// ```
|
|
||||||
void onNotificationRemovedFromChannel(
|
void onNotificationRemovedFromChannel(
|
||||||
Event event,
|
Event event,
|
||||||
StreamChannelListController controller,
|
StreamChannelListController controller,
|
||||||
) {
|
) {
|
||||||
final channels = [...controller.currentItems];
|
final channels = [...controller.currentItems];
|
||||||
final updatedChannels = channels.where((it) => it.cid != event.channel?.cid);
|
final updatedChannels =
|
||||||
|
channels.where((it) => it.cid != event.channel?.cid);
|
||||||
final listChanged = channels.length != updatedChannels.length;
|
final listChanged = channels.length != updatedChannels.length;
|
||||||
|
|
||||||
if (!listChanged) return;
|
if (!listChanged) return;
|
||||||
@@ -269,20 +178,12 @@ void onNotificationRemovedFromChannel(
|
|||||||
controller.channels = [...updatedChannels];
|
controller.channels = [...updatedChannels];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles 'user.presence.changed' and [EventType.userUpdated] event.
|
/// Function which gets called for the event
|
||||||
|
/// 'user.presence.changed' and [EventType.userUpdated].
|
||||||
///
|
///
|
||||||
/// This event is fired when a user's presence changes or gets updated.
|
/// This event is fired when a user's presence changes or gets updated.
|
||||||
///
|
///
|
||||||
/// By default, this updates the channel member with the event user.
|
/// By default, this updates the channel member with the event user.
|
||||||
///
|
|
||||||
/// ```dart
|
|
||||||
/// StreamChannelListController(
|
|
||||||
/// client: client,
|
|
||||||
/// onUserPresenceChanged: (event, controller) {
|
|
||||||
/// // Do something
|
|
||||||
/// },
|
|
||||||
/// );
|
|
||||||
/// ```
|
|
||||||
void onUserPresenceChanged(
|
void onUserPresenceChanged(
|
||||||
Event event,
|
Event event,
|
||||||
StreamChannelListController controller,
|
StreamChannelListController controller,
|
||||||
@@ -309,3 +210,4 @@ void onUserPresenceChanged(
|
|||||||
|
|
||||||
controller.channels = [...updatedChannels];
|
controller.channels = [...updatedChannels];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export 'src/user_item.dart';
|
|||||||
export 'src/user_list_view.dart';
|
export 'src/user_list_view.dart';
|
||||||
export 'src/user_mention_tile.dart';
|
export 'src/user_mention_tile.dart';
|
||||||
export 'src/utils.dart';
|
export 'src/utils.dart';
|
||||||
export 'src/v4/channel_list_view/channel_event_handlers.dart';
|
|
||||||
export 'src/v4/channel_list_view/stream_channel_list_controller.dart';
|
export 'src/v4/channel_list_view/stream_channel_list_controller.dart';
|
||||||
|
export 'src/v4/channel_list_view/stream_channel_list_event_handler.dart';
|
||||||
export 'src/v4/channel_list_view/stream_channel_list_view.dart';
|
export 'src/v4/channel_list_view/stream_channel_list_view.dart';
|
||||||
export 'src/visible_footnote.dart';
|
export 'src/visible_footnote.dart';
|
||||||
|
|||||||
Reference in New Issue
Block a user