Receive support for editing messages
This commit is contained in:
parent
2781e621ad
commit
36e21c0134
46 changed files with 2053 additions and 405 deletions
|
@ -27,6 +27,7 @@ import { ThemeType } from './Util';
|
|||
import * as GoogleChrome from '../util/GoogleChrome';
|
||||
import { ReadStatus } from '../messages/MessageReadStatus';
|
||||
import type { MessageStatusType } from '../components/conversation/Message';
|
||||
import { softAssert } from '../util/assert';
|
||||
|
||||
const MAX_WIDTH = 300;
|
||||
const MAX_HEIGHT = MAX_WIDTH * 1.5;
|
||||
|
@ -40,7 +41,9 @@ export type AttachmentType = {
|
|||
blurHash?: string;
|
||||
caption?: string;
|
||||
contentType: MIME.MIMEType;
|
||||
digest?: string;
|
||||
fileName?: string;
|
||||
uploadTimestamp?: number;
|
||||
/** Not included in protobuf, needs to be pulled from flags */
|
||||
isVoiceMessage?: boolean;
|
||||
/** For messages not already on disk, this will be a data url */
|
||||
|
@ -78,7 +81,6 @@ export type AttachmentType = {
|
|||
schemaVersion?: number;
|
||||
|
||||
/** Removed once we download the attachment */
|
||||
digest?: string;
|
||||
key?: string;
|
||||
};
|
||||
|
||||
|
@ -187,6 +189,7 @@ export async function migrateDataToFileSystem(
|
|||
const { data } = attachment;
|
||||
const attachmentHasData = !isUndefined(data);
|
||||
const shouldSkipSchemaUpgrade = !attachmentHasData;
|
||||
|
||||
if (shouldSkipSchemaUpgrade) {
|
||||
return attachment;
|
||||
}
|
||||
|
@ -1001,3 +1004,8 @@ export const canBeDownloaded = (
|
|||
): boolean => {
|
||||
return Boolean(attachment.key && attachment.digest);
|
||||
};
|
||||
|
||||
export function getAttachmentSignature(attachment: AttachmentType): string {
|
||||
softAssert(attachment.digest, 'attachment missing digest');
|
||||
return attachment.digest || String(attachment.blurHash);
|
||||
}
|
||||
|
|
|
@ -824,7 +824,8 @@ export const deleteAllExternalFiles = ({
|
|||
}
|
||||
|
||||
return async (message: MessageAttributesType) => {
|
||||
const { attachments, quote, contact, preview, sticker } = message;
|
||||
const { attachments, editHistory, quote, contact, preview, sticker } =
|
||||
message;
|
||||
|
||||
if (attachments && attachments.length) {
|
||||
await Promise.all(attachments.map(deleteAttachmentData));
|
||||
|
@ -858,15 +859,7 @@ export const deleteAllExternalFiles = ({
|
|||
}
|
||||
|
||||
if (preview && preview.length) {
|
||||
await Promise.all(
|
||||
preview.map(async item => {
|
||||
const { image } = item;
|
||||
|
||||
if (image && image.path) {
|
||||
await deleteOnDisk(image.path);
|
||||
}
|
||||
})
|
||||
);
|
||||
await deletePreviews(preview, deleteOnDisk);
|
||||
}
|
||||
|
||||
if (sticker && sticker.data && sticker.data.path) {
|
||||
|
@ -876,9 +869,42 @@ export const deleteAllExternalFiles = ({
|
|||
await deleteOnDisk(sticker.data.thumbnail.path);
|
||||
}
|
||||
}
|
||||
|
||||
if (editHistory && editHistory.length) {
|
||||
await editHistory.map(edit => {
|
||||
if (!edit.attachments || !edit.attachments.length) {
|
||||
return;
|
||||
}
|
||||
return Promise.all(edit.attachments.map(deleteAttachmentData));
|
||||
});
|
||||
await editHistory.map(edit => deletePreviews(edit.preview, deleteOnDisk));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
async function deletePreviews(
|
||||
preview: MessageAttributesType['preview'],
|
||||
deleteOnDisk: (path: string) => Promise<void>
|
||||
): Promise<Array<void>> {
|
||||
if (!preview) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Promise.all(
|
||||
preview.map(async item => {
|
||||
const { image } = item;
|
||||
|
||||
if (image && image.path) {
|
||||
await deleteOnDisk(image.path);
|
||||
}
|
||||
|
||||
if (image?.thumbnail?.path) {
|
||||
await deleteOnDisk(image.thumbnail.path);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// createAttachmentDataWriter :: (RelativePath -> IO Unit)
|
||||
// Message ->
|
||||
// IO (Promise Message)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue