Insert media URL into text
This commit is contained in:
parent
91ea4577f1
commit
b1b341d3b8
|
@ -91,21 +91,14 @@ const createStatusController: AppController = async (c) => {
|
||||||
tags.push(['subject', data.spoiler_text]);
|
tags.push(['subject', data.spoiler_text]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const viewerPubkey = await c.get('signer')?.getPublicKey();
|
const media = data.media_ids?.length ? await getUnattachedMediaByIds(kysely, data.media_ids) : [];
|
||||||
|
|
||||||
if (data.media_ids?.length) {
|
const imeta: string[][] = media.map(({ data }) => {
|
||||||
const media = await getUnattachedMediaByIds(kysely, data.media_ids)
|
const values: string[] = data.map((tag) => tag.join(' '));
|
||||||
.then((media) => media.filter(({ pubkey }) => pubkey === viewerPubkey))
|
|
||||||
.then((media) =>
|
|
||||||
media.map(({ data }) => {
|
|
||||||
const tags: string[][] = JSON.parse(data);
|
|
||||||
const values: string[] = tags.map((tag) => tag.join(' '));
|
|
||||||
return ['imeta', ...values];
|
return ['imeta', ...values];
|
||||||
})
|
});
|
||||||
);
|
|
||||||
|
|
||||||
tags.push(...media);
|
tags.push(...imeta);
|
||||||
}
|
|
||||||
|
|
||||||
const pubkeys = new Set<string>();
|
const pubkeys = new Set<string>();
|
||||||
|
|
||||||
|
@ -137,9 +130,15 @@ const createStatusController: AppController = async (c) => {
|
||||||
tags.push(['t', match[1]]);
|
tags.push(['t', match[1]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mediaUrls: string[] = media
|
||||||
|
.map(({ data }) => data.find(([name]) => name === 'url')?.[1])
|
||||||
|
.filter((url): url is string => Boolean(url));
|
||||||
|
|
||||||
|
const mediaCompat: string = mediaUrls.length ? ['', '', ...mediaUrls].join('\n') : '';
|
||||||
|
|
||||||
const event = await createEvent({
|
const event = await createEvent({
|
||||||
kind: 1,
|
kind: 1,
|
||||||
content,
|
content: content + mediaCompat,
|
||||||
tags,
|
tags,
|
||||||
}, c);
|
}, c);
|
||||||
|
|
||||||
|
|
|
@ -51,11 +51,17 @@ async function deleteUnattachedMediaByUrl(url: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get unattached media by IDs. */
|
/** Get unattached media by IDs. */
|
||||||
async function getUnattachedMediaByIds(kysely: Kysely<DittoTables>, ids: string[]) {
|
async function getUnattachedMediaByIds(kysely: Kysely<DittoTables>, ids: string[]): Promise<UnattachedMedia[]> {
|
||||||
if (!ids.length) return [];
|
if (!ids.length) return [];
|
||||||
return await selectUnattachedMediaQuery(kysely)
|
|
||||||
|
const results = await selectUnattachedMediaQuery(kysely)
|
||||||
.where('id', 'in', ids)
|
.where('id', 'in', ids)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
return results.map((row) => ({
|
||||||
|
...row,
|
||||||
|
data: JSON.parse(row.data),
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Delete rows as an event with media is being created. */
|
/** Delete rows as an event with media is being created. */
|
||||||
|
|
Loading…
Reference in New Issue