signal-desktop/ts/util/onCallLogEventSync.ts

70 lines
2.4 KiB
TypeScript
Raw Normal View History

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