Support voice memo backups

This commit is contained in:
trevor-signal
2024-06-06 12:16:27 -04:00
committed by GitHub
parent 348503c7f9
commit 9cbbbe0ef0
4 changed files with 82 additions and 19 deletions

View File

@@ -20,7 +20,7 @@ import {
isDecryptable,
isReencryptableToSameDigest,
} from '../../../types/Attachment';
import { Backups } from '../../../protobuf';
import { Backups, SignalService } from '../../../protobuf';
import * as Bytes from '../../../Bytes';
import { getTimestampFromLong } from '../../../util/timestampLongUtils';
import {
@@ -36,6 +36,7 @@ import {
getMediaNameForAttachment,
} from './mediaId';
import { redactGenericText } from '../../../util/privacy';
import { missingCaseError } from '../../../util/missingCaseError';
export function convertFilePointerToAttachment(
filePointer: Backups.FilePointer
@@ -123,6 +124,35 @@ export function convertFilePointerToAttachment(
throw new Error('convertFilePointerToAttachment: mising locator');
}
export function convertBackupMessageAttachmentToAttachment(
messageAttachment: Backups.IMessageAttachment
): AttachmentType | null {
if (!messageAttachment.pointer) {
return null;
}
const result = convertFilePointerToAttachment(messageAttachment.pointer);
switch (messageAttachment.flag) {
case Backups.MessageAttachment.Flag.VOICE_MESSAGE:
result.flags = SignalService.AttachmentPointer.Flags.VOICE_MESSAGE;
break;
case Backups.MessageAttachment.Flag.BORDERLESS:
result.flags = SignalService.AttachmentPointer.Flags.BORDERLESS;
break;
case Backups.MessageAttachment.Flag.GIF:
result.flags = SignalService.AttachmentPointer.Flags.GIF;
break;
case Backups.MessageAttachment.Flag.NONE:
case null:
case undefined:
result.flags = undefined;
break;
default:
throw missingCaseError(messageAttachment.flag);
}
return result;
}
/**
* Some attachments saved on desktop do not include the key used to encrypt the file
* originally. This means that we need to encrypt the file in-memory now (at