@@ -1,7 +1,7 @@
|
||||
import {get} from "svelte/store"
|
||||
import {ctx} from "@welshman/lib"
|
||||
import {addToListPublicly, removeFromList, makeList, FOLLOWS, MUTES} from "@welshman/util"
|
||||
import {userFollows, userMutes} from "./user.js"
|
||||
import {addToListPublicly, removeFromList, makeList, FOLLOWS, MUTES, PINS} from "@welshman/util"
|
||||
import {userFollows, userMutes, userPins} from "./user.js"
|
||||
import {nip44EncryptToSelf} from "./session.js"
|
||||
import {publishThunk} from "./thunk.js"
|
||||
|
||||
@@ -32,3 +32,17 @@ export const mute = async (tag: string[]) => {
|
||||
|
||||
return publishThunk({event, relays: ctx.app.router.FromUser().getUrls()})
|
||||
}
|
||||
|
||||
export const unpin = async (value: string) => {
|
||||
const list = get(userPins) || makeList({kind: PINS})
|
||||
const event = await removeFromList(list, value).reconcile(nip44EncryptToSelf)
|
||||
|
||||
return publishThunk({event, relays: ctx.app.router.FromUser().getUrls()})
|
||||
}
|
||||
|
||||
export const pin = async (tag: string[]) => {
|
||||
const list = get(userPins) || makeList({kind: PINS})
|
||||
const event = await addToListPublicly(list, tag).reconcile(nip44EncryptToSelf)
|
||||
|
||||
return publishThunk({event, relays: ctx.app.router.FromUser().getUrls()})
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ export * from "./handles.js"
|
||||
export * from "./mutes.js"
|
||||
export * from "./plaintext.js"
|
||||
export * from "./profiles.js"
|
||||
export * from "./pins.js"
|
||||
export * from "./relays.js"
|
||||
export * from "./relaySelections.js"
|
||||
export * from "./router.js"
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import {PINS, asDecryptedEvent, readList} from "@welshman/util"
|
||||
import {type TrustedEvent, type PublishedList} from "@welshman/util"
|
||||
import {type SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
import {deriveEventsMapped} from "@welshman/store"
|
||||
import {repository} from "./core.js"
|
||||
import {load} from "./subscribe.js"
|
||||
import {collection} from "./collection.js"
|
||||
import {loadRelaySelections} from "./relaySelections.js"
|
||||
|
||||
export const pins = deriveEventsMapped<PublishedList>(repository, {
|
||||
filters: [{kinds: [PINS]}],
|
||||
itemToEvent: item => item.event,
|
||||
eventToItem: (event: TrustedEvent) => readList(asDecryptedEvent(event)),
|
||||
})
|
||||
|
||||
export const {
|
||||
indexStore: pinsByPubkey,
|
||||
deriveItem: derivePins,
|
||||
loadItem: loadPins,
|
||||
} = collection({
|
||||
name: "pins",
|
||||
store: pins,
|
||||
getKey: pins => pins.event.pubkey,
|
||||
load: async (pubkey: string, request: Partial<SubscribeRequestWithHandlers> = {}) => {
|
||||
await loadRelaySelections(pubkey, request)
|
||||
await load({...request, filters: [{kinds: [PINS], authors: [pubkey]}]})
|
||||
},
|
||||
})
|
||||
@@ -2,6 +2,7 @@ import {derived} from "svelte/store"
|
||||
import {pubkey} from "./session.js"
|
||||
import {profilesByPubkey, loadProfile} from "./profiles.js"
|
||||
import {followsByPubkey, loadFollows} from "./follows.js"
|
||||
import {loadPins, pinsByPubkey} from "./pins.js"
|
||||
import {mutesByPubkey, loadMutes} from "./mutes.js"
|
||||
import {
|
||||
relaySelectionsByPubkey,
|
||||
@@ -35,6 +36,13 @@ export const userMutes = derived([mutesByPubkey, pubkey], ([$mutesByPubkey, $pub
|
||||
return $mutesByPubkey.get($pubkey)
|
||||
})
|
||||
|
||||
export const userPins = derived([pinsByPubkey, pubkey], ([$pinsByPubkey, $pubkey]) => {
|
||||
if (!$pubkey) return undefined
|
||||
|
||||
loadPins($pubkey)
|
||||
return $pinsByPubkey.get($pubkey)
|
||||
})
|
||||
|
||||
export const userRelaySelections = derived(
|
||||
[relaySelectionsByPubkey, pubkey],
|
||||
([$relaySelectionsByPubkey, $pubkey]) => {
|
||||
|
||||
Reference in New Issue
Block a user