Improve backup conversation message request state handling

This commit is contained in:
trevor-signal 2024-12-04 00:53:44 -05:00 committed by GitHub
parent 644f5e0fd4
commit 8655244261
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -118,6 +118,7 @@ import { getEnvironment, isTestEnvironment } from '../../environment';
import { hasAttachmentDownloads } from '../../util/hasAttachmentDownloads'; import { hasAttachmentDownloads } from '../../util/hasAttachmentDownloads';
import { isNightly } from '../../util/version'; import { isNightly } from '../../util/version';
import { ToastType } from '../../types/Toast'; import { ToastType } from '../../types/Toast';
import { isConversationAccepted } from '../../util/isConversationAccepted';
const MAX_CONCURRENCY = 10; const MAX_CONCURRENCY = 10;
@ -299,8 +300,9 @@ export class BackupImportStream extends Writable {
override async _final(done: (error?: Error) => void): Promise<void> { override async _final(done: (error?: Error) => void): Promise<void> {
try { try {
// Finish saving remaining conversations/messages // Finish saving remaining conversations/messages
await this.flushConversations(); // Save messages first since they depend on conversations in memory
await this.flushMessages(); await this.flushMessages();
await this.flushConversations();
log.info(`${this.logId}: flushed messages and conversations`); log.info(`${this.logId}: flushed messages and conversations`);
// Store sticker packs and schedule downloads // Store sticker packs and schedule downloads
@ -568,6 +570,8 @@ export class BackupImportStream extends Writable {
} }
if (hasAttachmentDownloads(attributes)) { if (hasAttachmentDownloads(attributes)) {
const conversation = this.conversations.get(attributes.conversationId);
if (conversation && isConversationAccepted(conversation)) {
attachmentDownloadJobPromises.push( attachmentDownloadJobPromises.push(
queueAttachmentDownloads(attributes, { queueAttachmentDownloads(attributes, {
source: AttachmentDownloadSource.BACKUP_IMPORT, source: AttachmentDownloadSource.BACKUP_IMPORT,
@ -575,6 +579,7 @@ export class BackupImportStream extends Writable {
); );
} }
} }
}
await Promise.allSettled(attachmentDownloadJobPromises); await Promise.allSettled(attachmentDownloadJobPromises);
await AttachmentDownloadManager.saveBatchedJobs(); await AttachmentDownloadManager.saveBatchedJobs();
} }
@ -940,6 +945,10 @@ export class BackupImportStream extends Writable {
secretParams: Bytes.toBase64(secretParams), secretParams: Bytes.toBase64(secretParams),
publicParams: Bytes.toBase64(publicParams), publicParams: Bytes.toBase64(publicParams),
profileSharing: group.whitelisted === true, profileSharing: group.whitelisted === true,
messageRequestResponseType:
group.whitelisted === true
? SignalService.SyncMessage.MessageRequestResponse.Type.ACCEPT
: undefined,
hideStory: group.hideStory === true, hideStory: group.hideStory === true,
storySendMode, storySendMode,
avatar: avatarUrl avatar: avatarUrl
@ -1377,7 +1386,7 @@ export class BackupImportStream extends Writable {
if (item.revisions?.length) { if (item.revisions?.length) {
strictAssert( strictAssert(
item.standardMessage, item.standardMessage,
'Only standard message can have revisions' `${logId}: Only standard message can have revisions`
); );
const history = await this.fromRevisions(attributes, item.revisions); const history = await this.fromRevisions(attributes, item.revisions);
@ -1386,7 +1395,7 @@ export class BackupImportStream extends Writable {
// Update timestamps on the parent message // Update timestamps on the parent message
const oldest = history.at(-1); const oldest = history.at(-1);
assertDev(oldest != null, 'History is non-empty'); assertDev(oldest != null, `${logId}: History is non-empty`);
attributes.editMessageReceivedAt = attributes.received_at; attributes.editMessageReceivedAt = attributes.received_at;
attributes.editMessageReceivedAtMs = attributes.received_at_ms; attributes.editMessageReceivedAtMs = attributes.received_at_ms;