Load user data before updating, prefer newer events in repository over old ones with the same created_at, add list update utils

This commit is contained in:
Jon Staab
2025-08-01 13:09:50 -07:00
parent bd67f2763d
commit 1f5f869f7c
9 changed files with 119 additions and 11 deletions
+2 -2
View File
@@ -39,13 +39,13 @@ export class Encryptable<T extends EventTemplate> {
*/
async reconcile(encrypt: Encrypt) {
const encryptContent = () => {
if (!this.updates.content) return null
if (!this.updates.content) return undefined
return encrypt(this.updates.content)
}
const encryptTags = () => {
if (!this.updates.tags) return null
if (!this.updates.tags) return undefined
return Promise.all(
this.updates.tags.map(async tag => {
+19
View File
@@ -89,6 +89,25 @@ export const addToListPrivately = (list: List, ...tags: string[][]) => {
})
}
export const updateList = (
list: List,
{publicTags, privateTags}: {publicTags?: string[][]; privateTags?: string[][]},
) => {
const template = {
kind: list.kind,
content: list.event?.content || "",
tags: publicTags || list.publicTags,
}
const updates: EncryptableUpdates = {}
if (privateTags) {
updates.content = JSON.stringify(privateTags)
}
return new Encryptable(template, updates)
}
export const getRelaysFromList = (list?: List, mode?: RelayMode): string[] => {
let tags = getRelayTags(getListTags(list))
+3 -1
View File
@@ -119,4 +119,6 @@ export const uniqTags = (tags: string[][]) => uniqBy(t => t.slice(0, 2).join(":"
export const tagsFromIMeta = (imeta: string[]) => imeta.map((m: string) => m.split(" "))
export const tagger = (name: string) => (value: string) => [name, value]
export const tagger =
(name: string) =>
(value: string, ...args: unknown[]) => [name, value]