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';
|
2021-07-09 19:36:10 +00:00
|
|
|
import { normalizeUuid } from '../util/normalizeUuid';
|
2023-06-29 19:17:27 +00:00
|
|
|
import type { ProcessedSent, ProcessedSyncMessage } from './Types.d';
|
|
|
|
import type { TaggedUUIDStringType } from '../types/UUID';
|
2021-07-09 19:36:10 +00:00
|
|
|
|
2023-06-29 19:17:27 +00:00
|
|
|
type ProtoUUIDTriple = Readonly<{
|
|
|
|
destinationAci?: string | null;
|
|
|
|
destinationPni?: string | null;
|
|
|
|
}>;
|
2021-07-09 19:36:10 +00:00
|
|
|
|
2023-06-29 19:17:27 +00:00
|
|
|
function toTaggedUuid({
|
|
|
|
destinationAci,
|
|
|
|
destinationPni,
|
|
|
|
}: ProtoUUIDTriple): TaggedUUIDStringType | undefined {
|
|
|
|
if (destinationAci) {
|
|
|
|
return {
|
|
|
|
aci: normalizeUuid(destinationAci, 'syncMessage.sent.destinationAci'),
|
|
|
|
pni: undefined,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (destinationPni) {
|
|
|
|
return {
|
|
|
|
aci: undefined,
|
|
|
|
pni: normalizeUuid(destinationPni, 'syncMessage.sent.destinationPni'),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
function processProtoWithDestinationUuid<Input extends ProtoUUIDTriple>(
|
|
|
|
input: Input
|
|
|
|
): Omit<Input, keyof ProtoUUIDTriple> & {
|
|
|
|
destinationUuid?: TaggedUUIDStringType;
|
|
|
|
} {
|
|
|
|
const { destinationAci, destinationPni, ...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-06-29 19:17:27 +00:00
|
|
|
destinationUuid: toTaggedUuid({
|
|
|
|
destinationAci,
|
|
|
|
destinationPni,
|
|
|
|
}),
|
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 {
|
|
|
|
destinationAci,
|
|
|
|
destinationPni,
|
|
|
|
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-06-29 19:17:27 +00:00
|
|
|
destinationUuid: toTaggedUuid({
|
|
|
|
destinationAci,
|
|
|
|
destinationPni,
|
|
|
|
}),
|
2021-07-09 19:36:10 +00:00
|
|
|
unidentifiedStatus: unidentifiedStatus
|
2023-06-29 19:17:27 +00:00
|
|
|
? unidentifiedStatus.map(processProtoWithDestinationUuid)
|
|
|
|
: undefined,
|
|
|
|
storyMessageRecipients: storyMessageRecipients
|
|
|
|
? storyMessageRecipients.map(processProtoWithDestinationUuid)
|
2021-07-09 19:36:10 +00:00
|
|
|
: undefined,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function processSyncMessage(
|
|
|
|
syncMessage: Proto.ISyncMessage
|
|
|
|
): ProcessedSyncMessage {
|
|
|
|
return {
|
|
|
|
...syncMessage,
|
|
|
|
sent: processSent(syncMessage.sent),
|
|
|
|
};
|
|
|
|
}
|