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.
This commit is contained in:
cogwheel0
2025-10-01 18:44:54 +05:30
parent 8a8ba76298
commit f896c4543f
2 changed files with 19 additions and 3 deletions

View File

@@ -267,7 +267,7 @@ class SocketConnectionStream extends _$SocketConnectionStream {
ProviderSubscription<AsyncValue<SocketService?>>? _serviceSubscription;
VoidCallback? _cancelConnectListener;
VoidCallback? _cancelDisconnectListener;
SocketConnectionState _latestState = SocketConnectionState.disconnected;
SocketConnectionState _latestState = SocketConnectionState.connecting;
@override
Stream<SocketConnectionState> 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<ConversationDelta> stream() =>
_controller?.stream ?? const Stream<ConversationDelta>.empty();
}
final conversationDeltaEventsProvider =
StreamProvider.family<ConversationDelta, ConversationDeltaRequest>((
ref,
request,
) {
final notifier = ref.watch(
conversationDeltaStreamProvider(request).notifier,
);
return notifier.stream();
});
// Attachment upload queue provider
final attachmentUploadQueueProvider = Provider<AttachmentUploadQueue?>((ref) {
final api = ref.watch(apiServiceProvider);

View File

@@ -246,7 +246,7 @@ final isOnlineProvider = Provider<bool>((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