diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 4185b96..ad21381 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 mediaCompat: string = mediaUrls.length ? ['', '', ...mediaUrls].join('\n') : ''; + const quoteCompat = data.quote_id ? `\n\nnostr:${nip19.noteEncode(data.quote_id)}` : ''; + const mediaCompat = mediaUrls.length ? `\n\n${mediaUrls.join('\n')}` : ''; const event = await createEvent({ kind: 1, - content: content + mediaCompat, + content: content + quoteCompat + mediaCompat, tags, }, c); 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;