commit 0c95071de75f8c81a391a0f644cf64dafed06407
parent da78a217a337236340e0911052863684b0c2568d
Author: William Casarin <jb55@jb55.com>
Date: Sun, 16 Jul 2023 10:49:31 -0700
project: rename parse_mentions to parse_note_content
This is more accurate
Diffstat:
9 files changed, 40 insertions(+), 40 deletions(-)
diff --git a/damus/Models/Mentions.swift b/damus/Models/Mentions.swift
@@ -163,7 +163,7 @@ struct Blocks {
let blocks: [Block]
}
-func parse_mentions(content: String, tags: [[String]]) -> Blocks {
+func parse_note_content(content: String, tags: [[String]]) -> Blocks {
var out: [Block] = []
var bs = note_blocks()
diff --git a/damus/Models/Post.swift b/damus/Models/Post.swift
@@ -111,6 +111,6 @@ func parse_post_bech32_mention(_ p: Parser) -> ReferencedId? {
/// Return a list of tags
func parse_post_blocks(content: String) -> [Block] {
- return parse_mentions(content: content, tags: []).blocks
+ return parse_note_content(content: content, tags: []).blocks
}
diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift
@@ -102,7 +102,7 @@ class NostrEvent: Codable, Identifiable, CustomStringConvertible, Equatable, Has
}
func get_blocks(content: String) -> Blocks {
- return parse_mentions(content: content, tags: self.tags)
+ return parse_note_content(content: content, tags: self.tags)
}
private lazy var inner_event: NostrEvent? = {
diff --git a/damus/Views/Profile/AboutView.swift b/damus/Views/Profile/AboutView.swift
@@ -39,7 +39,7 @@ struct AboutView: View {
}
}
.onAppear {
- let blocks = parse_mentions(content: about, tags: [])
+ let blocks = parse_note_content(content: about, tags: [])
about_string = render_blocks(blocks: blocks, profiles: state.profiles).content.attributed
}
diff --git a/damusTests/HashtagTests.swift b/damusTests/HashtagTests.swift
@@ -19,7 +19,7 @@ final class HashtagTests: XCTestCase {
}
func testParseHashtag() {
- let parsed = parse_mentions(content: "some hashtag #bitcoin derp", tags: []).blocks
+ let parsed = parse_note_content(content: "some hashtag #bitcoin derp", tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 3)
@@ -29,7 +29,7 @@ final class HashtagTests: XCTestCase {
}
func testHashtagWithComma() {
- let parsed = parse_mentions(content: "some hashtag #bitcoin, cool", tags: []).blocks
+ let parsed = parse_note_content(content: "some hashtag #bitcoin, cool", tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 3)
@@ -40,7 +40,7 @@ final class HashtagTests: XCTestCase {
func testHashtagWithEmoji() {
let content = "some hashtag #bitcoin☕️ cool"
- let parsed = parse_mentions(content: content, tags: []).blocks
+ let parsed = parse_note_content(content: content, tags: []).blocks
let post_blocks = parse_post_blocks(content: content)
XCTAssertNotNil(parsed)
@@ -57,7 +57,7 @@ final class HashtagTests: XCTestCase {
func testPowHashtag() {
let content = "pow! #ぽわ〜"
- let parsed = parse_mentions(content: content, tags: []).blocks
+ let parsed = parse_note_content(content: content, tags: []).blocks
let post_blocks = parse_post_blocks(content: content)
XCTAssertNotNil(parsed)
@@ -71,7 +71,7 @@ final class HashtagTests: XCTestCase {
}
func testHashtagWithAccents() {
- let parsed = parse_mentions(content: "hello from #türkiye", tags: []).blocks
+ let parsed = parse_note_content(content: "hello from #türkiye", tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 2)
@@ -80,7 +80,7 @@ final class HashtagTests: XCTestCase {
}
func testHashtagWithNonLatinCharacters() {
- let parsed = parse_mentions(content: "this is a #시험 hope it works", tags: []).blocks
+ let parsed = parse_note_content(content: "this is a #시험 hope it works", tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 3)
@@ -90,7 +90,7 @@ final class HashtagTests: XCTestCase {
}
func testParseHashtagEnd() {
- let parsed = parse_mentions(content: "some hashtag #bitcoin", tags: []).blocks
+ let parsed = parse_note_content(content: "some hashtag #bitcoin", tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 2)
diff --git a/damusTests/InvoiceTests.swift b/damusTests/InvoiceTests.swift
@@ -20,7 +20,7 @@ final class InvoiceTests: XCTestCase {
func testParseAnyAmountInvoice() throws {
let invstr = "LNBC1P3MR5UJSP5G7SA48YD4JWTTPCHWMY4QYN4UWZQCJQ8NMWKD6QE3HCRVYTDLH9SPP57YM9TSA9NN4M4XU59XMJCXKR7YDV29DDP6LVQUT46ZW6CU3KE9GQDQ9V9H8JXQ8P3MYLZJCQPJRZJQF60PZDVNGGQWQDNERZSQN35L8CVQ3QG2Z5NSZYD0D3Q0JW2TL6VUZA7FYQQWKGQQYQQQQLGQQQQXJQQ9Q9QXPQYSGQ39EM4QJMQFKZGJXZVGL7QJMYNSWA8PGDTAGXXRG5Z92M7VLCGKQK2L2THDF8LM0AUKAURH7FVAWDLRNMVF38W4EYJDNVN9V4Z9CRS5CQCV465C"
- let parsed = parse_mentions(content: invstr, tags: []).blocks
+ let parsed = parse_note_content(content: invstr, tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 1)
@@ -38,7 +38,7 @@ final class InvoiceTests: XCTestCase {
let invstr = """
LNBC1P3MR5UJSP5G7SA48YD4JWTTPCHWMY4QYN4UWZQCJQ8NMWKD6QE3HCRVYTDLH9SPP57YM9TSA9NN4M4XU59XMJCXKR7YDV29DDP6LVQUT46ZW6CU3KE9GQDQ9V9H8JXQ8P3MYLZJCQPJRZJQF60PZDVNGGQWQDNERZSQN35L8CVQ3QG2Z5NSZYD0D3Q0JW2TL6VUZA7FYQQWKGQQYQQQQLGQQQQXJQQ9Q9QXPQYSGQ39EM4QJMQFKZGJXZVGL7QJMYNSWA8PGDTAGXXRG5Z92M7VLCGKQK2L2THDF8LM0AUKAURH7FVAWDLRNMVF38W4EYJDNVN9V4Z9CRS5CQCV465C hi there
"""
- let parsed = parse_mentions(content: invstr, tags: []).blocks
+ let parsed = parse_note_content(content: invstr, tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 2)
@@ -54,7 +54,7 @@ LNBC1P3MR5UJSP5G7SA48YD4JWTTPCHWMY4QYN4UWZQCJQ8NMWKD6QE3HCRVYTDLH9SPP57YM9TSA9NN
func testParseInvoiceUpper() throws {
let invstr = "LNBC100N1P357SL0SP5T9N56WDZTUN39LGDQLR30XQWKSG3K69Q4Q2RKR52APLUJW0ESN0QPP5MRQGLJK62Z20Q4NVGR6LZCYN6FHYLZCCWDVU4K77APG3ZMRKUJJQDPZW35XJUEQD9EJQCFQV3JHXCMJD9C8G6T0DCXQYJW5QCQPJRZJQT56H4GVP5YX36U2UZQA6QWCSK3E2DUUNFXPPZJ9VHYPC3WFE2WSWZ607UQQ3XQQQSQQQQQQQQQQQLQQYG9QYYSGQAGX5H20AEULJ3GDWX3KXS8U9F4MCAKDKWUAKASAMM9562FFYR9EN8YG20LG0YGNR9ZPWP68524KMDA0T5XP2WYTEX35PU8HAPYJAJXQPSQL29R"
- let parsed = parse_mentions(content: invstr, tags: []).blocks
+ let parsed = parse_note_content(content: invstr, tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 1)
@@ -70,7 +70,7 @@ LNBC1P3MR5UJSP5G7SA48YD4JWTTPCHWMY4QYN4UWZQCJQ8NMWKD6QE3HCRVYTDLH9SPP57YM9TSA9NN
func testParseInvoiceWithPrefix() throws {
let invstr = "lightning:lnbc100n1p357sl0sp5t9n56wdztun39lgdqlr30xqwksg3k69q4q2rkr52aplujw0esn0qpp5mrqgljk62z20q4nvgr6lzcyn6fhylzccwdvu4k77apg3zmrkujjqdpzw35xjueqd9ejqcfqv3jhxcmjd9c8g6t0dcxqyjw5qcqpjrzjqt56h4gvp5yx36u2uzqa6qwcsk3e2duunfxppzj9vhypc3wfe2wswz607uqq3xqqqsqqqqqqqqqqqlqqyg9qyysgqagx5h20aeulj3gdwx3kxs8u9f4mcakdkwuakasamm9562ffyr9en8yg20lg0ygnr9zpwp68524kmda0t5xp2wytex35pu8hapyjajxqpsql29r"
- let parsed = parse_mentions(content: invstr, tags: []).blocks
+ let parsed = parse_note_content(content: invstr, tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 1)
@@ -79,7 +79,7 @@ LNBC1P3MR5UJSP5G7SA48YD4JWTTPCHWMY4QYN4UWZQCJQ8NMWKD6QE3HCRVYTDLH9SPP57YM9TSA9NN
func testParseInvoiceWithPrefixCapitalized() throws {
let invstr = "LIGHTNING:LNBC100N1P357SL0SP5T9N56WDZTUN39LGDQLR30XQWKSG3K69Q4Q2RKR52APLUJW0ESN0QPP5MRQGLJK62Z20Q4NVGR6LZCYN6FHYLZCCWDVU4K77APG3ZMRKUJJQDPZW35XJUEQD9EJQCFQV3JHXCMJD9C8G6T0DCXQYJW5QCQPJRZJQT56H4GVP5YX36U2UZQA6QWCSK3E2DUUNFXPPZJ9VHYPC3WFE2WSWZ607UQQ3XQQQSQQQQQQQQQQQLQQYG9QYYSGQAGX5H20AEULJ3GDWX3KXS8U9F4MCAKDKWUAKASAMM9562FFYR9EN8YG20LG0YGNR9ZPWP68524KMDA0T5XP2WYTEX35PU8HAPYJAJXQPSQL29R"
- let parsed = parse_mentions(content: invstr, tags: []).blocks
+ let parsed = parse_note_content(content: invstr, tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 1)
@@ -88,7 +88,7 @@ LNBC1P3MR5UJSP5G7SA48YD4JWTTPCHWMY4QYN4UWZQCJQ8NMWKD6QE3HCRVYTDLH9SPP57YM9TSA9NN
func testParseInvoice() throws {
let invstr = "lnbc100n1p357sl0sp5t9n56wdztun39lgdqlr30xqwksg3k69q4q2rkr52aplujw0esn0qpp5mrqgljk62z20q4nvgr6lzcyn6fhylzccwdvu4k77apg3zmrkujjqdpzw35xjueqd9ejqcfqv3jhxcmjd9c8g6t0dcxqyjw5qcqpjrzjqt56h4gvp5yx36u2uzqa6qwcsk3e2duunfxppzj9vhypc3wfe2wswz607uqq3xqqqsqqqqqqqqqqqlqqyg9qyysgqagx5h20aeulj3gdwx3kxs8u9f4mcakdkwuakasamm9562ffyr9en8yg20lg0ygnr9zpwp68524kmda0t5xp2wytex35pu8hapyjajxqpsql29r"
- let parsed = parse_mentions(content: invstr, tags: []).blocks
+ let parsed = parse_note_content(content: invstr, tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 1)
diff --git a/damusTests/NIP19Tests.swift b/damusTests/NIP19Tests.swift
@@ -19,7 +19,7 @@ final class NIP19Tests: XCTestCase {
}
func test_parse_nprofile() throws {
- let res = parse_mentions(content: "nostr:nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpp4mhxue69uhhytnc9e3k7mgpz4mhxue69uhkg6nzv9ejuumpv34kytnrdaksjlyr9p", tags: []).blocks
+ let res = parse_note_content(content: "nostr:nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpp4mhxue69uhhytnc9e3k7mgpz4mhxue69uhkg6nzv9ejuumpv34kytnrdaksjlyr9p", tags: []).blocks
XCTAssertEqual(res.count, 1)
let expected_ref = ReferencedId(ref_id: "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d", relay_id: "wss://r.x.com", key: "p")
let expected_mention = Mention(index: nil, type: .pubkey, ref: expected_ref)
@@ -27,7 +27,7 @@ final class NIP19Tests: XCTestCase {
}
func test_parse_npub() throws {
- let res = parse_mentions(content: "nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg ", tags: []).blocks
+ let res = parse_note_content(content: "nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg ", tags: []).blocks
XCTAssertEqual(res.count, 2)
let expected_ref = ReferencedId(ref_id: "7e7e9c42a91bfef19fa929e5fda1b72e0ebc1a4c1141673e2794234d86addf4e", relay_id: nil, key: "p")
let expected_mention = Mention(index: nil, type: .pubkey, ref: expected_ref)
@@ -35,7 +35,7 @@ final class NIP19Tests: XCTestCase {
}
func test_parse_note() throws {
- let res = parse_mentions(content: " nostr:note1s4p70596lv50x0zftuses32t6ck8x6wgd4edwacyetfxwns2jtysux7vep", tags: []).blocks
+ let res = parse_note_content(content: " nostr:note1s4p70596lv50x0zftuses32t6ck8x6wgd4edwacyetfxwns2jtysux7vep", tags: []).blocks
XCTAssertEqual(res.count, 2)
let expected_ref = ReferencedId(ref_id: "8543e7d0bafb28f33c495f2198454bd62c7369c86d72d77704cad2674e0a92c9", relay_id: nil, key: "e")
let expected_mention = Mention(index: nil, type: .event, ref: expected_ref)
@@ -43,7 +43,7 @@ final class NIP19Tests: XCTestCase {
}
func test_mention_with_adjacent() throws {
- let res = parse_mentions(content: " nostr:note1s4p70596lv50x0zftuses32t6ck8x6wgd4edwacyetfxwns2jtysux7vep?", tags: []).blocks
+ let res = parse_note_content(content: " nostr:note1s4p70596lv50x0zftuses32t6ck8x6wgd4edwacyetfxwns2jtysux7vep?", tags: []).blocks
XCTAssertEqual(res.count, 3)
let expected_ref = ReferencedId(ref_id: "8543e7d0bafb28f33c495f2198454bd62c7369c86d72d77704cad2674e0a92c9", relay_id: nil, key: "e")
let expected_mention = Mention(index: nil, type: .event, ref: expected_ref)
diff --git a/damusTests/ReplyTests.swift b/damusTests/ReplyTests.swift
@@ -21,7 +21,7 @@ class ReplyTests: XCTestCase {
func testMentionIsntReply() throws {
let content = "this is #[0] a mention"
let tags = [["e", "event_id"]]
- let blocks = parse_mentions(content: content, tags: tags).blocks
+ let blocks = parse_note_content(content: content, tags: tags).blocks
let event_refs = interpret_event_refs(blocks: blocks, tags: tags)
XCTAssertEqual(event_refs.count, 1)
@@ -94,7 +94,7 @@ class ReplyTests: XCTestCase {
func testRootReplyWithMention() throws {
let content = "this is #[1] a mention"
let tags = [["e", "thread_id"], ["e", "mentioned_id"]]
- let blocks = parse_mentions(content: content, tags: tags).blocks
+ let blocks = parse_note_content(content: content, tags: tags).blocks
let event_refs = interpret_event_refs(blocks: blocks, tags: tags)
XCTAssertEqual(event_refs.count, 2)
@@ -112,7 +112,7 @@ class ReplyTests: XCTestCase {
func testEmptyMention() throws {
let content = "this is some & content"
let tags: [[String]] = []
- let blocks = parse_mentions(content: content, tags: tags).blocks
+ let blocks = parse_note_content(content: content, tags: tags).blocks
let post_blocks = parse_post_blocks(content: content)
let post_tags = make_post_tags(post_blocks: post_blocks, tags: tags, silent_mentions: false)
let event_refs = interpret_event_refs(blocks: blocks, tags: tags)
@@ -126,7 +126,7 @@ class ReplyTests: XCTestCase {
func testManyMentions() throws {
let content = "#[10]"
let tags: [[String]] = [[],[],[],[],[],[],[],[],[],[],["p", "3e999f94e2cb34ef44a64b351141ac4e51b5121b2d31aed4a6c84602a1144692"]]
- let blocks = parse_mentions(content: content, tags: tags).blocks
+ let blocks = parse_note_content(content: content, tags: tags).blocks
let mentions = blocks.filter { $0.is_mention != nil }
XCTAssertEqual(mentions.count, 1)
}
@@ -149,7 +149,7 @@ class ReplyTests: XCTestCase {
let expected_render = "nostr:\(pk)\nnostr:\(pk)"
XCTAssertEqual(post_note.content, expected_render)
- let blocks = parse_mentions(content: post_note.content, tags: []).blocks
+ let blocks = parse_note_content(content: post_note.content, tags: []).blocks
let rendered = render_blocks(blocks: blocks)
XCTAssertEqual(rendered, expected_render)
@@ -163,7 +163,7 @@ class ReplyTests: XCTestCase {
func testThreadedReply() throws {
let content = "this is some content"
let tags = [["e", "thread_id"], ["e", "reply_id"]]
- let blocks = parse_mentions(content: content, tags: tags).blocks
+ let blocks = parse_note_content(content: content, tags: tags).blocks
let event_refs = interpret_event_refs(blocks: blocks, tags: tags)
XCTAssertEqual(event_refs.count, 2)
@@ -179,7 +179,7 @@ class ReplyTests: XCTestCase {
func testRootReply() throws {
let content = "this is a reply"
let tags = [["e", "thread_id"]]
- let blocks = parse_mentions(content: content, tags: tags).blocks
+ let blocks = parse_note_content(content: content, tags: tags).blocks
let event_refs = interpret_event_refs(blocks: blocks, tags: tags)
XCTAssertEqual(event_refs.count, 1)
@@ -193,14 +193,14 @@ class ReplyTests: XCTestCase {
func testNoReply() throws {
let content = "this is a #[0] reply"
- let blocks = parse_mentions(content: content, tags: []).blocks
+ let blocks = parse_note_content(content: content, tags: []).blocks
let event_refs = interpret_event_refs(blocks: blocks, tags: [])
XCTAssertEqual(event_refs.count, 0)
}
func testParseMention() throws {
- let parsed = parse_mentions(content: "this is #[0] a mention", tags: [["e", "event_id"]]).blocks
+ let parsed = parse_note_content(content: "this is #[0] a mention", tags: [["e", "event_id"]]).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 3)
@@ -375,7 +375,7 @@ class ReplyTests: XCTestCase {
}
func testParseInvalidMention() throws {
- let parsed = parse_mentions(content: "this is #[0] a mention", tags: []).blocks
+ let parsed = parse_note_content(content: "this is #[0] a mention", tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 3)
diff --git a/damusTests/damusTests.swift b/damusTests/damusTests.swift
@@ -71,7 +71,7 @@ class damusTests: XCTestCase {
[my website](https://jb55.com)
"""
- let parsed = parse_mentions(content: md, tags: []).blocks
+ let parsed = parse_note_content(content: md, tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 3)
@@ -81,7 +81,7 @@ class damusTests: XCTestCase {
}
func testParseUrlUpper() {
- let parsed = parse_mentions(content: "a HTTPS://jb55.COM b", tags: []).blocks
+ let parsed = parse_note_content(content: "a HTTPS://jb55.COM b", tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 3)
@@ -116,7 +116,7 @@ class damusTests: XCTestCase {
}
func testParseUrl() {
- let parsed = parse_mentions(content: "a https://jb55.com b", tags: []).blocks
+ let parsed = parse_note_content(content: "a https://jb55.com b", tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 3)
@@ -124,7 +124,7 @@ class damusTests: XCTestCase {
}
func testParseUrlEnd() {
- let parsed = parse_mentions(content: "a https://jb55.com", tags: []).blocks
+ let parsed = parse_note_content(content: "a https://jb55.com", tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 2)
@@ -133,7 +133,7 @@ class damusTests: XCTestCase {
}
func testParseUrlStart() {
- let parsed = parse_mentions(content: "https://jb55.com br", tags: []).blocks
+ let parsed = parse_note_content(content: "https://jb55.com br", tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 2)
@@ -143,7 +143,7 @@ class damusTests: XCTestCase {
func testNoParseUrlWithOnlyWhitespace() {
let testString = "https:// "
- let parsed = parse_mentions(content: testString, tags: []).blocks
+ let parsed = parse_note_content(content: testString, tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed[0].is_text, testString)
@@ -151,14 +151,14 @@ class damusTests: XCTestCase {
func testNoParseUrlTrailingCharacters() {
let testString = "https://foo.bar, "
- let parsed = parse_mentions(content: testString, tags: []).blocks
+ let parsed = parse_note_content(content: testString, tags: []).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed[0].is_url?.absoluteString, "https://foo.bar")
}
func testParseMentionBlank() {
- let parsed = parse_mentions(content: "", tags: [["e", "event_id"]]).blocks
+ let parsed = parse_note_content(content: "", tags: [["e", "event_id"]]).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 0)
@@ -179,7 +179,7 @@ class damusTests: XCTestCase {
}
func testParseMentionOnlyText() {
- let parsed = parse_mentions(content: "there is no mention here", tags: [["e", "event_id"]]).blocks
+ let parsed = parse_note_content(content: "there is no mention here", tags: [["e", "event_id"]]).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed.count, 1)