-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add delayed relay error handling and integrate with chat list s… #668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
codeswot
merged 2 commits into
master
from
667-network-relay-error-message-too-aggressive
Sep 22, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import 'dart:async'; | ||
|
|
||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:logging/logging.dart'; | ||
|
|
||
| import 'package:whitenoise/config/providers/relay_status_provider.dart'; | ||
|
|
||
| class DelayedRelayErrorState { | ||
| final bool shouldShowBanner; | ||
| final bool isDelayActive; | ||
|
|
||
| const DelayedRelayErrorState({ | ||
| this.shouldShowBanner = false, | ||
| this.isDelayActive = false, | ||
| }); | ||
|
|
||
| DelayedRelayErrorState copyWith({ | ||
| bool? shouldShowBanner, | ||
| bool? isDelayActive, | ||
| }) { | ||
| return DelayedRelayErrorState( | ||
| shouldShowBanner: shouldShowBanner ?? this.shouldShowBanner, | ||
| isDelayActive: isDelayActive ?? this.isDelayActive, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class DelayedRelayErrorNotifier extends Notifier<DelayedRelayErrorState> { | ||
| static const Duration _delayDuration = Duration(seconds: 30); | ||
| final _logger = Logger('DelayedRelayErrorNotifier'); | ||
|
|
||
| Timer? _delayTimer; | ||
| bool _lastConnectionStatus = true; | ||
|
|
||
| @override | ||
| DelayedRelayErrorState build() { | ||
| ref.listen<AsyncValue<bool>>(allRelayTypesConnectionProvider, (previous, next) { | ||
| next.when( | ||
| data: (isConnected) => _handleConnectionStatusChange(isConnected), | ||
| loading: () { | ||
| _logger.info('Relay connection status is loading'); | ||
| }, | ||
| error: (error, stackTrace) { | ||
| _logger.warning('Error in relay connection status: $error'); | ||
| _handleConnectionStatusChange(false); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| return const DelayedRelayErrorState(); | ||
| } | ||
|
|
||
| void _handleConnectionStatusChange(bool isConnected) { | ||
| _logger.info('Relay connection status changed: $isConnected (was: $_lastConnectionStatus)'); | ||
|
|
||
| if (isConnected && !_lastConnectionStatus) { | ||
| _logger.info('Connection restored - hiding banner immediately'); | ||
| _cancelDelayTimer(); | ||
| state = state.copyWith(shouldShowBanner: false, isDelayActive: false); | ||
| } else if (!isConnected && _lastConnectionStatus) { | ||
| _logger.info('Connection lost - starting 30-second delay timer'); | ||
| _startDelayTimer(); | ||
| } | ||
|
|
||
| _lastConnectionStatus = isConnected; | ||
| } | ||
|
|
||
| void _startDelayTimer() { | ||
| _cancelDelayTimer(); | ||
| state = state.copyWith(isDelayActive: true, shouldShowBanner: false); | ||
| _delayTimer = Timer(_delayDuration, () { | ||
| _logger.info('30-second delay completed - checking if banner should still be shown'); | ||
| final currentConnectionAsync = ref.read(allRelayTypesConnectionProvider); | ||
| currentConnectionAsync.when( | ||
| data: (isConnected) { | ||
| if (!isConnected) { | ||
| _logger.info('Still disconnected after delay - showing banner'); | ||
| state = state.copyWith(shouldShowBanner: true, isDelayActive: false); | ||
| } else { | ||
| _logger.info('Connection restored during delay - not showing banner'); | ||
| state = state.copyWith(shouldShowBanner: false, isDelayActive: false); | ||
| } | ||
| }, | ||
| loading: () { | ||
| state = state.copyWith(shouldShowBanner: false, isDelayActive: false); | ||
| }, | ||
| error: (error, stackTrace) { | ||
| _logger.warning('Error checking connection status after delay: $error'); | ||
| state = state.copyWith(shouldShowBanner: true, isDelayActive: false); | ||
| }, | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| void _cancelDelayTimer() { | ||
| if (_delayTimer != null) { | ||
| _logger.info('Cancelling delay timer'); | ||
| _delayTimer!.cancel(); | ||
| _delayTimer = null; | ||
| } | ||
| } | ||
|
|
||
| void dispose() { | ||
| _cancelDelayTimer(); | ||
| } | ||
| } | ||
|
|
||
| final delayedRelayErrorProvider = | ||
| NotifierProvider<DelayedRelayErrorNotifier, DelayedRelayErrorState>( | ||
| DelayedRelayErrorNotifier.new, | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I'm understanding this:
_handleConnectionStatusChangemethod is called.How we we hear about these changes in connection status?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we enter a not connected state we delay for 30 seconds, and if after that 30 seconds connection is not back we show the banner