1
0
mirror of git://jb55.com/damus synced 2024-09-16 02:03:45 +00:00

util: add separate_images and separate_invoices

This commit is contained in:
Suhail Saqan 2023-06-01 14:49:56 -05:00 committed by William Casarin
parent 40459e247e
commit d39a3da3b7
2 changed files with 24 additions and 1 deletions

View File

@ -949,6 +949,29 @@ func first_eref_mention(ev: NostrEvent, keypair: Keypair) -> Mention<NoteId>? {
return nil
}
func separate_images(ev: NostrEvent, keypair: Keypair) -> [MediaUrl]? {
let urlBlocks: [URL] = ev.blocks(keypair).blocks.reduce(into: []) { urls, block in
guard case .url(let url) = block else {
return
}
if classify_url(url).is_img != nil {
urls.append(url)
}
}
let mediaUrls = urlBlocks.map { MediaUrl.image($0) }
return mediaUrls.isEmpty ? nil : mediaUrls
}
func separate_invoices(ev: NostrEvent, keypair: Keypair) -> [Invoice]? {
let invoiceBlocks: [Invoice] = ev.blocks(keypair).blocks.reduce(into: []) { invoices, block in
guard case .invoice(let invoice) = block else {
return
}
invoices.append(invoice)
}
return invoiceBlocks.isEmpty ? nil : invoiceBlocks
}
/**
Transforms a `NostrEvent` of known kind `NostrKind.like`to a human-readable emoji.
If the known kind is not a `NostrKind.like`, it will return `nil`.

View File

@ -93,7 +93,7 @@ struct FollowingView: View {
/*
struct FollowingView_Previews: PreviewProvider {
static var previews: some View {
FollowingView(contact: <#NostrEvent#>, damus_state: <#DamusState#>)
FollowingView(damus_state: test_damus_state, following: test_following_model)
}
}
*/