33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
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'
|
|
|
|
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: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
|
load({...request, filters: [{kinds: [MUTES], authors: [pubkey]}]}),
|
|
})
|