forked from coracle/flotilla
Set up thunks
This commit is contained in:
+11
-23
@@ -8,6 +8,7 @@ import {
|
||||
editList,
|
||||
makeList,
|
||||
createList,
|
||||
createEvent,
|
||||
} from "@welshman/util"
|
||||
import {pk, signer, repository, INDEXER_RELAYS} from "@app/base"
|
||||
import {
|
||||
@@ -17,8 +18,10 @@ import {
|
||||
loadProfile,
|
||||
loadFollows,
|
||||
loadMutes,
|
||||
getRelaySelectionsByPubkey,
|
||||
loadRelaySelections,
|
||||
publish,
|
||||
makeThunk,
|
||||
publishThunk,
|
||||
ensurePlaintext,
|
||||
} from "@app/state"
|
||||
|
||||
@@ -49,30 +52,15 @@ export const updateList = async (kind: number, modifyTags: ModifyTags) => {
|
||||
const $pk = pk.get()!
|
||||
const $signer = signer.get()!
|
||||
const [prev] = repository.query([{kinds: [kind], authors: [$pk]}])
|
||||
const userRelays = getRelaySelectionsByPubkey().get($pk)
|
||||
const relays = [...INDEXER_RELAYS, ...getWriteRelayUrls(userRelays)]
|
||||
|
||||
// Preserve content instead of use encrypted tags because kind 3 content is used for
|
||||
// relay selections in many places. Content isn't supported for mutes or relays so this is ok
|
||||
const relays = [...INDEXER_RELAYS, ...getWriteRelayUrls(await loadRelaySelections($pk))]
|
||||
const encrypt = (content: string) => $signer.nip44.encrypt($pk, content)
|
||||
// Preserve content if we have it
|
||||
const event = prev
|
||||
? {...prev, tags: modifyTags(prev.tags)}
|
||||
: createEvent(kind, {tags: modifyTags([])})
|
||||
|
||||
let encryptable
|
||||
if (prev) {
|
||||
const content = await ensurePlaintext(prev)
|
||||
const list = readList(asDecryptedEvent(prev, {content}))
|
||||
const publicTags = modifyTags(list.publicTags)
|
||||
|
||||
encryptable = editList({...list, publicTags})
|
||||
} else {
|
||||
const list = makeList({kind})
|
||||
const publicTags = modifyTags(list.publicTags)
|
||||
|
||||
encryptable = createList({...list, publicTags})
|
||||
}
|
||||
|
||||
const template = await encryptable.reconcile(encrypt)
|
||||
const event = await $signer.sign({...template, created_at: now()})
|
||||
|
||||
await publish({event, relays})
|
||||
publishThunk(makeThunk({event, relays}))
|
||||
}
|
||||
|
||||
export const addGroupMemberships = (newTags: string[][]) =>
|
||||
|
||||
Reference in New Issue
Block a user