refactor: rename ChannelEvents to ChannelEventHandlers

This commit is contained in:
Gordon Hayes
2021-12-06 14:04:14 +05:30
committed by xsahil03x
parent 042315353c
commit 5b05363497
3 changed files with 28 additions and 28 deletions
@@ -3,11 +3,11 @@ import 'package:stream_chat_flutter/src/v4/channel_list_view/stream_channel_list
import 'package:stream_chat_flutter/src/v4/channel_list_view/stream_channel_list_event_handler.dart' import 'package:stream_chat_flutter/src/v4/channel_list_view/stream_channel_list_event_handler.dart'
as event_handler; as event_handler;
/// Contains methods that are called for certain [Event]s. These methods are /// Contains handlers that are called from [StreamChannelListController] for
/// called from the [StreamChannelListController]. /// certain [Event]s.
/// ///
/// This class can be mixed in or extended to create custom overrides. /// This class can be mixed in or extended to create custom overrides.
class ChannelEvents { class ChannelEventHandlers {
/// Function which gets called for the event /// Function which gets called for the event
/// [EventType.channelDeleted]. /// [EventType.channelDeleted].
/// ///
@@ -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_events.dart'; import 'package:stream_chat_flutter/src/v4/channel_list_view/channel_event_handlers.dart';
/// The default channel page limit to load. /// The default channel page limit to load.
const defaultChannelPagedLimit = 10; const defaultChannelPagedLimit = 10;
@@ -11,6 +11,7 @@ const defaultChannelPagedLimit = 10;
/// ///
/// This class lets you perform tasks such as: /// This class lets you perform tasks such as:
/// * Load initial data. /// * Load initial data.
/// * Use channel events handlers.
/// * 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.
@@ -21,9 +22,9 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
/// ///
/// * `client` is the Stream chat client to use for the channels list. /// * `client` is the Stream chat client to use for the channels list.
/// ///
/// * `channelEvents` is the channel events to use for the channels list. /// * `channelEventHandlers` is the channel events to use for the channels
/// This class can be mixed in or extended to create custom overrides. See /// list. This class can be mixed in or extended to create custom overrides.
/// [ChannelEvents] for advice. /// See [ChannelEventHandlers] for advice.
/// ///
/// * `filter` is the query filters to use. /// * `filter` is the query filters to use.
/// ///
@@ -39,33 +40,32 @@ 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,
ChannelEvents? channelEvents, ChannelEventHandlers? channelEventHandlers,
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,
}) : channelEvents = channelEvents ?? ChannelEvents(), }) : _channelEventHandlers = channelEventHandlers ?? ChannelEventHandlers(),
super(const PagedValue.loading()) { super(const PagedValue.loading());
this.channelEvents.test();
}
/// 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,
required this.channelEvents, ChannelEventHandlers? channelEventHandlers,
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,
}) : super(value); }) : _channelEventHandlers = channelEventHandlers ?? ChannelEventHandlers(),
super(value);
/// The channel events to use for the channels list. /// The channel events to use for the channels list.
final ChannelEvents channelEvents; 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;
@@ -183,32 +183,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) {
channelEvents.onChannelDeleted(event, this); _channelEventHandlers.onChannelDeleted(event, this);
} else if (eventType == EventType.channelHidden) { } else if (eventType == EventType.channelHidden) {
channelEvents.onChannelDeleted(event, this); _channelEventHandlers.onChannelHidden(event, this);
} else if (eventType == EventType.channelTruncated) { } else if (eventType == EventType.channelTruncated) {
channelEvents.onChannelTruncated(event, this); _channelEventHandlers.onChannelTruncated(event, this);
} else if (eventType == EventType.channelUpdated) { } else if (eventType == EventType.channelUpdated) {
channelEvents.onChannelUpdated(event, this); _channelEventHandlers.onChannelUpdated(event, this);
} else if (eventType == EventType.channelVisible) { } else if (eventType == EventType.channelVisible) {
channelEvents.onChannelVisible(event, this); _channelEventHandlers.onChannelVisible(event, this);
} else if (eventType == EventType.connectionRecovered) { } else if (eventType == EventType.connectionRecovered) {
channelEvents.onConnectionRecovered(event, this); _channelEventHandlers.onConnectionRecovered(event, this);
} else if (eventType == EventType.connectionChanged) { } else if (eventType == EventType.connectionChanged) {
if (event.online != null) { if (event.online != null) {
channelEvents.onConnectionRecovered(event, this); _channelEventHandlers.onConnectionRecovered(event, this);
} }
} else if (eventType == EventType.messageNew) { } else if (eventType == EventType.messageNew) {
channelEvents.onMessageNew(event, this); _channelEventHandlers.onMessageNew(event, this);
} else if (eventType == EventType.notificationAddedToChannel) { } else if (eventType == EventType.notificationAddedToChannel) {
channelEvents.onNotificationAddedToChannel(event, this); _channelEventHandlers.onNotificationAddedToChannel(event, this);
} else if (eventType == EventType.notificationMessageNew) { } else if (eventType == EventType.notificationMessageNew) {
channelEvents.onNotificationMessageNew(event, this); _channelEventHandlers.onNotificationMessageNew(event, this);
} else if (eventType == EventType.notificationRemovedFromChannel) { } else if (eventType == EventType.notificationRemovedFromChannel) {
channelEvents.onNotificationRemovedFromChannel(event, this); _channelEventHandlers.onNotificationRemovedFromChannel(event, this);
} else if (eventType == 'user.presence.changed' || } else if (eventType == 'user.presence.changed' ||
eventType == EventType.userUpdated) { eventType == EventType.userUpdated) {
channelEvents.onUserPresenceChanged(event, this); _channelEventHandlers.onUserPresenceChanged(event, this);
} }
}); });
} }
@@ -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_events.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_view.dart'; export 'src/v4/channel_list_view/stream_channel_list_view.dart';
export 'src/visible_footnote.dart'; export 'src/visible_footnote.dart';