add PIN kind utilities

This commit is contained in:
Ticruz
2025-01-16 17:47:28 +01:00
parent 3c100a8ce6
commit b334da9389
4 changed files with 53 additions and 2 deletions
+16 -2
View File
@@ -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()})
}