mirror of
git://jb55.com/damus
synced 2024-09-18 19:23:49 +00:00
util: add separate_images and separate_invoices
This commit is contained in:
parent
40459e247e
commit
d39a3da3b7
@ -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`.
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user