Improve check during message export
This commit is contained in:
parent
a769429b36
commit
11fed7e7f8
2 changed files with 58 additions and 2 deletions
|
@ -47,7 +47,7 @@ import { isConversationUnregistered } from '../../util/isConversationUnregistere
|
||||||
import { uuidToBytes } from '../../util/uuidToBytes';
|
import { uuidToBytes } from '../../util/uuidToBytes';
|
||||||
import { assertDev, strictAssert } from '../../util/assert';
|
import { assertDev, strictAssert } from '../../util/assert';
|
||||||
import { getSafeLongFromTimestamp } from '../../util/timestampLongUtils';
|
import { getSafeLongFromTimestamp } from '../../util/timestampLongUtils';
|
||||||
import { MINUTE, SECOND, DurationInSeconds } from '../../util/durations';
|
import { DAY, MINUTE, SECOND, DurationInSeconds } from '../../util/durations';
|
||||||
import {
|
import {
|
||||||
PhoneNumberDiscoverability,
|
PhoneNumberDiscoverability,
|
||||||
parsePhoneNumberDiscoverability,
|
parsePhoneNumberDiscoverability,
|
||||||
|
@ -111,6 +111,7 @@ import {
|
||||||
import type { CoreAttachmentBackupJobType } from '../../types/AttachmentBackup';
|
import type { CoreAttachmentBackupJobType } from '../../types/AttachmentBackup';
|
||||||
import { AttachmentBackupManager } from '../../jobs/AttachmentBackupManager';
|
import { AttachmentBackupManager } from '../../jobs/AttachmentBackupManager';
|
||||||
import { getBackupCdnInfo } from './util/mediaId';
|
import { getBackupCdnInfo } from './util/mediaId';
|
||||||
|
import { calculateExpirationTimestamp } from '../../util/expirationTimer';
|
||||||
import { ReadStatus } from '../../messages/MessageReadStatus';
|
import { ReadStatus } from '../../messages/MessageReadStatus';
|
||||||
|
|
||||||
const MAX_CONCURRENCY = 10;
|
const MAX_CONCURRENCY = 10;
|
||||||
|
@ -174,7 +175,10 @@ type NonBubbleResultType = Readonly<
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export class BackupExportStream extends Readable {
|
export class BackupExportStream extends Readable {
|
||||||
private readonly backupTimeMs = getSafeLongFromTimestamp(Date.now());
|
// Shared between all methods for consistency.
|
||||||
|
private now = Date.now();
|
||||||
|
|
||||||
|
private readonly backupTimeMs = getSafeLongFromTimestamp(this.now);
|
||||||
private readonly convoIdToRecipientId = new Map<string, number>();
|
private readonly convoIdToRecipientId = new Map<string, number>();
|
||||||
private attachmentBackupJobs: Array<CoreAttachmentBackupJobType> = [];
|
private attachmentBackupJobs: Array<CoreAttachmentBackupJobType> = [];
|
||||||
private buffers = new Array<Uint8Array>();
|
private buffers = new Array<Uint8Array>();
|
||||||
|
@ -825,6 +829,12 @@ export class BackupExportStream extends Readable {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const expirationTimestamp = calculateExpirationTimestamp(message);
|
||||||
|
if (expirationTimestamp != null && expirationTimestamp <= this.now + DAY) {
|
||||||
|
// Message expires too soon
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
let authorId: Long | undefined;
|
let authorId: Long | undefined;
|
||||||
|
|
||||||
const isOutgoing = message.type === 'outgoing';
|
const isOutgoing = message.type === 'outgoing';
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { ReadStatus } from '../../messages/MessageReadStatus';
|
||||||
import { SeenStatus } from '../../MessageSeenStatus';
|
import { SeenStatus } from '../../MessageSeenStatus';
|
||||||
import { loadCallsHistory } from '../../services/callHistoryLoader';
|
import { loadCallsHistory } from '../../services/callHistoryLoader';
|
||||||
import { ID_V1_LENGTH } from '../../groups';
|
import { ID_V1_LENGTH } from '../../groups';
|
||||||
|
import { DurationInSeconds, WEEK } from '../../util/durations';
|
||||||
import {
|
import {
|
||||||
setupBasics,
|
setupBasics,
|
||||||
asymmetricRoundtripHarness,
|
asymmetricRoundtripHarness,
|
||||||
|
@ -423,4 +424,49 @@ describe('backup/bubble messages', () => {
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('drops messages that expire soon', async () => {
|
||||||
|
await asymmetricRoundtripHarness(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
conversationId: contactA.id,
|
||||||
|
id: generateGuid(),
|
||||||
|
type: 'incoming',
|
||||||
|
received_at: 3,
|
||||||
|
received_at_ms: 3,
|
||||||
|
sent_at: 3,
|
||||||
|
timestamp: 3,
|
||||||
|
sourceServiceId: CONTACT_A,
|
||||||
|
body: 'd',
|
||||||
|
readStatus: ReadStatus.Unread,
|
||||||
|
seenStatus: SeenStatus.Unseen,
|
||||||
|
unidentifiedDeliveryReceived: true,
|
||||||
|
expirationStartTimestamp: Date.now(),
|
||||||
|
expireTimer: DurationInSeconds.fromSeconds(1),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not drop messages that expire far in the future', async () => {
|
||||||
|
await symmetricRoundtripHarness([
|
||||||
|
{
|
||||||
|
conversationId: contactA.id,
|
||||||
|
id: generateGuid(),
|
||||||
|
type: 'incoming',
|
||||||
|
received_at: 3,
|
||||||
|
received_at_ms: 3,
|
||||||
|
sent_at: 3,
|
||||||
|
timestamp: 3,
|
||||||
|
sourceServiceId: CONTACT_A,
|
||||||
|
body: 'd',
|
||||||
|
readStatus: ReadStatus.Unread,
|
||||||
|
seenStatus: SeenStatus.Unseen,
|
||||||
|
unidentifiedDeliveryReceived: true,
|
||||||
|
expirationStartTimestamp: Date.now(),
|
||||||
|
expireTimer: DurationInSeconds.fromMillis(WEEK),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue