Receive support for editing messages

This commit is contained in:
Josh Perez 2023-03-27 19:48:57 -04:00 committed by GitHub
parent 2781e621ad
commit 36e21c0134
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 2053 additions and 405 deletions

View file

@ -21,31 +21,12 @@ export function hasAttachmentDownloads(
return true;
}
const hasNormalAttachments = normalAttachments.some(attachment => {
if (!attachment) {
return false;
}
// We've already downloaded this!
if (attachment.path) {
return false;
}
return true;
});
const hasNormalAttachments = hasNormalAttachmentDownloads(normalAttachments);
if (hasNormalAttachments) {
return true;
}
const previews = message.preview || [];
const hasPreviews = previews.some(item => {
if (!item.image) {
return false;
}
// We've already downloaded this!
if (item.image.path) {
return false;
}
return true;
});
const hasPreviews = hasPreviewDownloads(message.preview);
if (hasPreviews) {
return true;
}
@ -85,5 +66,48 @@ export function hasAttachmentDownloads(
return !sticker.data || (sticker.data && !sticker.data.path);
}
const { editHistory } = message;
if (editHistory) {
const hasAttachmentsWithinEditHistory = editHistory.some(
edit =>
hasNormalAttachmentDownloads(edit.attachments) ||
hasPreviewDownloads(edit.preview)
);
if (hasAttachmentsWithinEditHistory) {
return true;
}
}
return false;
}
function hasPreviewDownloads(
previews: MessageAttributesType['preview']
): boolean {
return (previews || []).some(item => {
if (!item.image) {
return false;
}
// We've already downloaded this!
if (item.image.path) {
return false;
}
return true;
});
}
function hasNormalAttachmentDownloads(
attachments: MessageAttributesType['attachments']
): boolean {
return (attachments || []).some(attachment => {
if (!attachment) {
return false;
}
// We've already downloaded this!
if (attachment.path) {
return false;
}
return true;
});
}