Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/config/providers/relay_status_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';

import 'package:whitenoise/config/providers/active_pubkey_provider.dart';
import 'package:whitenoise/config/providers/auth_provider.dart';
import 'package:whitenoise/models/relay_status.dart';
Expand Down Expand Up @@ -87,7 +86,7 @@ class RelayStatusNotifier extends Notifier<RelayStatusState> {
'RelayStatusNotifier: Fetching relay statuses for pubkey: $activePubkey',
);
// Fetch relay statuses using the Rust function
final relayStatuses = await fetchRelayStatus(pubkey: activePubkey);
final relayStatuses = await getAccountRelayStatuses(pubkey: activePubkey);
_logger.info('RelayStatusNotifier: Fetched ${relayStatuses.length} relay statuses');

// Convert list of tuples to map
Expand Down
27 changes: 25 additions & 2 deletions lib/src/rust/api/relays.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,31 @@ Future<RelayType> relayTypeInbox() => RustLib.instance.api.crateApiRelaysRelayTy

Future<RelayType> relayTypeKeyPackage() => RustLib.instance.api.crateApiRelaysRelayTypeKeyPackage();

Future<List<(String, String)>> fetchRelayStatus({required String pubkey}) =>
RustLib.instance.api.crateApiRelaysFetchRelayStatus(pubkey: pubkey);
Future<List<(String, String)>> getAccountRelayStatuses({
required String pubkey,
}) => RustLib.instance.api.crateApiRelaysGetAccountRelayStatuses(pubkey: pubkey);

/// Ensures all subscriptions (global and all accounts) are operational.
///
/// This method is designed for periodic background tasks that need to ensure
/// the entire subscription system is functioning. It checks and refreshes
/// global subscriptions first, then iterates through all accounts.
///
/// Uses a best-effort strategy: if one subscription check fails, logs the error
/// and continues with the remaining checks. This maximizes the number of working
/// subscriptions even when some fail due to transient network issues.
///
/// # Error Handling
///
/// - **Subscription errors**: Logged and ignored, processing continues
/// - **Database errors**: Propagated immediately (catastrophic failure)
///
/// # Returns
///
/// - `Ok(())`: Completed all checks (some may have failed, check logs)
/// - `Err(_)`: Only on catastrophic failures (e.g., database connection lost)
Future<void> ensureAllSubscriptions() =>
RustLib.instance.api.crateApiRelaysEnsureAllSubscriptions();

class Relay {
final String url;
Expand Down
Loading