Handle npub correctly in draft notes

Damus stores npub as both Strings and URLs in NSAttributedString.Key.link when a note is saved as a draft. Make Damus correctly handle both when we retrieve and store drafts.

Changelog-Changed: Handle npub correctly in draft notes
Signed-off-by: Askeew <askeew@hotmail.com>
Closes: https://github.com/damus-io/damus/issues/2923
This commit is contained in:
Askia Linder
2025-06-21 17:32:29 +02:00
committed by Daniel D’Aquino
parent 51e07df1b5
commit 6f9a00d728
2 changed files with 45 additions and 1 deletions

View File

@@ -863,7 +863,9 @@ func build_post(state: DamusState, post: NSAttributedString, action: PostAction,
func build_post(state: DamusState, post: NSAttributedString, action: PostAction, uploadedMedias: [UploadedMedia], pubkeys: [Pubkey]) -> NostrPost {
let post = NSMutableAttributedString(attributedString: post)
post.enumerateAttributes(in: NSRange(location: 0, length: post.length), options: []) { attributes, range, stop in
if let link = attributes[.link] as? String {
let linkValue = attributes[.link]
let link = (linkValue as? String) ?? (linkValue as? URL)?.absoluteString
if let link {
let nextCharIndex = range.upperBound
if nextCharIndex < post.length,
let nextChar = post.attributedSubstring(from: NSRange(location: nextCharIndex, length: 1)).string.first,