Import/export view-once messages

This commit is contained in:
Fedor Indutny 2024-10-29 11:16:09 -07:00 committed by GitHub
parent 2f6270c585
commit ce090a8a3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 66 additions and 3 deletions

View file

@ -77,6 +77,7 @@ import {
isNormalBubble,
isPhoneNumberDiscovery,
isProfileChange,
isTapToView,
isUniversalTimerNotification,
isUnsupportedMessage,
isVerifiedChange,
@ -1060,7 +1061,12 @@ export class BackupExportStream extends Readable {
}
const { contact, sticker } = message;
if (message.isErased) {
if (isTapToView(message)) {
result.viewOnceMessage = await this.toViewOnceMessage({
message,
backupLevel,
});
} else if (message.isErased) {
result.remoteDeletedMessage = {};
} else if (messageHasPaymentEvent(message)) {
const { payment } = message;
@ -2265,7 +2271,7 @@ export class BackupExportStream extends Readable {
serverTimestamp != null
? getSafeLongFromTimestamp(serverTimestamp)
: null,
read: readStatus === ReadStatus.Read,
read: readStatus === ReadStatus.Read || readStatus === ReadStatus.Viewed,
sealedSender: unidentifiedDeliveryReceived === true,
};
}
@ -2443,6 +2449,30 @@ export class BackupExportStream extends Readable {
};
}
private async toViewOnceMessage({
message,
backupLevel,
}: {
message: Pick<
MessageAttributesType,
'attachments' | 'received_at' | 'reactions'
>;
backupLevel: BackupLevel;
}): Promise<Backups.IViewOnceMessage> {
const attachment = message.attachments?.at(0);
return {
attachment:
attachment == null
? null
: await this.processMessageAttachment({
attachment,
backupLevel,
messageReceivedAt: message.received_at,
}),
reactions: this.getMessageReactions(message),
};
}
private async toChatItemRevisions(
parent: Backups.IChatItem,
message: MessageAttributesType,

View file

@ -1303,6 +1303,11 @@ export class BackupImportStream extends Writable {
...attributes,
...(await this.fromStandardMessage(item.standardMessage, chatConvo.id)),
};
} else if (item.viewOnceMessage) {
attributes = {
...attributes,
...(await this.fromViewOnceMessage(item.viewOnceMessage)),
};
} else {
const result = await this.fromNonBubbleChatItem(item, {
aboutMe,
@ -1566,6 +1571,27 @@ export class BackupImportStream extends Writable {
};
}
private async fromViewOnceMessage({
attachment,
reactions,
}: Backups.IViewOnceMessage): Promise<Partial<MessageAttributesType>> {
return {
...(attachment
? {
attachments: [
convertBackupMessageAttachmentToAttachment(attachment),
].filter(isNotNil),
}
: {
attachments: undefined,
readStatus: ReadStatus.Viewed,
isErased: true,
}),
reactions: this.fromReactions(reactions),
isViewOnce: true,
};
}
private async fromRevisions(
mainMessage: MessageAttributesType,
revisions: ReadonlyArray<Backups.IChatItem>