Add app package

This commit is contained in:
Jon Staab
2024-08-30 09:46:47 -07:00
parent e462ec2ada
commit 6e1ad713c3
34 changed files with 1193 additions and 48 deletions
+40
View File
@@ -0,0 +1,40 @@
import {MUTES, asDecryptedEvent, readList} from '@welshman/util'
import {type TrustedEvent, type PublishedList} from '@welshman/util'
import {type SubscribeRequest} from "@welshman/net"
import {deriveEventsMapped, withGetter} from '@welshman/store'
import {repository, load} from './core'
import {collection} from './collection'
import {ensurePlaintext} from './plaintext'
import {getWriteRelayUrls, loadRelaySelections} from './relaySelections'
export const mutes = withGetter(
deriveEventsMapped<PublishedList>(repository, {
filters: [{kinds: [MUTES]}],
itemToEvent: item => item.event,
eventToItem: async (event: TrustedEvent) =>
readList(
asDecryptedEvent(event, {
content: await ensurePlaintext(event),
}),
),
})
)
export const {
indexStore: mutesByPubkey,
deriveItem: deriveMutes,
loadItem: loadMutes,
} = collection({
name: "mutes",
store: mutes,
getKey: mute => mute.event.pubkey,
load: async (pubkey: string, hints = [], request: Partial<SubscribeRequest> = {}) => {
const relays = getWriteRelayUrls(await loadRelaySelections(pubkey, hints))
return load({
...request,
relays: [...relays, ...hints],
filters: [{kinds: [MUTES], authors: [pubkey]}],
})
},
})