util: add separate_images and separate_invoices
This commit is contained in:
committed by
William Casarin
parent
40459e247e
commit
d39a3da3b7
@@ -949,6 +949,29 @@ func first_eref_mention(ev: NostrEvent, keypair: Keypair) -> Mention<NoteId>? {
|
|||||||
return nil
|
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.
|
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`.
|
If the known kind is not a `NostrKind.like`, it will return `nil`.
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ struct FollowingView: View {
|
|||||||
/*
|
/*
|
||||||
struct FollowingView_Previews: PreviewProvider {
|
struct FollowingView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
FollowingView(contact: <#NostrEvent#>, damus_state: <#DamusState#>)
|
FollowingView(damus_state: test_damus_state, following: test_following_model)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user