Split up commands and add them to domain modules

This commit is contained in:
Jon Staab
2026-06-16 16:34:43 -07:00
parent 163d2dc355
commit abb9f20747
21 changed files with 526 additions and 496 deletions
+28 -3
View File
@@ -1,7 +1,16 @@
import {PINS, asDecryptedEvent, readList} from "@welshman/util"
import {
PINS,
asDecryptedEvent,
readList,
makeList,
addToListPublicly,
removeFromList,
} from "@welshman/util"
import type {TrustedEvent} from "@welshman/util"
import {RepositoryCollection} from "./repositoryCollection.js"
import {RelayLists} from "./relayLists.js"
import {Network} from "./network.js"
import {Thunks} from "./thunk.js"
import {User} from "./user.js"
import type {IClient} from "./client.js"
/**
@@ -18,6 +27,22 @@ export class PinLists extends RepositoryCollection<ReturnType<typeof readList>>
}
fetch(pubkey: string, relayHints: string[] = []) {
return this.ctx.use(RelayLists).loadUsingOutbox(pubkey, {kinds: [PINS]}, relayHints)
return this.ctx.use(Network).loadUsingOutbox(pubkey, {kinds: [PINS]}, relayHints)
}
pin = async (tag: string[]) => {
const user = User.require(this.ctx)
const list = (await this.forceLoad(user.pubkey)) || makeList({kind: PINS})
const event = await addToListPublicly(list, tag).reconcile(user.nip44EncryptToSelf)
return this.ctx.use(Thunks).publishToOutbox({event})
}
unpin = async (value: string) => {
const user = User.require(this.ctx)
const list = (await this.forceLoad(user.pubkey)) || makeList({kind: PINS})
const event = await removeFromList(list, value).reconcile(user.nip44EncryptToSelf)
return this.ctx.use(Thunks).publishToOutbox({event})
}
}