mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-11 11:43:17 +08:00
fix: trim redundant quoted message metadata
This commit is contained in:
parent
559ea2c5a5
commit
149f435216
7 changed files with 677 additions and 251 deletions
|
|
@ -2,7 +2,6 @@ import { promptContentForMessage } from '../image-prompt.mjs';
|
|||
|
||||
const REPLY_CONTENT_MAX_CODE_POINTS = 8_000;
|
||||
const REPLY_ATTACHMENTS_MAX = 20;
|
||||
const REPLY_ID_MAX_CODE_POINTS = 512;
|
||||
const REPLY_AUTHOR_NAME_MAX_CODE_POINTS = 256;
|
||||
const REPLY_ATTACHMENT_NAME_MAX_CODE_POINTS = 255;
|
||||
|
||||
|
|
@ -105,8 +104,6 @@ async function resolveReference(reference, signal) {
|
|||
}
|
||||
|
||||
function normalizeReference(reference) {
|
||||
const messageId = cleanString(reference.messageId, REPLY_ID_MAX_CODE_POINTS);
|
||||
const authorId = cleanString(reference.authorId, REPLY_ID_MAX_CODE_POINTS);
|
||||
const authorName = cleanString(reference.authorName, REPLY_AUTHOR_NAME_MAX_CODE_POINTS);
|
||||
const content = cleanString(reference.content, REPLY_CONTENT_MAX_CODE_POINTS, { multiline: true });
|
||||
const { attachments, truncated: attachmentsTruncated } = cleanAttachments(reference.attachments);
|
||||
|
|
@ -114,19 +111,16 @@ function normalizeReference(reference) {
|
|||
if (!content.value && attachments.length === 0 && !unavailableReason) {
|
||||
unavailableReason = 'not-delivered';
|
||||
}
|
||||
const truncated = authorName.truncated
|
||||
|| content.truncated
|
||||
|| attachmentsTruncated;
|
||||
return {
|
||||
note: REPLY_NOTE,
|
||||
...(messageId.value ? { messageId: messageId.value } : {}),
|
||||
...(authorId.value ? { authorId: authorId.value } : {}),
|
||||
...(authorName.value ? { authorName: authorName.value } : {}),
|
||||
...(content.value ? { content: content.value } : {}),
|
||||
attachments,
|
||||
...(attachments.length > 0 ? { attachments } : {}),
|
||||
...(unavailableReason ? { unavailableReason } : {}),
|
||||
truncated: messageId.truncated
|
||||
|| authorId.truncated
|
||||
|| authorName.truncated
|
||||
|| content.truncated
|
||||
|| attachmentsTruncated,
|
||||
...(truncated ? { truncated: true } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -142,11 +142,10 @@ function telegramFileSource(message, loadFile) {
|
|||
};
|
||||
}
|
||||
|
||||
function telegramReplyAttachment(kind, file, fallbackName) {
|
||||
function telegramReplyAttachment(kind, file) {
|
||||
if (!file || typeof file !== 'object') return null;
|
||||
const name = typeof file.file_name === 'string' && file.file_name
|
||||
? file.file_name : typeof fallbackName === 'string' && fallbackName
|
||||
? fallbackName : undefined;
|
||||
? file.file_name : undefined;
|
||||
return { kind, ...(name ? { name } : {}) };
|
||||
}
|
||||
|
||||
|
|
@ -156,11 +155,7 @@ function telegramReplyAttachments(message) {
|
|||
const largest = message.photo.reduce((best, candidate) => (
|
||||
photoScore(candidate) > photoScore(best) ? candidate : best
|
||||
));
|
||||
attachments.push(telegramReplyAttachment(
|
||||
'image',
|
||||
largest,
|
||||
`${largest.file_unique_id ?? largest.file_id ?? 'telegram-photo'}.jpg`,
|
||||
));
|
||||
attachments.push(telegramReplyAttachment('image', largest));
|
||||
} else if (message?.document) {
|
||||
attachments.push(telegramReplyAttachment(
|
||||
imageTypeForDocument(message.document) ? 'image' : 'file',
|
||||
|
|
@ -180,7 +175,6 @@ function telegramReplyAttachments(message) {
|
|||
attachments.push(telegramReplyAttachment(
|
||||
message.sticker.is_video === true ? 'video' : 'image',
|
||||
message.sticker,
|
||||
message.sticker.file_unique_id ?? message.sticker.file_id,
|
||||
));
|
||||
}
|
||||
return attachments.filter(Boolean);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue