Skip to content
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

Add URL where an Event is from when obtaining events through get_events_of() #190

Open
nobu-maeda opened this issue Nov 14, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@nobu-maeda
Copy link

Describe the enhancement
As titled. Currently Events are received without knowing which Relay its from if they are obtained through the get_events_of() client function. Suggestion here is to also return the URL as part of the callback (eg. in pool.rs)

Use case
It would help to determine which Relay to reply to, or DM to, if an application wishes to reply to the author of a particular event.

@nobu-maeda nobu-maeda added the enhancement New feature or request label Nov 14, 2023
@nobu-maeda
Copy link
Author

I can create a PR for this if this sounds like a reasonable proposal. Thanks

@yukibtc
Copy link
Member

yukibtc commented Nov 15, 2023

Hi, from commit f20c776 (PR #178) it's possible to query the local database (in-memory or persistent) to know in which relays the event was seen.
You can try this code using master branch:

[dependencies]
nostr-sdk = { git = "https://github.com/rust-nostr/nostr", branch = "master" }
# OR
nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "696ffd596c7fc69d299c4389fc2148c66538f226" }
// ...
let database = client.database();
let relays = database
    .event_recently_seen_on_relays(event_id)
    .await?;
println!("Seen on: {relays:?}");

@nobu-maeda
Copy link
Author

Seems to work, at least in my integration test environment. I am using event_recently_seen_on_relays() after calling get_events_of(). The first time I see an event, I call event_recently_seen_on_relays() and keep track of that event along with the relay url HashSet, and drop all subsequent occurrence of that eventID. The expectation is that the number of urls seen from event_recently_seen_on_relays() will always match the actual number of occurrences the events gets seen as a result of get_events_of().

I guess the most ideal is that the relay URL is part of the Event struct so that this somewhat hacky correlation is not needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants