Use kind constants for gift wraps

This commit is contained in:
Jon Staab 2024-06-06 10:16:48 -07:00
parent bc372eedd7
commit e1fb6eee67
6 changed files with 14 additions and 35 deletions

View File

@ -13,7 +13,6 @@ import {
loadDeletes,
loadHandlers,
loadPubkeyUserData,
loadGiftWrap,
loadAllMessages,
loadGroupMessages,
loadNotifications,
@ -96,7 +95,6 @@ export const loadUserData = async () => {
// Load anything they might need to be notified about, in serial to avoid
// clogging up higher priority requests
await loadSeen()
await loadGiftWrap()
await loadAllMessages()
await loadGroupMessages()
await loadNotifications()

View File

@ -41,16 +41,12 @@
document.title = "Groups"
onMount(() => {
const {admins, recipients, relays, since} = getGroupReqInfo()
const {admins} = getGroupReqInfo()
const scroller = createScroller(loadMore, {element})
updateCurrentSession(assoc("groups_last_synced", now()))
load({
relays,
skipCache: true,
filters: [{kinds: giftWrapKinds, "#p": recipients, since}],
})
loadGroupMessages()
load({
skipCache: true,

View File

@ -302,7 +302,7 @@ export const wrapWithFallback = async (template, {author = null, wrap}) => {
author,
wrap: {
...wrap,
kind: 1060,
kind: WRAP_NIP04,
algo: "nip04",
},
}),

View File

@ -28,6 +28,8 @@ import {
getIdFilters,
isGroupAddress,
isSignedEvent,
WRAP,
WRAP_NIP04,
EPOCH,
LABEL,
DELETE,
@ -493,29 +495,9 @@ export const loadSeen = () =>
filters: [addSinceToFilter({kinds: [READ_RECEIPT], authors: [pubkey.get()]})],
})
export const loadGiftWrap = () => {
const kinds = []
if (nip44.get().isEnabled()) {
kinds.push(1059)
}
if (nip04.get().isEnabled()) {
kinds.push(1060)
}
if (kinds.length > 0) {
return load({
skipCache: true,
relays: hints.User().getUrls(),
filters: [addSinceToFilter({kinds, authors: [pubkey.get()]})],
})
}
}
export const loadAllMessages = ({reload = false} = {}) => {
let filters = [
{kinds: [1059], "#p": [pubkey.get()]},
{kinds: [WRAP, WRAP_NIP04], "#p": [pubkey.get()]},
{kinds: [4], authors: [pubkey.get()]},
{kinds: [4], "#p": [pubkey.get()]},
]
@ -543,7 +525,7 @@ export const listenForMessages = (pubkeys: string[]) => {
skipCache: true,
relays: hints.Messages(pubkeys).getUrls(),
filters: [
addSinceToFilter({kinds: [1059], "#p": [pubkey.get()]}, seconds(7, "day")),
addSinceToFilter({kinds: [WRAP], "#p": [pubkey.get()]}, seconds(7, "day")),
addSinceToFilter({kinds: [4], authors: allPubkeys}),
addSinceToFilter({kinds: [4], "#p": allPubkeys}),
],

View File

@ -39,6 +39,8 @@ import {
indexBy,
} from "@welshman/lib"
import {
WRAP,
WRAP_NIP04,
READ_RECEIPT,
NAMED_BOOKMARKS,
HANDLER_RECOMMENDATION,
@ -308,8 +310,8 @@ export const ensureUnwrapped = async (event: TrustedEvent) => {
if (session) {
const canDecrypt =
(event.kind === 1059 && getNip44(session).isEnabled()) ||
(event.kind === 1060 && getNip04(session).isEnabled())
(event.kind === WRAP && getNip44(session).isEnabled()) ||
(event.kind === WRAP_NIP04 && getNip04(session).isEnabled())
if (canDecrypt) {
const rumor = await getNip59(session).unwrap(event, session.privkey)

View File

@ -1,4 +1,5 @@
import type {UnsignedEvent} from "nostr-tools"
import {WRAP, WRAP_NIP04} from '@welshman/util'
import {getPublicKey} from "src/util/nostr"
import {tryJson} from "src/util/misc"
import logger from "src/util/logger"
@ -18,7 +19,7 @@ export const seal = (content, pubkey) => ({
pubkey,
})
export const wrap = (content, pubkey, recipient, kind = 1059, tags = []) => ({
export const wrap = (content, pubkey, recipient, kind = WRAP, tags = []) => ({
kind,
created_at: now(5),
tags: tags.concat([["p", recipient]]),
@ -31,7 +32,7 @@ export type WrapperParams = {
wrap?: {
author: string
recipient: string
kind?: 1059 | 1060
kind?: WRAP | WRAP_NIP04
algo?: "nip04" | "nip44"
tags?: string[][]
}