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:
committed by
Daniel D’Aquino
parent
51e07df1b5
commit
6f9a00d728
@@ -176,6 +176,48 @@ final class PostViewTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(post.tags, [["q", test_note.id.hex()]])
|
||||
}
|
||||
|
||||
func testBuildPostRecognizesStringsAsNpubs() throws {
|
||||
// given
|
||||
let expectedLink = "nostr:\(test_pubkey.npub)"
|
||||
let content = NSMutableAttributedString(string: "@test", attributes: [
|
||||
NSAttributedString.Key.link: "damus:\(expectedLink)"
|
||||
])
|
||||
|
||||
// when
|
||||
let post = build_post(
|
||||
state: test_damus_state,
|
||||
post: content,
|
||||
action: .posting(.user(test_pubkey)),
|
||||
uploadedMedias: [],
|
||||
pubkeys: []
|
||||
)
|
||||
|
||||
// then
|
||||
XCTAssertEqual(post.content, expectedLink)
|
||||
}
|
||||
|
||||
func testBuildPostRecognizesUrlsAsNpubs() throws {
|
||||
// given
|
||||
guard let npubUrl = URL(string: "damus:nostr:\(test_pubkey.npub)") else {
|
||||
return XCTFail("Could not create URL")
|
||||
}
|
||||
let content = NSMutableAttributedString(string: "@test", attributes: [
|
||||
NSAttributedString.Key.link: npubUrl
|
||||
])
|
||||
|
||||
// when
|
||||
let post = build_post(
|
||||
state: test_damus_state,
|
||||
post: content,
|
||||
action: .posting(.user(test_pubkey)),
|
||||
uploadedMedias: [],
|
||||
pubkeys: []
|
||||
)
|
||||
|
||||
// then
|
||||
XCTAssertEqual(post.content, "nostr:\(test_pubkey.npub)")
|
||||
}
|
||||
}
|
||||
|
||||
func checkMentionLinkEditorHandling(
|
||||
|
||||
Reference in New Issue
Block a user