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

Handle njump me links #1202

Merged
merged 7 commits into from
Jun 5, 2024
Merged

Handle njump me links #1202

merged 7 commits into from
Jun 5, 2024

Conversation

mplorentz
Copy link
Member

Issues covered

This is related to #367, but it doesn't quite cover all of it and that ticket isn't prioritized so I'm not going to move it into the sprint or anything. @rabble was complaining about this so I was going to write up a comment about how to do it but it was so easy that ended up just doing it.

Description

This adds code to handle the links njump.me is using if you tap "Open in Nos" from their site.

How to test

  1. In Nos on an iPhone (not macOS), tap "Copy link" on a note or profile.
  2. Paste the link into Safari
  3. Tap the four squares icon in the bottom right of the screen next to "open in your default app"
  4. The next part depends on what version of the app you are running. If you are running the production app you can just tap Nos. Otherwise tap and hold on Nos and drag the link into the notes app. Then tap "Edit link" and change the beginning from "nos:" to "nos-dev:" or "nos-staging" depending on what version of the app you are using. Then tap "Done" and tap the link.

The Nos app should open and display the note or profile.

Screenshots/Video

RPReplay_Final1717080608.MP4

Copy link
Member

@martindsq martindsq left a comment

Choose a reason for hiding this comment

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

I'm happy njump is working now! We should add support for the nostr: scheme. I think this kind of things are super important.

} else {
/// Check for links like nos:nevent123174
let firstPathComponent = components.path
let unformattedRegex = /(?:nostr:)?(?<entity>((npub1|note1|nprofile1|nevent1)[a-zA-Z0-9]{58,255}))/
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this regex to a new shared place? Even though the regex could be not 100% the same and could not be shared, we are repeating patterns for some things and I found myself sometimes having to fix a problem with one regex and having to search for the other ones to see if the same error could occur there. Just a centralized place where we put all regexes could help to identify potential issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

I want to add support for nostr: too. I considered refactoring NoteParser and this code to share a regex, but I didn't because this was just a few minutes of work that I didn't want to throw away because it seemed really useful. I didn't want to (probably) quadruple the time I spent on it to do a refactor. I tried to pull out the shared part of the regex into a constant, but you can't interpolate a regex literal inside another regex literal, so I would have to switch to NSRegularExpression or something, which would require more code refactoring... and that would only be for the regex itself. To share the code that extracts the hex from bech32 would require some more.

Given that this is the second place we are using the regex I'm ok with duplicating it. I like the rule of waiting to refactor until you've copied code in three places rather than two.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. Let's keep the eyes open for the next time we need to add or modify a regex to include that refactor in the scope of the ticket.

@mplorentz mplorentz requested a review from martindsq June 3, 2024 18:37
@joshuatbrown
Copy link
Contributor

Excited to have this!

@mplorentz mplorentz enabled auto-merge June 4, 2024 19:18
@mplorentz mplorentz added this pull request to the merge queue Jun 5, 2024
Merged via the queue into main with commit 9edd6b8 Jun 5, 2024
5 checks passed
@mplorentz mplorentz deleted the handle-njump-me-links branch June 5, 2024 18:32
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