Browse Source

make sure kind 1111 has complete tags

imwald
Silberengel 1 month ago
parent
commit
48aa02226c
  1. 27
      src/lib/draft-event.ts
  2. 7
      src/lib/rss-article.ts

27
src/lib/draft-event.ts

@ -24,7 +24,7 @@ import {
isProtectedEvent, isProtectedEvent,
isReplaceableEvent isReplaceableEvent
} from './event' } from './event'
import { canonicalizeRssArticleUrl } from '@/lib/rss-article' import { canonicalizeRssArticleUrl, NIP22_URL_SCOPE_KIND } from '@/lib/rss-article'
import { cleanUrl } from '@/lib/url' import { cleanUrl } from '@/lib/url'
import { randomString } from './random' import { randomString } from './random'
import { generateBech32IdFromETag, tagNameEquals } from './tag' import { generateBech32IdFromETag, tagNameEquals } from './tag'
@ -247,7 +247,9 @@ export async function createCommentDraftEvent(
if (isRssArticleThreadRoot) { if (isRssArticleThreadRoot) {
if (rssArticleUrl) { if (rssArticleUrl) {
const u = canonicalizeHttpUrlForITags(rssArticleUrl) const u = canonicalizeHttpUrlForITags(rssArticleUrl)
tags.push(buildITag(u, false), buildITag(u, true)) tags.push(buildITag(u, true), buildITag(u, false))
const scopeKind = rootKind ?? NIP22_URL_SCOPE_KIND
tags.push(buildKTag(scopeKind, true), buildKTag(scopeKind))
} }
} else { } else {
if (rootCoordinateTag) { if (rootCoordinateTag) {
@ -263,7 +265,7 @@ export async function createCommentDraftEvent(
} }
if (rootUrl) { if (rootUrl) {
const u = canonicalizeHttpUrlForITags(rootUrl) const u = canonicalizeHttpUrlForITags(rootUrl)
tags.push(buildITag(u, false), buildITag(u, true)) tags.push(buildITag(u, true), buildITag(u, false))
} }
tags.push( tags.push(
...[ ...[
@ -1106,7 +1108,7 @@ async function extractCommentMentions(content: string, parentEvent: Event) {
quoteReplaceableCoordinates, quoteReplaceableCoordinates,
rootEventId: undefined, rootEventId: undefined,
rootCoordinateTag: undefined, rootCoordinateTag: undefined,
rootKind: undefined, rootKind: url ? NIP22_URL_SCOPE_KIND : undefined,
rootPubkey: undefined, rootPubkey: undefined,
rootUrl: url rootUrl: url
} }
@ -1119,12 +1121,21 @@ async function extractCommentMentions(content: string, parentEvent: Event) {
? buildATag(parentEvent, true) ? buildATag(parentEvent, true)
: undefined : undefined
const rootEventId = isComment ? parentEvent.tags.find(tagNameEquals('E'))?.[1] : parentEvent.id const rootEventId = isComment ? parentEvent.tags.find(tagNameEquals('E'))?.[1] : parentEvent.id
const rootKind = isComment ? parentEvent.tags.find(tagNameEquals('K'))?.[1] : parentEvent.kind let rootKind = isComment ? parentEvent.tags.find(tagNameEquals('K'))?.[1] : parentEvent.kind
const rootPubkey = isComment ? parentEvent.tags.find(tagNameEquals('P'))?.[1] : parentEvent.pubkey const rootPubkey = isComment ? parentEvent.tags.find(tagNameEquals('P'))?.[1] : parentEvent.pubkey
const rootUrl = isComment const rootUrl = isComment
? parentEvent.tags.find((t) => t[0] === 'I' || t[0] === 'i')?.[1] ? parentEvent.tags.find((t) => t[0] === 'I' || t[0] === 'i')?.[1]
: undefined : undefined
if (
isComment &&
rootUrl &&
(rootKind === undefined || rootKind === '') &&
(rootUrl.startsWith('http://') || rootUrl.startsWith('https://'))
) {
rootKind = NIP22_URL_SCOPE_KIND
}
return { return {
quoteEventHexIds, quoteEventHexIds,
quoteReplaceableCoordinates, quoteReplaceableCoordinates,
@ -1556,7 +1567,9 @@ export async function createVoiceCommentDraftEvent(
if (isRssArticleThreadRootVoice) { if (isRssArticleThreadRootVoice) {
if (rssArticleUrlVoice) { if (rssArticleUrlVoice) {
const u = canonicalizeHttpUrlForITags(rssArticleUrlVoice) const u = canonicalizeHttpUrlForITags(rssArticleUrlVoice)
tags.push(buildITag(u, false), buildITag(u, true)) tags.push(buildITag(u, true), buildITag(u, false))
const scopeKind = rootKind ?? NIP22_URL_SCOPE_KIND
tags.push(buildKTag(scopeKind, true), buildKTag(scopeKind))
} }
} else { } else {
if (rootCoordinateTag) { if (rootCoordinateTag) {
@ -1572,7 +1585,7 @@ export async function createVoiceCommentDraftEvent(
} }
if (rootUrl) { if (rootUrl) {
const u = canonicalizeHttpUrlForITags(rootUrl) const u = canonicalizeHttpUrlForITags(rootUrl)
tags.push(buildITag(u, false), buildITag(u, true)) tags.push(buildITag(u, true), buildITag(u, false))
} }
tags.push( tags.push(
...[ ...[

7
src/lib/rss-article.ts

@ -1,5 +1,8 @@
import { ExtendedKind } from '@/constants' import { ExtendedKind } from '@/constants'
import { cleanUrl } from '@/lib/url' import { cleanUrl } from '@/lib/url'
/** NIP-22: `K` / `k` value for http(s) URL comment scopes (web pages, articles). */
export const NIP22_URL_SCOPE_KIND = 'web'
import { bytesToHex } from '@noble/hashes/utils' import { bytesToHex } from '@noble/hashes/utils'
import { sha256 } from '@noble/hashes/sha256' import { sha256 } from '@noble/hashes/sha256'
import type { Event } from 'nostr-tools' import type { Event } from 'nostr-tools'
@ -62,8 +65,10 @@ export function createRssThreadRootEvent(articleUrl: string): Event {
created_at: 0, created_at: 0,
kind: ExtendedKind.RSS_THREAD_ROOT, kind: ExtendedKind.RSS_THREAD_ROOT,
tags: [ tags: [
['I', canonical],
['i', canonical], ['i', canonical],
['I', canonical] ['K', NIP22_URL_SCOPE_KIND],
['k', NIP22_URL_SCOPE_KIND]
], ],
content: '', content: '',
sig: '' sig: ''

Loading…
Cancel
Save