notes: count words in notes during artifact parsing

This commit is contained in:
William Casarin
2023-06-01 11:45:04 -07:00
parent fe077fa5c2
commit 6ca9bda01e
6 changed files with 28 additions and 13 deletions

View File

@@ -1170,7 +1170,7 @@ func process_local_notification(damus_state: DamusState, event ev: NostrEvent) {
}
if type == .text && damus_state.settings.mention_notification {
let blocks = ev.blocks(damus_state.keypair.privkey)
let blocks = ev.blocks(damus_state.keypair.privkey).blocks
for case .mention(let mention) in blocks where mention.ref.ref_id == damus_state.keypair.pubkey {
let content = NSAttributedString(render_note_content(ev: ev, profiles: damus_state.profiles, privkey: damus_state.keypair.privkey).content.attributed).string

View File

@@ -150,7 +150,12 @@ func render_blocks(blocks: [Block]) -> String {
}
}
func parse_mentions(content: String, tags: [[String]]) -> [Block] {
struct Blocks {
let words: Int
let blocks: [Block]
}
func parse_mentions(content: String, tags: [[String]]) -> Blocks {
var out: [Block] = []
var bs = note_blocks()
@@ -174,9 +179,10 @@ func parse_mentions(content: String, tags: [[String]]) -> [Block] {
i += 1
}
let words = Int(bs.words)
blocks_free(&bs)
return out
return Blocks(words: words, blocks: out)
}
func strblock_to_string(_ s: str_block_t) -> String? {