Skip to content

Commit 8b209bb

Browse files
authored
feat: expose ensureAllSubscriptions method to Flutter API (#715)
1 parent 8c5ddb2 commit 8b209bb

File tree

9 files changed

+277
-148
lines changed

9 files changed

+277
-148
lines changed

lib/config/providers/relay_status_provider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class RelayStatusNotifier extends Notifier<RelayStatusState> {
8787
'RelayStatusNotifier: Fetching relay statuses for pubkey: $activePubkey',
8888
);
8989
// Fetch relay statuses using the Rust function
90-
final relayStatuses = await fetchRelayStatus(pubkey: activePubkey);
90+
final relayStatuses = await getAccountRelayStatuses(pubkey: activePubkey);
9191
_logger.info('RelayStatusNotifier: Fetched ${relayStatuses.length} relay statuses');
9292

9393
// Convert list of tuples to map

lib/src/rust/api/relays.dart

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,31 @@ Future<RelayType> relayTypeInbox() => RustLib.instance.api.crateApiRelaysRelayTy
1717

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

20-
Future<List<(String, String)>> fetchRelayStatus({required String pubkey}) =>
21-
RustLib.instance.api.crateApiRelaysFetchRelayStatus(pubkey: pubkey);
20+
Future<List<(String, String)>> getAccountRelayStatuses({
21+
required String pubkey,
22+
}) => RustLib.instance.api.crateApiRelaysGetAccountRelayStatuses(pubkey: pubkey);
23+
24+
/// Ensures all subscriptions (global and all accounts) are operational.
25+
///
26+
/// This method is designed for periodic background tasks that need to ensure
27+
/// the entire subscription system is functioning. It checks and refreshes
28+
/// global subscriptions first, then iterates through all accounts.
29+
///
30+
/// Uses a best-effort strategy: if one subscription check fails, logs the error
31+
/// and continues with the remaining checks. This maximizes the number of working
32+
/// subscriptions even when some fail due to transient network issues.
33+
///
34+
/// # Error Handling
35+
///
36+
/// - **Subscription errors**: Logged and ignored, processing continues
37+
/// - **Database errors**: Propagated immediately (catastrophic failure)
38+
///
39+
/// # Returns
40+
///
41+
/// - `Ok(())`: Completed all checks (some may have failed, check logs)
42+
/// - `Err(_)`: Only on catastrophic failures (e.g., database connection lost)
43+
Future<void> ensureAllSubscriptions() =>
44+
RustLib.instance.api.crateApiRelaysEnsureAllSubscriptions();
2245

2346
class Relay {
2447
final String url;

0 commit comments

Comments
 (0)