2021-07-09 19:36:10 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-06-29 19:17:27 +00:00
|
|
|
import type { SignalService as Proto } from '../protobuf';
|
2023-08-10 16:43:33 +00:00
|
|
|
import type { ServiceIdString } from '../types/ServiceId';
|
|
|
|
import { normalizeServiceId } from '../types/ServiceId';
|
2023-06-29 19:17:27 +00:00
|
|
|
import type { ProcessedSent, ProcessedSyncMessage } from './Types.d';
|
2021-07-09 19:36:10 +00:00
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
type ProtoServiceId = Readonly<{
|
|
|
|
destinationServiceId?: string | null;
|
2023-06-29 19:17:27 +00:00
|
|
|
}>;
|
2021-07-09 19:36:10 +00:00
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
function processProtoWithDestinationServiceId<Input extends ProtoServiceId>(
|
2023-06-29 19:17:27 +00:00
|
|
|
input: Input
|
2023-08-10 16:43:33 +00:00
|
|
|
): Omit<Input, keyof ProtoServiceId> & {
|
|
|
|
destinationServiceId?: ServiceIdString;
|
2023-06-29 19:17:27 +00:00
|
|
|
} {
|
2023-08-10 16:43:33 +00:00
|
|
|
const { destinationServiceId, ...remaining } = input;
|
2021-07-09 19:36:10 +00:00
|
|
|
|
|
|
|
return {
|
2023-06-29 19:17:27 +00:00
|
|
|
...remaining,
|
2021-07-09 19:36:10 +00:00
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
destinationServiceId: destinationServiceId
|
|
|
|
? normalizeServiceId(destinationServiceId, 'processSyncMessage')
|
|
|
|
: undefined,
|
2021-07-09 19:36:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function processSent(
|
|
|
|
sent?: Proto.SyncMessage.ISent | null
|
|
|
|
): ProcessedSent | undefined {
|
|
|
|
if (!sent) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2023-06-29 19:17:27 +00:00
|
|
|
const {
|
2023-08-10 16:43:33 +00:00
|
|
|
destinationServiceId,
|
2023-06-29 19:17:27 +00:00
|
|
|
unidentifiedStatus,
|
|
|
|
storyMessageRecipients,
|
|
|
|
...remaining
|
|
|
|
} = sent;
|
2021-07-09 19:36:10 +00:00
|
|
|
|
|
|
|
return {
|
2023-06-29 19:17:27 +00:00
|
|
|
...remaining,
|
2021-07-09 19:36:10 +00:00
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
destinationServiceId: destinationServiceId
|
|
|
|
? normalizeServiceId(destinationServiceId, 'processSent')
|
|
|
|
: undefined,
|
2021-07-09 19:36:10 +00:00
|
|
|
unidentifiedStatus: unidentifiedStatus
|
2023-08-10 16:43:33 +00:00
|
|
|
? unidentifiedStatus.map(processProtoWithDestinationServiceId)
|
2023-06-29 19:17:27 +00:00
|
|
|
: undefined,
|
|
|
|
storyMessageRecipients: storyMessageRecipients
|
2023-08-10 16:43:33 +00:00
|
|
|
? storyMessageRecipients.map(processProtoWithDestinationServiceId)
|
2021-07-09 19:36:10 +00:00
|
|
|
: undefined,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function processSyncMessage(
|
|
|
|
syncMessage: Proto.ISyncMessage
|
|
|
|
): ProcessedSyncMessage {
|
|
|
|
return {
|
|
|
|
...syncMessage,
|
|
|
|
sent: processSent(syncMessage.sent),
|
|
|
|
};
|
|
|
|
}
|