Skip to content

Conversation

@jgmontoya
Copy link
Contributor

@jgmontoya jgmontoya commented Aug 11, 2025

Summary by CodeRabbit

  • New Features
    • After login, the app now refreshes your account data in the background.
    • New accounts publish basic profile/metadata after activation.
  • Refactor
    • Account creation and login flows reorganized into smaller, private helper steps for improved reliability (no public API changes).
    • Relay publishing logic restructured for clearer new-vs-existing account paths.
  • Tests
    • Added tests validating relay-list publishing behavior.
  • Chores
    • Running Just without a target now lists available project commands by default.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds a default Justfile recipe; refactors account creation/login into private helper steps without public API changes; introduces a pubkey-centric relay-publishing helper, updates publishing logic and tag kinds, and adds tests for relay-list event construction.

Changes

Cohort / File(s) Summary
Build tooling
justfile
Adds a public default recipe executing @just --list, placed under the Development section before clear-dev-data.
Account lifecycle refactor
src/whitenoise/accounts/mod.rs
Replaces monolithic setup with private helpers: create_base_account_with_private_key, setup_relays_for_new_account, setup_relays_for_existing_account, persist_and_activate_account, setup_metadata, setup_key_package, persist_account, and background_fetch_account_data. create_identity and login keep signatures; login now triggers background fetch post-activation.
Relay publishing refactor + tests
src/whitenoise/accounts/relays.rs
Adds publish_relay_list_for_pubkey (pub(crate)), refactors publish_relay_list_for_account to delegate, differentiates tag kinds by RelayType (Nostr vs Inbox/KeyPackage), removes unnecessary cloning, aligns publish call to use target relays, and adds tests validating relay-tag/r-tag construction and contents.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Whitenoise
  participant SecretStore
  participant DB
  participant Relays
  participant Subscriptions

  User->>Whitenoise: create_identity(petname, ...)
  activate Whitenoise
  Whitenoise->>SecretStore: store private key
  Whitenoise->>Whitenoise: setup_relays_for_new_account()
  Whitenoise->>DB: persist_account()
  Whitenoise->>Relays: connect and publish defaults
  Whitenoise->>Whitenoise: setup_key_package()
  Whitenoise->>Subscriptions: setup subscriptions
  Whitenoise->>Whitenoise: setup_metadata(petname)
  deactivate Whitenoise
Loading
sequenceDiagram
  participant User
  participant Whitenoise
  participant SecretStore
  participant DB
  participant Relays
  participant Subscriptions
  participant Fetcher

  User->>Whitenoise: login(credentials)
  activate Whitenoise
  Whitenoise->>SecretStore: store private key
  Whitenoise->>Whitenoise: setup_relays_for_existing_account()
  Whitenoise->>DB: persist_account()
  Whitenoise->>Relays: connect
  Whitenoise->>Whitenoise: setup_key_package()
  Whitenoise->>Subscriptions: setup subscriptions
  Whitenoise-->>Fetcher: trigger background data fetch
  deactivate Whitenoise
Loading
sequenceDiagram
  participant Account
  participant Whitenoise
  participant Signer
  participant TargetRelays

  Account->>Whitenoise: publish_relay_list_for_account(type, target_relays?)
  Whitenoise->>Whitenoise: compute relay_list and relays_to_use
  Whitenoise->>Signer: build+sign event (tags vary by RelayType)
  Whitenoise->>TargetRelays: publish event
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~35 minutes

Possibly related PRs

  • Refactor Signup Login #300: Refactors account creation/login and relay-publishing logic in the same modules (mod.rs and relays.rs); overlaps in lifecycle orchestration and relay publication changes.
  • Refactor relay methods #296: Related changes to relay publishing paths in relays.rs; overlaps with helper extraction and publishing behavior.
  • Fix tag reference #305: Adjusts relay-list event construction/tag kinds in relays.rs; closely aligned with tag-kind differentiation and tests added here.

Suggested reviewers

  • delcin-raj

Poem

I thump my whiskers, code in tow,
Keys tucked safe where secrets grow.
Relays hum, events take wing,
Default just lists everything.
Hop—new helpers pave the spring! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f83882 and 90a65f6.

📒 Files selected for processing (1)
  • src/whitenoise/accounts/mod.rs (3 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/setup-account

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
src/whitenoise/accounts/mod.rs (1)

600-617: Persist: good cleanup on failure; minor consistency nits

  • Cleanup of stored private key on DB save failure is appreciated.
  • Consider standardizing tracing targets (they vary between setup_account and persist_and_activate_account) for easier log filtering.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aa07b2d and 2f83882.

📒 Files selected for processing (3)
  • justfile (1 hunks)
  • src/whitenoise/accounts/mod.rs (3 hunks)
  • src/whitenoise/accounts/relays.rs (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/whitenoise/accounts/mod.rs (2)
src/whitenoise/utils.rs (1)
  • capitalize_first_letter (128-134)
src/whitenoise/secrets_store.rs (1)
  • new (44-48)
src/whitenoise/accounts/relays.rs (1)
src/whitenoise/accounts/mod.rs (1)
  • new (183-200)
⏰ 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). (2)
  • GitHub Check: check (macos-latest, native)
  • GitHub Check: check (ubuntu-latest, native)
🔇 Additional comments (5)
justfile (1)

5-7: LGTM: Default recipe lists available commands

This is a sensible default and non-invasive. No issues.

src/whitenoise/accounts/relays.rs (3)

280-309: Helper correctness: tag mapping and signer-based publish

The new helper cleanly maps:

  • Nostr -> "r" tags (Tag::reference), kind 10002
  • Inbox/KeyPackage -> "relay" tags (Tag::custom(TagKind::Relay)), kinds 10050/10051

Using publish_event_builder_with_signer with the per-pubkey signer is correct, and passing target_relays by value avoids unnecessary cloning. Looks good.


950-1024: Tests for Nostr relay-list publishing are spot on

The test asserts correct kind, tag types (only 'r' tags), counts, and empty content. This validates observable behavior well. Nice.


1026-1110: Tests for Inbox/KeyPackage relay-list publishing are comprehensive

Looping over both kinds, asserting 'relay' tags only, and verifying contents keeps coverage DRY and focused. Solid.

src/whitenoise/accounts/mod.rs (1)

258-269: No action needed: relay publishing already ensures connections

The publish_event_builder_with_signer method calls ensure_relays_connected(relays.clone()).await before sending any events, so relays are connected on-demand prior to publishing. You can safely ignore the suggested refactor for pre-connecting in setup_relays_for_new_account.

Likely an incorrect or invalid review comment.

Comment on lines +581 to 599
async fn setup_metadata(&self, account: &Account) -> Result<()> {
let petname = petname::petname(2, " ")
.unwrap_or_else(|| "Anonymous User".to_string())
.split_whitespace()
.map(Whitenoise::capitalize_first_letter)
.collect::<Vec<_>>()
.join(" ");

let key_package_relays = if is_new_account {
Account::default_relays()
} else {
match self
.fetch_relays_from(nip65_relays.clone(), pubkey, RelayType::KeyPackage)
.await
{
Ok(relays) if !relays.is_empty() => relays,
_ => {
need_to_publish_key_package = true;
Account::default_relays()
}
}
let metadata = Metadata {
name: Some(petname.clone()),
display_name: Some(petname),
..Default::default()
};

// Step 3: Create account struct
let account = Account {
pubkey,
settings: AccountSettings::default(),
last_synced: Timestamp::zero(),
nip65_relays,
inbox_relays,
key_package_relays,
nostr_mls: Account::create_nostr_mls(pubkey, &self.config.data_dir)?,
};
self.update_metadata(&metadata, account).await?;
tracing::debug!(target: "whitenoise::setup_metadata", "Created and published metadata with petname: {}", metadata.name.as_ref().unwrap_or(&"Unknown".to_string()));
Ok(())
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the capitalization helper is resolvable

Whitenoise::capitalize_first_letter suggests an associated method, but the provided snippet shows a free function whitenoise::utils::capitalize_first_letter(...). If the associated method doesn’t exist, this won’t compile. Either import and call the free function or add an associated wrapper.

Run this to confirm the helper exists as an associated function:


🏁 Script executed:

#!/bin/bash
# Find any associated method named `capitalize_first_letter` on Whitenoise
rg -n $'impl\\s+Whitenoise\\s*\\{[^}]*capitalize_first_letter' -A 2 -B 2
# Also find the free function
rg -n $'fn\\s+capitalize_first_letter\\s*\\('

Length of output: 208


Fix capitalization helper reference

The code currently calls Whitenoise::capitalize_first_letter, but no such associated method exists. The helper is defined as a free function in src/whitenoise/utils.rs. You must either:

  • Import and call the free function directly
    use crate::utils::capitalize_first_letter;
    
    // …
    .map(capitalize_first_letter)
  • Or add a wrapper in impl Whitenoise { … } that delegates to the free function.

Locations to update:

  • src/whitenoise/accounts/mod.rs (around line 585): replace Whitenoise::capitalize_first_letter with the imported capitalize_first_letter

Example diff:

 use petname;
+use crate::utils::capitalize_first_letter;

     // …
-    .map(Whitenoise::capitalize_first_letter)
+    .map(capitalize_first_letter)
     // …
🤖 Prompt for AI Agents
In src/whitenoise/accounts/mod.rs around lines 581 to 599, the code calls a
non-existent associated method Whitenoise::capitalize_first_letter; import the
free helper from the utils module and use it directly: add a use
crate::whitenoise::utils::capitalize_first_letter; (or an appropriate relative
path) at the top of the file and replace
.map(Whitenoise::capitalize_first_letter) with .map(capitalize_first_letter).
Ensure the import path matches the crate/module layout.

Copy link
Member

@erskingardner erskingardner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small naming suggestion but all good.

self.background_fetch_account_data(&account).await?;
tracing::debug!(target: "whitenoise::setup_account", "Background data fetch triggered");
}
fn create_base_account_with_stored_key(&self, keys: &Keys) -> Result<Account> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe change the name of this to be create_base_account_with_key (the key isn't stored until this method is called)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to create_base_account_with_private_key

Removes setup_account and creates individual private functions for the required steps
@jgmontoya jgmontoya force-pushed the refactor/setup-account branch from 2f83882 to 90a65f6 Compare August 11, 2025 10:27
@jgmontoya jgmontoya merged commit a7bf49f into master Aug 11, 2025
3 of 4 checks passed
@jgmontoya jgmontoya deleted the refactor/setup-account branch August 11, 2025 10:32
This was referenced Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants