-
Notifications
You must be signed in to change notification settings - Fork 13
feat: expose ensureAllSubscriptions method to Flutter API #715
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
Conversation
WalkthroughRenamed relay status API from fetchRelayStatus to getAccountRelayStatuses across Dart/FRB/Rust layers and updated call sites. Added ensureAllSubscriptions API in Dart and Rust, with corresponding FRB codegen and dispatch updates. Minor pubspec formatting tweak and a Rust dependency revision in Cargo.toml. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor UI as UI
participant Provider as RelayStatusProvider
participant DartAPI as Dart Relays API
participant FRB as FRB (Dart↔Rust)
participant RustAPI as Rust relays.rs
participant Core as Whitenoise Core
UI->>Provider: refreshStatuses(pubkey)
Provider->>DartAPI: getAccountRelayStatuses(pubkey)
DartAPI->>FRB: crateApiRelaysGetAccountRelayStatuses(pubkey)
FRB->>RustAPI: get_account_relay_statuses(pubkey)
RustAPI->>Core: query account relay statuses
Core-->>RustAPI: Vec<(relay, status)>
RustAPI-->>FRB: statuses
FRB-->>DartAPI: List<(String, String)>
DartAPI-->>Provider: statuses
Provider-->>UI: render
note over DartAPI,RustAPI: New API name used end-to-end
sequenceDiagram
autonumber
actor App as App
participant DartAPI as Dart Relays API
participant FRB as FRB (Dart↔Rust)
participant RustAPI as Rust relays.rs
participant Core as Whitenoise Core
App->>DartAPI: ensureAllSubscriptions()
DartAPI->>FRB: crateApiRelaysEnsureAllSubscriptions()
FRB->>RustAPI: ensure_all_subscriptions()
RustAPI->>Core: ensure_all_subscriptions()
Core-->>RustAPI: Ok / Error (best-effort)
RustAPI-->>FRB: Result<(), ApiError>
FRB-->>DartAPI: Future<void>
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (7)
🚧 Files skipped from review as they are similar to previous changes (2)
🧰 Additional context used📓 Path-based instructions (1)**/*.dart📄 CodeRabbit inference engine (.cursor/rules/flutter.mdc)
Files:
🧬 Code graph analysis (1)rust/src/frb_generated.rs (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
rust/src/frb_generated.rs (1)
3411-3499: Regenerate Dart bindings
The Rust dispatcher now routes func_ids 19 and 25, but lib/src/rust/frb_generated.dart is missingensureAllSubscriptionsandgetAccountRelayStatuses. Re-run the codegen to include these methods.
🧹 Nitpick comments (5)
lib/src/rust/api.dart (1)
2-2: LGTM. Note: add CHANGELOG entry for exposed ensureAllSubscriptions and relay status API rename.Keeps generated header in sync with FRB 2.10.0.
lib/config/providers/relay_status_provider.dart (1)
86-92: getAccountRelayStatuses returns a List of Dart records; optionally preflight subscriptions
- getAccountRelayStatuses returns Future<List<(String, String)>> so
for (final (url, status) in relayStatuses)remains valid.- Optional: add a best-effort call to ensureAllSubscriptions() before fetching statuses.
_logger.info( 'RelayStatusNotifier: Fetching relay statuses for pubkey: $activePubkey', ); + // Best effort: ensure subscriptions are healthy before reading statuses + try { + await ensureAllSubscriptions(); + } catch (_) { + // ignore: best-effort only + } // Fetch relay statuses using the Rust function final relayStatuses = await getAccountRelayStatuses(pubkey: activePubkey);lib/src/rust/frb_generated.dart (3)
162-165: LGTM: ensureAllSubscriptions exposed and wiredAPI and impl look correct (no args, unit decode, proper const meta). Good addition for background maintenance flows. Based on learnings
- Schedule it from background tasks (e.g., platform background workers) with sensible backoff.
- Treat it as idempotent; avoid overlapping calls; surface errors to logs/telemetry.
Also applies to: 981-1009, 1005-1008
160-166: Docs/CHANGELOGPublic API surface changed (new relays methods and rename of status API). Please update CHANGELOG and any API docs.
183-186: Record support enabled; consider ergonomic Map wrapper
- pubspec.yaml uses
sdk: ^3.7.2, which supports Dart records.- Optional: add a helper in the relays API layer to convert
List<(String, String)>→Map<String, String>for easier consumption.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
pubspec.lockis excluded by!**/*.lockrust/Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (18)
lib/config/providers/relay_status_provider.dart(1 hunks)lib/src/rust/api.dart(1 hunks)lib/src/rust/api/accounts.dart(1 hunks)lib/src/rust/api/error.dart(1 hunks)lib/src/rust/api/groups.dart(1 hunks)lib/src/rust/api/messages.dart(1 hunks)lib/src/rust/api/metadata.dart(1 hunks)lib/src/rust/api/relays.dart(2 hunks)lib/src/rust/api/users.dart(1 hunks)lib/src/rust/api/utils.dart(1 hunks)lib/src/rust/api/welcomes.dart(1 hunks)lib/src/rust/frb_generated.dart(46 hunks)lib/src/rust/frb_generated.io.dart(1 hunks)lib/src/rust/lib.dart(1 hunks)pubspec.yaml(1 hunks)rust/Cargo.toml(2 hunks)rust/src/api/relays.rs(1 hunks)rust/src/frb_generated.rs(13 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.dart
📄 CodeRabbit inference engine (.cursor/rules/flutter.mdc)
**/*.dart: Always declare the type of each variable and function (parameters and return value). Avoid using 'any'. Create necessary types.
Don't leave blank lines within a function.
One export per file.
Use PascalCase for classes.
Use camelCase for variables, functions, and methods.
Use underscores_case for file and directory names.
Use UPPERCASE for environment variables. Avoid magic numbers and define constants.
Start each function with a verb.
Use verbs for boolean variables. Example: isLoading, hasError, canDelete, etc.
Use complete words instead of abbreviations and correct spelling, except for standard and well-known abbreviations (API, URL, i, j, err, ctx, req, res, next).
Write short functions with a single purpose. Less than 20 instructions.
Name functions with a verb and something else. If it returns a boolean, use isX or hasX, canX, etc. If it doesn't return anything, use executeX or saveX, etc.
Avoid nesting blocks by early checks and returns, or extraction to utility functions.
Use higher-order functions (map, filter, reduce, etc.) to avoid function nesting. Use arrow functions for simple functions (less than 3 instructions). Use named functions for non-simple functions.
Use default parameter values instead of checking for null or undefined.
Reduce function parameters using RO-RO: use an object to pass multiple parameters and to return results. Declare necessary types for input arguments and output.
Use a single level of abstraction in functions.
Don't abuse primitive types and encapsulate data in composite types.
Avoid data validations in functions and use classes with internal validation.
Prefer immutability for data. Use readonly for data that doesn't change. Use 'as const' for literals that don't change.
Declare interfaces to define contracts.
Write small classes with a single purpose. Less than 200 instructions, less than 10 public methods, less than 10 properties.
Use exceptions to handle errors you don't expect. If you catch an exception, it sh...
Files:
lib/src/rust/frb_generated.io.dartlib/src/rust/api/utils.dartlib/src/rust/api/users.dartlib/src/rust/api/accounts.dartlib/src/rust/lib.dartlib/config/providers/relay_status_provider.dartlib/src/rust/api/relays.dartlib/src/rust/api/metadata.dartlib/src/rust/api.dartlib/src/rust/frb_generated.dartlib/src/rust/api/welcomes.dartlib/src/rust/api/error.dartlib/src/rust/api/messages.dartlib/src/rust/api/groups.dart
🧠 Learnings (2)
📚 Learning: 2025-08-08T13:39:00.500Z
Learnt from: CR
PR: parres-hq/whitenoise_flutter#0
File: .cursor/rules/flutter.mdc:0-0
Timestamp: 2025-08-08T13:39:00.500Z
Learning: Applies to **/*.dart : Use flutter_rust_bridge to access core functionality of the app.
Applied to files:
lib/src/rust/frb_generated.io.dartlib/src/rust/api/utils.dartlib/src/rust/api/users.dartlib/src/rust/api/accounts.dartrust/Cargo.tomllib/src/rust/lib.dartlib/src/rust/api/relays.dartlib/src/rust/api/metadata.dartlib/src/rust/api.dartrust/src/frb_generated.rslib/src/rust/frb_generated.dartlib/src/rust/api/welcomes.dartpubspec.yamllib/src/rust/api/error.dartlib/src/rust/api/messages.dartlib/src/rust/api/groups.dart
📚 Learning: 2025-08-08T13:39:00.500Z
Learnt from: CR
PR: parres-hq/whitenoise_flutter#0
File: .cursor/rules/flutter.mdc:0-0
Timestamp: 2025-08-08T13:39:00.500Z
Learning: Applies to **/*.dart : Use the whitenoise rust crate (via flutter_rust_bridge) as the source of all data and only way to trigger changes in our data model.
Applied to files:
rust/Cargo.tomllib/src/rust/api.dart
🧬 Code graph analysis (2)
rust/src/api/relays.rs (1)
rust/src/api/accounts.rs (2)
from(17-24)from(39-53)
rust/src/frb_generated.rs (3)
rust/src/api/relays.rs (2)
ensure_all_subscriptions(73-79)get_account_relay_statuses(41-51)rust/src/api/accounts.rs (1)
export_account_nsec(93-101)rust/src/api/messages.rs (1)
fetch_aggregated_messages_for_group(251-262)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Flutter CI
🔇 Additional comments (22)
lib/src/rust/api/users.dart (1)
2-2: Annotation update only — LGTM.Generated header reflects FRB 2.10.0; nothing else changed.
lib/src/rust/api/utils.dart (1)
2-2: Annotation bump acknowledged — no functional changes.All good.
lib/src/rust/api/error.dart (1)
2-2: Header version updated — LGTM.Generated file; no code changes in this segment.
lib/src/rust/api/accounts.dart (1)
2-2: Confirm FRB 2.10.0 pin and relay API changes across Dart & Rust
- pubspec.yaml uses flutter_rust_bridge 2.10.0
- ensureAllSubscriptions & getAccountRelayStatuses present; fetchRelayStatus removed
- verify Rust crate(s) Cargo.toml also pins flutter_rust_bridge to 2.10.0
lib/src/rust/api/groups.dart (1)
2-2: Header bump only — OKGenerated header matches FRB 2.10.0; no functional changes.
lib/src/rust/api/welcomes.dart (1)
2-2: Header bump only — OKGenerated header updated to FRB 2.10.0.
lib/src/rust/frb_generated.io.dart (1)
2-2: Header bump only — OKIO bridge header reflects FRB 2.10.0; no functional changes here.
pubspec.yaml (1)
40-40: Approve FRB 2.10.0 pin and bindings cleanup: Dart and Rust deps correctly pinned to 2.10.0, no 2.11.x remnants, new relays API present, old API removed.rust/Cargo.toml (1)
12-12: Confirm whitenoise API functions in commit
Manually verify that commit ae54a8d796af84c7c4357dcf7b317a930026ad09 of parres-hq/whitenoise (src/whitenoise/database/relays.rs) defines ensure_all_subscriptions and get_account_relay_statuses.lib/src/rust/lib.dart (1)
2-2: FRB header version update — OKNo functional changes; aligns with the codegen downgrade to 2.10.0.
lib/src/rust/api/messages.dart (1)
2-2: FRB header version update — OKNo functional changes; consistent with generator downgrade.
lib/src/rust/api/metadata.dart (1)
2-2: FRB header version update — OKNo functional changes; consistent with generator downgrade.
rust/src/api/relays.rs (2)
41-51: Rename and delegation look correctResolves account, delegates to core get_account_relay_statuses, converts to (String, String). Async and error mapping are correct.
53-79: New ensure_all_subscriptions API — solid, minimal bridgeExposes the core best‑effort checker with proper error mapping. Ready for background/periodic callers.
rust/src/frb_generated.rs (3)
740-774: Wire function for ensure_all_subscriptions added correctly.No args, async wrapper, proper debug_name. Looks good.
971-1007: Wire function for get_account_relay_statuses looks correct.Decodes pubkey and calls relays::get_account_relay_statuses. Matches Dart signature.
43-45: Dependency pinning verified: both Rust and Dart sides use flutter_rust_bridge 2.10.0 matching the codegen.lib/src/rust/api/relays.dart (3)
20-23: Confirm no stale fetchRelayStatus callers. Runrg -nP --type=dart '\bfetchRelayStatus\b'to ensure all invocations are replaced withgetAccountRelayStatuses.
24-44: Confirm generated binding exists and schedule with backoff
- Verify that
crateApiRelaysEnsureAllSubscriptionsis present in the generated Dart API underRustLib.instance.api.- Invoke this via a background task with exponential backoff instead of from UI frames.
2-2: FRB version alignment confirmed: pubspec.yaml and Cargo.toml both specify 2.10.0, matching generated code markers.lib/src/rust/frb_generated.dart (2)
370-396: FuncId remapping across file: ensure native side regeneratedNumerous funcId values changed after codegen downgrade and API additions. Verify Rust-side glue (wire/procedural macro output) is regenerated and included in this PR to avoid ABI mismatch at runtime.
Also applies to: 411-418, 545-556
2-2: FRB version and SDK constraint verified
All flutter_rust_bridge versions (2.10.0) align in pubspec.yaml, generated Dart files, Cargo.toml, and Rust code. Dart SDK ≥3.7.2 satisfies record support.
90f67c1 to
1a77336
Compare
Description
Exposes the ensureAllSubscriptions method from the Rust core to the Flutter API layer. This method was added in PR#382 to the whitenoise crate and is now available for use in periodic background tasks to ensure all subscriptions (global and per-account) remain operational.
Type of Change
Checklist
just precommitto ensure that formatting and linting are correctjust check-flutter-coverageto ensure that flutter coverage rules are passingCHANGELOG.mdfile with your changes (if they affect the user experience)Summary by CodeRabbit
New Features
Refactor
Chores