This commit is contained in:
Jon Staab
2024-08-26 14:43:43 -07:00
parent 644c32dd09
commit 88318e9753
36 changed files with 370 additions and 311 deletions
+18 -16
View File
@@ -2,21 +2,15 @@ import {uniqBy, uniq, now, choice} from "@welshman/lib"
import {
GROUPS,
GROUP_JOIN,
asDecryptedEvent,
getGroupTags,
getRelayTagValues,
readList,
editList,
makeList,
createList,
createEvent,
displayProfile,
} from "@welshman/util"
import {PublishStatus} from "@welshman/net"
import {pk, signer, repository, INDEXER_RELAYS} from "@app/base"
import {pk, repository, INDEXER_RELAYS} from "@app/base"
import {
loadOne,
subscribe,
getWriteRelayUrls,
loadGroup,
loadGroupMembership,
@@ -27,7 +21,6 @@ import {
loadRelaySelections,
makeThunk,
publishThunk,
ensurePlaintext,
getProfilesByPubkey,
} from "@app/state"
@@ -48,11 +41,18 @@ export const getPubkeyPetname = (pubkey: string) => {
return display
}
export const makeMention = (pubkey: string, hints?: string[]) =>
["p", pubkey, choice(hints || getPubkeyHints(pubkey)), getPubkeyPetname(pubkey)]
export const makeMention = (pubkey: string, hints?: string[]) => [
"p",
pubkey,
choice(hints || getPubkeyHints(pubkey)),
getPubkeyPetname(pubkey),
]
export const makeIMeta = (url: string, data: Record<string, string>) =>
["imeta", `url ${url}`, ...Object.entries(data).map(([k, v]) => [k, v].join(' '))]
export const makeIMeta = (url: string, data: Record<string, string>) => [
"imeta",
`url ${url}`,
...Object.entries(data).map(([k, v]) => [k, v].join(" ")),
]
// Loaders
@@ -83,7 +83,6 @@ export type ModifyTags = (tags: string[][]) => string[][]
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 relays = getWriteRelayUrls(getRelaySelectionsByPubkey().get($pk))
@@ -103,15 +102,18 @@ export const removeGroupMemberships = (noms: string[]) =>
export const sendJoinRequest = async (nom: string, url: string): Promise<[boolean, string]> => {
const relays = [url]
const filters = [{kinds: [9000], '#h': [nom], '#p': [pk.get()!], since: now() - 30}]
const filters = [{kinds: [9000], "#h": [nom], "#p": [pk.get()!], since: now() - 30}]
const event = createEvent(GROUP_JOIN, {tags: [["h", nom]]})
const statusData = await publishThunk(makeThunk({event, relays}))
const {status, message} = statusData[url]
if (message.includes('already a member')) return [true, ""]
if (message.includes("already a member")) return [true, ""]
if (status !== PublishStatus.Success) return [false, message]
if (await loadOne({filters, relays})) return [true, ""]
return [false, "Your request was not automatically approved, but may be approved manually later. Please try again later or contact the group admin."]
return [
false,
"Your request was not automatically approved, but may be approved manually later. Please try again later or contact the group admin.",
]
}