From 86b3a5159023eb286afa68f9ddc8103bd367cb99 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 30 May 2024 11:55:03 -0500 Subject: [PATCH 1/3] Add quote URI to the event content --- src/controllers/api/statuses.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 4185b96..0e4bd3a 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -21,7 +21,7 @@ import { addTag, deleteTag } from '@/utils/tags.ts'; import { asyncReplaceAll } from '@/utils/text.ts'; const createStatusSchema = z.object({ - in_reply_to_id: z.string().regex(/[0-9a-f]{64}/).nullish(), + in_reply_to_id: n.id().nullish(), language: z.string().refine(ISO6391.validate).nullish(), media_ids: z.string().array().nullish(), poll: z.object({ @@ -36,7 +36,7 @@ const createStatusSchema = z.object({ status: z.string().nullish(), to: z.string().array().nullish(), visibility: z.enum(['public', 'unlisted', 'private', 'direct']).nullish(), - quote_id: z.string().nullish(), + quote_id: n.id().nullish(), }).refine( (data) => Boolean(data.status || data.media_ids?.length), { message: 'Status must contain text or media.' }, @@ -155,11 +155,12 @@ const createStatusController: AppController = async (c) => { .map(({ data }) => data.find(([name]) => name === 'url')?.[1]) .filter((url): url is string => Boolean(url)); + const quoteCompat = data.quote_id ? `\n\n${nip19.noteEncode(data.quote_id)}` : ''; const mediaCompat: string = mediaUrls.length ? ['', '', ...mediaUrls].join('\n') : ''; const event = await createEvent({ kind: 1, - content: content + mediaCompat, + content: content + quoteCompat + mediaCompat, tags, }, c); From c0123df79ae73bd9e5d2f1abec1b370be31d2025 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 30 May 2024 12:03:01 -0500 Subject: [PATCH 2/3] Strip newlines from end of status --- src/controllers/api/statuses.ts | 2 +- src/utils/note.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 0e4bd3a..49682dc 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -155,7 +155,7 @@ const createStatusController: AppController = async (c) => { .map(({ data }) => data.find(([name]) => name === 'url')?.[1]) .filter((url): url is string => Boolean(url)); - const quoteCompat = data.quote_id ? `\n\n${nip19.noteEncode(data.quote_id)}` : ''; + const quoteCompat = data.quote_id ? `\n\nnostr:${nip19.noteEncode(data.quote_id)}` : ''; const mediaCompat: string = mediaUrls.length ? ['', '', ...mediaUrls].join('\n') : ''; const event = await createEvent({ diff --git a/src/utils/note.ts b/src/utils/note.ts index 0d1e3b2..c10e3e9 100644 --- a/src/utils/note.ts +++ b/src/utils/note.ts @@ -46,7 +46,7 @@ interface ParsedNoteContent { /** Convert Nostr content to Mastodon API HTML. Also return parsed data. */ function parseNoteContent(content: string): ParsedNoteContent { // Parsing twice is ineffecient, but I don't know how to do only once. - const html = linkifyStr(content, linkifyOpts); + const html = linkifyStr(content, linkifyOpts).replace(/\n+$/, ''); const links = linkify.find(content).filter(isLinkURL); const firstUrl = links.find(isNonMediaLink)?.href; From e8ca21acdea83b69ed687a13473504b23675e592 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 30 May 2024 12:05:25 -0500 Subject: [PATCH 3/3] mediaCompat consistency --- src/controllers/api/statuses.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 49682dc..ad21381 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -156,7 +156,7 @@ const createStatusController: AppController = async (c) => { .filter((url): url is string => Boolean(url)); const quoteCompat = data.quote_id ? `\n\nnostr:${nip19.noteEncode(data.quote_id)}` : ''; - const mediaCompat: string = mediaUrls.length ? ['', '', ...mediaUrls].join('\n') : ''; + const mediaCompat = mediaUrls.length ? `\n\n${mediaUrls.join('\n')}` : ''; const event = await createEvent({ kind: 1,