Skip to content

Conversation

@josefinalliende
Copy link
Contributor

@josefinalliende josefinalliende commented Aug 30, 2025

Description

The get user method was searching in the existing users in database but not creating a new one if the npub wasn't saved in db yet. In parres-hq/whitenoise#336 we made publlic the method to find or create a user, and updated the metadata and relays

Changes:

This PR fixes the get user method in the bridge by using the find or create method from whitenoise crate

Example of results of same pub before and after:

Before After
efore After

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore
  • 🧪 Tests

Checklist

  • Run just precommit to ensure that formatting and linting are correct
  • Run just check-flutter-coverage to ensure that flutter coverage rules are passing
  • Updated the CHANGELOG.md file with your changes (if they affect the user experience)

Summary by CodeRabbit

  • Bug Fixes

    • Resolved an issue where searching for a previously unseen npub wouldn’t show user metadata by automatically creating the user during lookup, ensuring consistent results.
  • Chores

    • Updated an internal dependency to a newer revision to improve stability and maintainability. No behavioral changes expected.
  • Documentation

    • Added an entry to the Unreleased -> Fixed section of the changelog describing the user search/metadata correction.
  • Notes

    • No public API or interface changes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 30, 2025

Walkthrough

Updates changelog text, bumps the whitenoise Git dependency revision in Cargo.toml, and modifies get_user to call find_or_create_user_by_pubkey instead of find_user_by_pubkey, enabling user creation on lookup.

Changes

Cohort / File(s) Summary
Documentation
CHANGELOG.md
Added Unreleased -> Fixed entry noting get user logic shows metadata when searching a new npub; no API changes.
Dependencies
rust/Cargo.toml
Updated whitenoise Git revision from b1ac58b... to 70282b4...; no other dependency changes.
User retrieval logic
rust/src/api/users.rs
In get_user, replaced find_user_by_pubkey(...) with find_or_create_user_by_pubkey(...); behavior now creates user if absent; signatures unchanged.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Client
    participant API as API:get_user
    participant Repo as UsersRepo
    Client->>API: GET /users/{pubkey}
    API->>Repo: find_or_create_user_by_pubkey(pubkey)
    alt User does not exist
        rect rgba(200,230,255,0.35)
        note over Repo: Create user record with metadata
        Repo-->>API: Newly created User
        end
    else User exists
        Repo-->>API: Existing User
    end
    API-->>Client: 200 OK + User (with metadata)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

Thump-thump—my paws tap code with glee,
A fresh npub hops into being, you see.
Cargo hums, a hash anew,
Changelog whispers what we do.
Find or create—no burrow too deep—
Metadata carrots, for users to keep. 🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/get-user

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.
    • 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.
  • 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 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/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@josefinalliende josefinalliende linked an issue Aug 30, 2025 that may be closed by this pull request
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: 0

🧹 Nitpick comments (3)
CHANGELOG.md (1)

24-24: Polish the entry for clarity and code-style.

Use the function name and be explicit about the behavior.

-- Fixed get user logic, to show metadata when searching a new npub
+- Fix `get_user` logic: create user on first lookup (new npub) so metadata is shown.
rust/src/api/users.rs (1)

33-35: Correct fix; consider documenting side effects and aligning other API calls.

  • This switches to create-on-read, which can write to storage. Add a brief doc comment so callers know it persists state.
  • Consider using the same create-on-read behavior in user_metadata, user_relays, and user_has_key_package to avoid 404/NotFound if they’re called first. If that’s not desired, leave as-is but document the difference.

Add docs above get_user:

/// Returns the user, creating a local record if it doesn't exist.
/// Side effect: may write to storage and trigger metadata/relay updates.
pub async fn get_user(pubkey: String) -> Result<User, ApiError> { ... }

Optional consistency change:

-    let user = whitenoise.find_user_by_pubkey(&pubkey).await?;
+    let user = whitenoise.find_or_create_user_by_pubkey(&pubkey).await?;

Please confirm whether create-on-read is intended across these endpoints or only for get_user.

rust/Cargo.toml (1)

26-26: Pin revision correct; verify lockfile and add traceability comment

  • Ensure rust/Cargo.lock is committed and updated to reference this rev so CI installs deterministically.
  • Add an inline comment linking to the upstream PR (e.g. parres-hq/whitenoise#336) for future traceability.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3b46956 and eeacd90.

⛔ Files ignored due to path filters (3)
  • ios/Podfile.lock is excluded by !**/*.lock
  • pubspec.lock is excluded by !**/*.lock
  • rust/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • rust/Cargo.toml (1 hunks)
  • rust/src/api/users.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.md

📄 CodeRabbit inference engine (.cursor/rules/whitenoise.mdc)

**/*.md: NIPs (Nostr Implementation Possibilities) are numbered like NIP-XX where XX are two capitalized hexadecimal digits, e.g., NIP-01 and NIP-C7.
To read a specific NIP, construct the NIP URL following this template: https://raw.githubusercontent.com/nostr-protocol/nips/refs/heads/master/{nip}.md (replace {nip} in the URL template with the relevant NIP name, e.g., 07 for NIP-07, or C7 for NIP-C7).
To read the definition of a specific kind, construct a URL following this template: https://nostrbook.dev/kinds/{kind}.md (replace {kind} in the template with the kind number, e.g., https://nostrbook.dev/kinds/0.md for kind 0).

Files:

  • CHANGELOG.md

@josefinalliende josefinalliende merged commit 1cad807 into master Aug 30, 2025
2 checks passed
@josefinalliende josefinalliende deleted the fix/get-user branch August 30, 2025 13:49
@coderabbitai coderabbitai bot mentioned this pull request Sep 2, 2025
11 tasks
@coderabbitai coderabbitai bot mentioned this pull request Sep 13, 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.

Find or create user

4 participants