signal-desktop/ts/util/onCallLogEventSync.ts

68 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-08-08 17:53:06 -07:00
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { CallLogEventSyncEvent } from '../textsecure/messageReceiverEvents';
2025-06-16 11:59:31 -07:00
import { createLogger } from '../logging/log';
2024-07-22 11:16:33 -07:00
import { DataWriter } from '../sql/Client';
2024-06-25 17:58:38 -07:00
import type { CallLogEventTarget } from '../types/CallDisposition';
2023-08-08 17:53:06 -07:00
import { CallLogEvent } from '../types/CallDisposition';
import { missingCaseError } from './missingCaseError';
2024-06-25 17:58:38 -07:00
import { strictAssert } from './assert';
import { updateDeletedMessages } from './callDisposition';
2023-08-08 17:53:06 -07:00
2025-06-16 11:59:31 -07:00
const log = createLogger('onCallLogEventSync');
2023-08-08 17:53:06 -07:00
export async function onCallLogEventSync(
syncEvent: CallLogEventSyncEvent
): Promise<void> {
2024-06-25 17:58:38 -07:00
const { data, confirm } = syncEvent;
const { type, peerIdAsConversationId, peerIdAsRoomId, callId, timestamp } =
data.callLogEventDetails;
2024-06-25 17:58:38 -07:00
const target: CallLogEventTarget = {
peerIdAsConversationId,
peerIdAsRoomId,
2024-06-25 17:58:38 -07:00
callId,
timestamp,
};
2023-08-08 17:53:06 -07:00
log.info(
2025-06-16 11:59:31 -07:00
`Processing event (Event: ${type}, CallId: ${callId}, Timestamp: ${timestamp})`
2023-08-08 17:53:06 -07:00
);
2024-06-25 17:58:38 -07:00
if (type === CallLogEvent.Clear) {
2025-06-16 11:59:31 -07:00
log.info('Clearing call history');
try {
2024-07-22 11:16:33 -07:00
const messageIds = await DataWriter.clearCallHistory(target);
2024-06-25 17:58:38 -07:00
updateDeletedMessages(messageIds);
} finally {
// We want to reset the call history even if the clear fails.
window.reduxActions.callHistory.resetCallHistory();
}
2023-08-08 17:53:06 -07:00
confirm();
2024-06-25 17:58:38 -07:00
} else if (type === CallLogEvent.MarkedAsRead) {
2025-06-16 11:59:31 -07:00
log.info('Marking call history read');
2024-06-25 17:58:38 -07:00
try {
2024-08-27 06:20:23 -07:00
const count = await DataWriter.markAllCallHistoryRead(target);
2025-06-16 11:59:31 -07:00
log.info(`Marked ${count} call history messages read`);
2024-06-25 17:58:38 -07:00
} finally {
window.reduxActions.callHistory.updateCallHistoryUnreadCount();
}
confirm();
} else if (type === CallLogEvent.MarkedAsReadInConversation) {
2025-06-16 11:59:31 -07:00
log.info('Marking call history read in conversation');
try {
strictAssert(peerIdAsConversationId, 'Missing peerIdAsConversationId');
strictAssert(peerIdAsRoomId, 'Missing peerIdAsRoomId');
2024-08-27 06:20:23 -07:00
const count =
await DataWriter.markAllCallHistoryReadInConversation(target);
2025-06-16 11:59:31 -07:00
log.info(`Marked ${count} call history messages read`);
} finally {
window.reduxActions.callHistory.updateCallHistoryUnreadCount();
}
confirm();
2023-08-08 17:53:06 -07:00
} else {
2024-06-25 17:58:38 -07:00
throw missingCaseError(type);
2023-08-08 17:53:06 -07:00
}
}