Move the Block helper type to its own file, collapse the various standalone functions for parsing block data, and refactor consumers to initialize a Block with given data and access its members as needed.

Closes: https://github.com/damus-io/damus/pull/1528
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Grimless
2023-08-21 17:17:21 -04:00
committed by William Casarin
parent dd29e87146
commit a64f898df7
8 changed files with 244 additions and 229 deletions

View File

@@ -130,7 +130,9 @@ struct DMChatView: View, KeyboardReadable {
func send_message() {
let tags = [["p", pubkey.hex()]]
let post_blocks = parse_post_blocks(content: dms.draft)
let content = render_blocks(blocks: post_blocks)
let content = post_blocks
.map(\.asString)
.joined(separator: "")
guard let dm = create_dm(content, to_pk: pubkey, tags: tags, keypair: damus_state.keypair) else {
print("error creating dm")

View File

@@ -445,7 +445,15 @@ func render_blocks(blocks bs: Blocks, profiles: Profiles) -> NoteArtifactsSepara
let blocks = bs.blocks
let one_note_ref = blocks
.filter({ $0.is_note_mention })
.filter({
if case .mention(let mention) = $0,
case .note = mention.ref {
return true
}
else {
return false
}
})
.count == 1
var ind: Int = -1