Merge branch 'quote-uri' into 'main'

Add quote URI to the event content

See merge request soapbox-pub/ditto!335
This commit is contained in:
Alex Gleason 2024-05-30 17:09:43 +00:00
commit 594be870e1
2 changed files with 6 additions and 5 deletions

View File

@ -21,7 +21,7 @@ import { addTag, deleteTag } from '@/utils/tags.ts';
import { asyncReplaceAll } from '@/utils/text.ts'; import { asyncReplaceAll } from '@/utils/text.ts';
const createStatusSchema = z.object({ 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(), language: z.string().refine(ISO6391.validate).nullish(),
media_ids: z.string().array().nullish(), media_ids: z.string().array().nullish(),
poll: z.object({ poll: z.object({
@ -36,7 +36,7 @@ const createStatusSchema = z.object({
status: z.string().nullish(), status: z.string().nullish(),
to: z.string().array().nullish(), to: z.string().array().nullish(),
visibility: z.enum(['public', 'unlisted', 'private', 'direct']).nullish(), visibility: z.enum(['public', 'unlisted', 'private', 'direct']).nullish(),
quote_id: z.string().nullish(), quote_id: n.id().nullish(),
}).refine( }).refine(
(data) => Boolean(data.status || data.media_ids?.length), (data) => Boolean(data.status || data.media_ids?.length),
{ message: 'Status must contain text or media.' }, { message: 'Status must contain text or media.' },
@ -155,11 +155,12 @@ const createStatusController: AppController = async (c) => {
.map(({ data }) => data.find(([name]) => name === 'url')?.[1]) .map(({ data }) => data.find(([name]) => name === 'url')?.[1])
.filter((url): url is string => Boolean(url)); .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({ const event = await createEvent({
kind: 1, kind: 1,
content: content + mediaCompat, content: content + quoteCompat + mediaCompat,
tags, tags,
}, c); }, c);

View File

@ -46,7 +46,7 @@ interface ParsedNoteContent {
/** Convert Nostr content to Mastodon API HTML. Also return parsed data. */ /** Convert Nostr content to Mastodon API HTML. Also return parsed data. */
function parseNoteContent(content: string): ParsedNoteContent { function parseNoteContent(content: string): ParsedNoteContent {
// Parsing twice is ineffecient, but I don't know how to do only once. // 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 links = linkify.find(content).filter(isLinkURL);
const firstUrl = links.find(isNonMediaLink)?.href; const firstUrl = links.find(isNonMediaLink)?.href;