ConversationsBloc constructor
ConversationsBloc({
- GetLoggedInUserUseCase? getLoggedInUserUseCase,
- GetConversationUseCase? getConversationUseCase,
- MarkAsDeliveredUseCase? markAsDeliveredUseCase,
- DeleteConversationUseCase? deleteConversationUseCase,
- GetConversationsUseCase? getConversationsUseCase,
- LoadMoreConversationsUseCase? loadMoreConversationsUseCase,
- bool disableSoundForMessages = false,
- String? customSoundForMessages,
- bool usersStatusVisibility = true,
- bool receiptsVisibility = true,
- bool includeBlockedUsers = false,
- int visibleItemThreshold = 30,
- bool disableSDKListeners = false,
- ConversationsRequestBuilder? conversationsRequestBuilder,
- ConversationsBuilderProtocol? conversationsProtocol,
Creates a ConversationsBloc.
All use cases are optional - if not provided, they will be automatically initialized from the default service locator. This makes it easy to extend the bloc without worrying about dependency injection.
Implementation
ConversationsBloc({
GetLoggedInUserUseCase? getLoggedInUserUseCase,
GetConversationUseCase? getConversationUseCase,
MarkAsDeliveredUseCase? markAsDeliveredUseCase,
DeleteConversationUseCase? deleteConversationUseCase,
GetConversationsUseCase? getConversationsUseCase,
LoadMoreConversationsUseCase? loadMoreConversationsUseCase,
this.disableSoundForMessages = false,
this.customSoundForMessages,
this.usersStatusVisibility = true,
this.receiptsVisibility = true,
this.includeBlockedUsers = false,
this.visibleItemThreshold = 30,
this.disableSDKListeners = false,
this.conversationsRequestBuilder,
this.conversationsProtocol,
}) : getLoggedInUserUseCase = getLoggedInUserUseCase ?? _getServiceLocator().getLoggedInUserUseCase,
getConversationUseCase = getConversationUseCase ?? _getServiceLocator().getConversationUseCase,
markAsDeliveredUseCase = markAsDeliveredUseCase ?? _getServiceLocator().markAsDeliveredUseCase,
deleteConversationUseCase = deleteConversationUseCase ?? _getServiceLocator().deleteConversationUseCase,
getConversationsUseCase = getConversationsUseCase ?? _getServiceLocator().getConversationsUseCase,
loadMoreConversationsUseCase = loadMoreConversationsUseCase ?? _getServiceLocator().loadMoreConversationsUseCase,
super(const ConversationsInitial()) {
// Resolve effective request builder once. Protocol wins over direct builder.
_effectiveRequestBuilder =
conversationsProtocol?.requestBuilder ?? conversationsRequestBuilder;
// Register event handlers
on<LoadConversations>(_onLoadConversations);
on<LoadMoreConversations>(_onLoadMoreConversations);
on<RefreshConversations>(_onRefreshConversations);
on<DeleteConversation>(_onDeleteConversation);
on<RemoveConversation>(_onRemoveConversation);
on<SetActiveConversation>(_onSetActiveConversation);
on<ToggleConversationSelection>(_onToggleConversationSelection);
on<ClearConversationSelection>(_onClearConversationSelection);
on<UpdateConversation>(_onUpdateConversation);
on<ResetUnreadCount>(_onResetUnreadCount);
// Internal events
on<_MessageReceivedUpdate>(_onMessageReceivedUpdate);
on<_UserStatusUpdate>(_onUserStatusUpdate);
on<_ReceiptUpdate>(_onReceiptUpdate);
on<_MessageEditedUpdate>(_onMessageEditedUpdate);
on<_GroupUpdate>(_onGroupUpdate);
on<_RemoveGroupConversation>(_onRemoveGroupConversation);
on<_ConnectionStateUpdate>(_onConnectionStateUpdate);
on<_ConversationUnreadUpdate>(_onConversationUnreadUpdate);
// List base hook events
on<_ListItemAdded>(_onListItemAdded);
on<_ListItemRemoved>(_onListItemRemoved);
on<_ListItemUpdated>(_onListItemUpdated);
on<_ListCleared>(_onListCleared);
on<_ListReplaced>(_onListReplaced);
// Initialize logged in user and register SDK listeners
_initializeAndRegisterListeners();
}