Split up commands and add them to domain modules
This commit is contained in:
@@ -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})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user