|
|
|
@ -47,6 +47,7 @@ export function createRepostDraftEvent(event: Event): TDraftEvent { |
|
|
|
|
|
|
|
|
|
|
|
export async function createShortTextNoteDraftEvent( |
|
|
|
export async function createShortTextNoteDraftEvent( |
|
|
|
content: string, |
|
|
|
content: string, |
|
|
|
|
|
|
|
pictureInfos: { url: string; tags: string[][] }[], |
|
|
|
options: { |
|
|
|
options: { |
|
|
|
parentEvent?: Event |
|
|
|
parentEvent?: Event |
|
|
|
addClientTag?: boolean |
|
|
|
addClientTag?: boolean |
|
|
|
@ -70,6 +71,11 @@ export async function createShortTextNoteDraftEvent( |
|
|
|
tags.push(['e', parentEventId, '', 'reply']) |
|
|
|
tags.push(['e', parentEventId, '', 'reply']) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { images } = extractImagesFromContent(content) |
|
|
|
|
|
|
|
if (images && images.length) { |
|
|
|
|
|
|
|
tags.push(...generateImetaTags(images, pictureInfos)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (options.addClientTag) { |
|
|
|
if (options.addClientTag) { |
|
|
|
tags.push(['client', 'jumble']) |
|
|
|
tags.push(['client', 'jumble']) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -98,6 +104,7 @@ export function createRelaySetDraftEvent(relaySet: TRelaySet): TDraftEvent { |
|
|
|
|
|
|
|
|
|
|
|
export async function createPictureNoteDraftEvent( |
|
|
|
export async function createPictureNoteDraftEvent( |
|
|
|
content: string, |
|
|
|
content: string, |
|
|
|
|
|
|
|
pictureInfos: { url: string; tags: string[][] }[], |
|
|
|
options: { |
|
|
|
options: { |
|
|
|
addClientTag?: boolean |
|
|
|
addClientTag?: boolean |
|
|
|
} = {} |
|
|
|
} = {} |
|
|
|
@ -109,8 +116,7 @@ export async function createPictureNoteDraftEvent( |
|
|
|
throw new Error('No images found in content') |
|
|
|
throw new Error('No images found in content') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const tags = images |
|
|
|
const tags = generateImetaTags(images, pictureInfos) |
|
|
|
.map((image) => ['imeta', `url ${image}`]) |
|
|
|
|
|
|
|
.concat(pubkeys.map((pubkey) => ['p', pubkey])) |
|
|
|
.concat(pubkeys.map((pubkey) => ['p', pubkey])) |
|
|
|
.concat(quoteEventIds.map((eventId) => ['q', eventId])) |
|
|
|
.concat(quoteEventIds.map((eventId) => ['q', eventId])) |
|
|
|
.concat(hashtags.map((hashtag) => ['t', hashtag])) |
|
|
|
.concat(hashtags.map((hashtag) => ['t', hashtag])) |
|
|
|
@ -130,6 +136,7 @@ export async function createPictureNoteDraftEvent( |
|
|
|
export async function createCommentDraftEvent( |
|
|
|
export async function createCommentDraftEvent( |
|
|
|
content: string, |
|
|
|
content: string, |
|
|
|
parentEvent: Event, |
|
|
|
parentEvent: Event, |
|
|
|
|
|
|
|
pictureInfos: { url: string; tags: string[][] }[], |
|
|
|
options: { |
|
|
|
options: { |
|
|
|
addClientTag?: boolean |
|
|
|
addClientTag?: boolean |
|
|
|
} = {} |
|
|
|
} = {} |
|
|
|
@ -153,12 +160,15 @@ export async function createCommentDraftEvent( |
|
|
|
['e', parentEventId], |
|
|
|
['e', parentEventId], |
|
|
|
['k', parentEventKind.toString()], |
|
|
|
['k', parentEventKind.toString()], |
|
|
|
['p', parentEventPubkey] |
|
|
|
['p', parentEventPubkey] |
|
|
|
].concat( |
|
|
|
] |
|
|
|
pubkeys |
|
|
|
.concat(pubkeys.map((pubkey) => ['p', pubkey])) |
|
|
|
.map((pubkey) => ['p', pubkey]) |
|
|
|
|
|
|
|
.concat(quoteEventIds.map((eventId) => ['q', eventId])) |
|
|
|
.concat(quoteEventIds.map((eventId) => ['q', eventId])) |
|
|
|
.concat(hashtags.map((hashtag) => ['t', hashtag])) |
|
|
|
.concat(hashtags.map((hashtag) => ['t', hashtag])) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const { images } = extractImagesFromContent(content) |
|
|
|
|
|
|
|
if (images && images.length) { |
|
|
|
|
|
|
|
tags.push(...generateImetaTags(images, pictureInfos)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (options.addClientTag) { |
|
|
|
if (options.addClientTag) { |
|
|
|
tags.push(['client', 'jumble']) |
|
|
|
tags.push(['client', 'jumble']) |
|
|
|
@ -171,3 +181,12 @@ export async function createCommentDraftEvent( |
|
|
|
created_at: dayjs().unix() |
|
|
|
created_at: dayjs().unix() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function generateImetaTags(imageUrls: string[], pictureInfos: { url: string; tags: string[][] }[]) { |
|
|
|
|
|
|
|
return imageUrls.map((imageUrl) => { |
|
|
|
|
|
|
|
const pictureInfo = pictureInfos.find((info) => info.url === imageUrl) |
|
|
|
|
|
|
|
return pictureInfo |
|
|
|
|
|
|
|
? ['imeta', ...pictureInfo.tags.map(([n, v]) => `${n} ${v}`)] |
|
|
|
|
|
|
|
: ['imeta', `url ${imageUrl}`] |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|