Move receipts and view/read syncs to new syncTasks system

This commit is contained in:
Scott Nonnenberg 2024-06-17 12:24:39 -07:00 committed by GitHub
parent 1a263e63da
commit 75c32e86f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 1242 additions and 612 deletions

View file

@ -1,17 +1,67 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import PQueue from 'p-queue';
import { batch } from 'react-redux';
import type { MessageAttributesType } from '../model-types.d';
import { deletePackReference } from '../types/Stickers';
import { isStory } from '../messages/helpers';
import { isDirectConversation } from './whatTypeOfConversation';
import * as log from '../logging/log';
import { getCallHistorySelector } from '../state/selectors/callHistory';
import {
DirectCallStatus,
GroupCallStatus,
AdhocCallStatus,
} from '../types/CallDisposition';
import { getMessageIdForLogging } from './idForLogging';
import type { SingleProtoJobQueue } from '../jobs/singleProtoJobQueue';
import { MINUTE } from './durations';
import { drop } from './drop';
export async function cleanupMessage(
message: MessageAttributesType
export async function cleanupMessages(
messages: ReadonlyArray<MessageAttributesType>,
{
fromSync,
markCallHistoryDeleted,
singleProtoJobQueue,
}: {
fromSync?: boolean;
markCallHistoryDeleted: (callId: string) => Promise<void>;
singleProtoJobQueue: SingleProtoJobQueue;
}
): Promise<void> {
cleanupMessageFromMemory(message);
await deleteMessageData(message);
// First, handle any calls that need to be deleted
const inMemoryQueue = new PQueue({ concurrency: 3, timeout: MINUTE * 30 });
drop(
inMemoryQueue.addAll(
messages.map((message: MessageAttributesType) => async () => {
await maybeDeleteCall(message, {
fromSync,
markCallHistoryDeleted,
singleProtoJobQueue,
});
})
)
);
await inMemoryQueue.onIdle();
// Then, remove messages from memory, so we can batch the updates in redux
batch(() => {
messages.forEach(message => cleanupMessageFromMemory(message));
});
// Then, handle any asynchronous actions (e.g. deleting data from disk)
const unloadedQueue = new PQueue({ concurrency: 3, timeout: MINUTE * 30 });
drop(
unloadedQueue.addAll(
messages.map((message: MessageAttributesType) => async () => {
await deleteMessageData(message);
})
)
);
await unloadedQueue.onIdle();
}
/** Removes a message from redux caches & backbone, but does NOT delete files on disk,
@ -122,3 +172,50 @@ export async function deleteMessageData(
await deletePackReference(message.id, packId);
}
}
export async function maybeDeleteCall(
message: MessageAttributesType,
{
fromSync,
markCallHistoryDeleted,
singleProtoJobQueue,
}: {
fromSync?: boolean;
markCallHistoryDeleted: (callId: string) => Promise<void>;
singleProtoJobQueue: SingleProtoJobQueue;
}
): Promise<void> {
const { callId } = message;
const logId = `maybeDeleteCall(${getMessageIdForLogging(message)})`;
if (!callId) {
return;
}
const callHistory = getCallHistorySelector(window.reduxStore.getState())(
callId
);
if (!callHistory) {
return;
}
if (
callHistory.status === DirectCallStatus.Pending ||
callHistory.status === GroupCallStatus.Joined ||
callHistory.status === GroupCallStatus.OutgoingRing ||
callHistory.status === GroupCallStatus.Ringing ||
callHistory.status === AdhocCallStatus.Pending
) {
log.warn(
`${logId}: Call status is ${callHistory.status}; not deleting from Call Tab`
);
return;
}
if (!fromSync) {
await singleProtoJobQueue.add(
window.textsecure.MessageSender.getDeleteCallEvent(callHistory)
);
}
await markCallHistoryDeleted(callId);
window.reduxActions.callHistory.removeCallHistory(callId);
}