commit d39a3da3b728aa06ac96a2dec2f071050fa6e3f1
parent 40459e247ec5c9890629b87eb60960cf4db98a10
Author: Suhail Saqan <suhail.saqan@gmail.com>
Date: Thu, 1 Jun 2023 14:49:56 -0500
util: add separate_images and separate_invoices
Diffstat:
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift
@@ -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`.
diff --git a/damus/Views/FollowingView.swift b/damus/Views/FollowingView.swift
@@ -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)
}
}
*/