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/1496
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 6ab893a617
commit 286ae68fd6
8 changed files with 244 additions and 229 deletions

View File

@@ -415,7 +415,15 @@ extension NdbNote {
// Rely on Apple's NLLanguageRecognizer to tell us which language it thinks the note is in
// and filter on only the text portions of the content as URLs and hashtags confuse the language recognizer.
let originalBlocks = self.blocks(privkey).blocks
let originalOnlyText = originalBlocks.compactMap { $0.is_text }.joined(separator: " ")
let originalOnlyText = originalBlocks.compactMap {
if case .text(let txt) = $0 {
return txt
}
else {
return nil
}
}
.joined(separator: " ")
// Only accept language recognition hypothesis if there's at least a 50% probability that it's accurate.
let languageRecognizer = NLLanguageRecognizer()