From f896c4543f45ee6981aeee6fbbcbc899a1f67f73 Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Wed, 1 Oct 2025 18:44:54 +0530 Subject: [PATCH] refactor: update socket connection state and add conversation delta stream provider - Changed the initial state of the socket connection from `disconnected` to `connecting` to better reflect the connection process. - Updated the service change handling to emit the `connecting` state when the service is null. - Introduced a new `stream()` method in the `ConversationDeltaStream` class for direct access to the underlying stream, improving usability. - Added a `conversationDeltaEventsProvider` to provide a stream of conversation delta events based on requests, enhancing the application's real-time capabilities. --- lib/core/providers/app_providers.dart | 20 ++++++++++++++++++-- lib/core/services/connectivity_service.dart | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/core/providers/app_providers.dart b/lib/core/providers/app_providers.dart index d068a8c..955994c 100644 --- a/lib/core/providers/app_providers.dart +++ b/lib/core/providers/app_providers.dart @@ -267,7 +267,7 @@ class SocketConnectionStream extends _$SocketConnectionStream { ProviderSubscription>? _serviceSubscription; VoidCallback? _cancelConnectListener; VoidCallback? _cancelDisconnectListener; - SocketConnectionState _latestState = SocketConnectionState.disconnected; + SocketConnectionState _latestState = SocketConnectionState.connecting; @override Stream build() { @@ -320,7 +320,7 @@ class SocketConnectionStream extends _$SocketConnectionStream { void _handleServiceChange(SocketService? service) { if (service == null) { _unbindSocket(); - _emit(SocketConnectionState.disconnected); + _emit(SocketConnectionState.connecting); return; } @@ -462,8 +462,24 @@ class ConversationDeltaStream extends _$ConversationDeltaStream { _socketSubscription?.dispose(); _socketSubscription = null; } + + /// Provides direct access to the underlying stream. + /// Exposed as a method to avoid property-based lint violations. + Stream stream() => + _controller?.stream ?? const Stream.empty(); } +final conversationDeltaEventsProvider = + StreamProvider.family(( + ref, + request, + ) { + final notifier = ref.watch( + conversationDeltaStreamProvider(request).notifier, + ); + return notifier.stream(); + }); + // Attachment upload queue provider final attachmentUploadQueueProvider = Provider((ref) { final api = ref.watch(apiServiceProvider); diff --git a/lib/core/services/connectivity_service.dart b/lib/core/services/connectivity_service.dart index d9ce86b..fbaf834 100644 --- a/lib/core/services/connectivity_service.dart +++ b/lib/core/services/connectivity_service.dart @@ -246,7 +246,7 @@ final isOnlineProvider = Provider((ref) { if (reviewerMode) return true; final status = ref.watch(connectivityStatusProvider); return status.when( - data: (status) => status == ConnectivityStatus.online, + data: (status) => status != ConnectivityStatus.offline, loading: () => true, // Assume online while checking error: (_, _) => true, // Assume online on error to avoid false offline states