destinationServiceId in Sent
This commit is contained in:
parent
af4ad55c68
commit
f90c2b7479
20 changed files with 322 additions and 104 deletions
|
@ -52,7 +52,7 @@ import { bytesToUuid } from '../Crypto';
|
|||
import type { DownloadedAttachmentType } from '../types/Attachment';
|
||||
import { Address } from '../types/Address';
|
||||
import { QualifiedAddress } from '../types/QualifiedAddress';
|
||||
import type { UUIDStringType } from '../types/UUID';
|
||||
import type { UUIDStringType, TaggedUUIDStringType } from '../types/UUID';
|
||||
import { UUID, UUIDKind } from '../types/UUID';
|
||||
import * as Errors from '../types/errors';
|
||||
|
||||
|
@ -2028,8 +2028,9 @@ export default class MessageReceiver
|
|||
|
||||
let p: Promise<void> = Promise.resolve();
|
||||
if (msg.flags && msg.flags & Proto.DataMessage.Flags.END_SESSION) {
|
||||
if (destinationUuid) {
|
||||
p = this.handleEndSession(envelope, new UUID(destinationUuid));
|
||||
const anyUuid = destinationUuid?.aci ?? destinationUuid?.pni;
|
||||
if (anyUuid) {
|
||||
p = this.handleEndSession(envelope, new UUID(anyUuid));
|
||||
} else if (destination) {
|
||||
const theirUuid = UUID.lookup(destination);
|
||||
if (theirUuid) {
|
||||
|
@ -2061,8 +2062,7 @@ export default class MessageReceiver
|
|||
const ev = new SentEvent(
|
||||
{
|
||||
destination: dropNull(destination),
|
||||
destinationUuid:
|
||||
dropNull(destinationUuid) || envelope.destinationUuid.toString(),
|
||||
destinationUuid,
|
||||
timestamp: timestamp?.toNumber(),
|
||||
serverTimestamp: envelope.serverTimestamp,
|
||||
device: envelope.sourceDevice,
|
||||
|
@ -2168,7 +2168,9 @@ export default class MessageReceiver
|
|||
if (sentMessage && message.groupV2) {
|
||||
const ev = new SentEvent(
|
||||
{
|
||||
destinationUuid: envelope.destinationUuid.toString(),
|
||||
destinationUuid: {
|
||||
aci: envelope.destinationUuid.toString(),
|
||||
},
|
||||
device: envelope.sourceDevice,
|
||||
isRecipientUpdate: Boolean(sentMessage.isRecipientUpdate),
|
||||
message,
|
||||
|
@ -2183,10 +2185,7 @@ export default class MessageReceiver
|
|||
}
|
||||
|
||||
return {
|
||||
destinationUuid: normalizeUuid(
|
||||
destinationUuid,
|
||||
'handleStoryMessage.destinationUuid'
|
||||
),
|
||||
destinationUuid,
|
||||
isAllowedToReplyToStory: Boolean(isAllowedToReply),
|
||||
};
|
||||
})
|
||||
|
@ -2202,25 +2201,26 @@ export default class MessageReceiver
|
|||
const { storyMessageRecipients } = sentMessage;
|
||||
const recipients = storyMessageRecipients ?? [];
|
||||
|
||||
const isAllowedToReply = new Map<string, boolean>();
|
||||
const distributionListToSentUuid = new Map<string, Set<string>>();
|
||||
const isAllowedToReply = new Map<UUIDStringType, boolean>();
|
||||
const distributionListToSentUuid = new Map<
|
||||
string,
|
||||
Map<UUIDStringType, TaggedUUIDStringType>
|
||||
>();
|
||||
|
||||
recipients.forEach(recipient => {
|
||||
const { destinationUuid } = recipient;
|
||||
if (!destinationUuid) {
|
||||
if (!destinationUuid?.aci && !destinationUuid?.pni) {
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedDestinationUuid = normalizeUuid(
|
||||
destinationUuid,
|
||||
'handleStoryMessage.destinationUuid'
|
||||
);
|
||||
const destinationUuidString =
|
||||
destinationUuid?.aci || destinationUuid?.pni;
|
||||
|
||||
if (recipient.distributionListIds) {
|
||||
recipient.distributionListIds.forEach(listId => {
|
||||
const sentUuids: Set<string> =
|
||||
distributionListToSentUuid.get(listId) || new Set();
|
||||
sentUuids.add(normalizedDestinationUuid);
|
||||
const sentUuids: Map<UUIDStringType, TaggedUUIDStringType> =
|
||||
distributionListToSentUuid.get(listId) || new Map();
|
||||
sentUuids.set(destinationUuidString, destinationUuid);
|
||||
distributionListToSentUuid.set(listId, sentUuids);
|
||||
});
|
||||
} else {
|
||||
|
@ -2232,7 +2232,7 @@ export default class MessageReceiver
|
|||
}
|
||||
|
||||
isAllowedToReply.set(
|
||||
normalizedDestinationUuid,
|
||||
destinationUuidString,
|
||||
recipient.isAllowedToReply !== false
|
||||
);
|
||||
});
|
||||
|
@ -2240,14 +2240,22 @@ export default class MessageReceiver
|
|||
distributionListToSentUuid.forEach((sentToUuids, listId) => {
|
||||
const ev = new SentEvent(
|
||||
{
|
||||
destinationUuid: envelope.destinationUuid.toString(),
|
||||
destinationUuid: {
|
||||
aci: envelope.destinationUuid.toString(),
|
||||
pni: undefined,
|
||||
},
|
||||
timestamp: envelope.timestamp,
|
||||
serverTimestamp: envelope.serverTimestamp,
|
||||
device: envelope.sourceDevice,
|
||||
unidentifiedStatus: Array.from(sentToUuids).map(
|
||||
unidentifiedStatus: Array.from(sentToUuids.values()).map(
|
||||
destinationUuid => ({
|
||||
destinationUuid,
|
||||
isAllowedToReplyToStory: isAllowedToReply.get(destinationUuid),
|
||||
isAllowedToReplyToStory: Boolean(
|
||||
(destinationUuid.aci &&
|
||||
isAllowedToReply.get(destinationUuid.aci)) ||
|
||||
(destinationUuid.pni &&
|
||||
isAllowedToReply.get(destinationUuid.pni))
|
||||
),
|
||||
})
|
||||
),
|
||||
message,
|
||||
|
@ -2867,11 +2875,15 @@ export default class MessageReceiver
|
|||
return undefined;
|
||||
}
|
||||
|
||||
private getDestination(sentMessage: Proto.SyncMessage.ISent) {
|
||||
private getDestination(sentMessage: ProcessedSent) {
|
||||
if (sentMessage.message && sentMessage.message.groupV2) {
|
||||
return `groupv2(${this.getGroupId(sentMessage.message)})`;
|
||||
}
|
||||
return sentMessage.destination || sentMessage.destinationUuid;
|
||||
return (
|
||||
sentMessage.destination ||
|
||||
sentMessage.destinationUuid?.aci ||
|
||||
sentMessage.destinationUuid?.pni
|
||||
);
|
||||
}
|
||||
|
||||
private async handleSyncMessage(
|
||||
|
@ -3067,8 +3079,7 @@ export default class MessageReceiver
|
|||
const ev = new SentEvent(
|
||||
{
|
||||
destination: dropNull(destination),
|
||||
destinationUuid:
|
||||
dropNull(destinationUuid) || envelope.destinationUuid.toString(),
|
||||
destinationUuid,
|
||||
timestamp: envelope.timestamp,
|
||||
serverTimestamp: envelope.serverTimestamp,
|
||||
device: envelope.sourceDevice,
|
||||
|
|
|
@ -17,6 +17,7 @@ import type { ConversationModel } from '../models/conversations';
|
|||
import { GLOBAL_ZONE } from '../SignalProtocolStore';
|
||||
import { assertDev, strictAssert } from '../util/assert';
|
||||
import { parseIntOrThrow } from '../util/parseIntOrThrow';
|
||||
import { getTaggedConversationUuid } from '../util/getConversationUuid';
|
||||
import { Address } from '../types/Address';
|
||||
import { QualifiedAddress } from '../types/QualifiedAddress';
|
||||
import { SenderKeys } from '../LibSignalStores';
|
||||
|
@ -24,7 +25,7 @@ import type {
|
|||
TextAttachmentType,
|
||||
UploadedAttachmentType,
|
||||
} from '../types/Attachment';
|
||||
import type { UUID } from '../types/UUID';
|
||||
import type { UUID, TaggedUUIDStringType } from '../types/UUID';
|
||||
import type {
|
||||
ChallengeType,
|
||||
GetGroupLogOptionsType,
|
||||
|
@ -1205,7 +1206,7 @@ export default class MessageSender {
|
|||
encodedEditMessage?: Uint8Array;
|
||||
timestamp: number;
|
||||
destination: string | undefined;
|
||||
destinationUuid: string | null | undefined;
|
||||
destinationUuid: TaggedUUIDStringType | undefined;
|
||||
expirationStartTimestamp: number | null;
|
||||
conversationIdsSentTo?: Iterable<string>;
|
||||
conversationIdsWithSealedSender?: Set<string>;
|
||||
|
@ -1230,8 +1231,10 @@ export default class MessageSender {
|
|||
if (destination) {
|
||||
sentMessage.destination = destination;
|
||||
}
|
||||
if (destinationUuid) {
|
||||
sentMessage.destinationUuid = destinationUuid;
|
||||
if (destinationUuid?.aci) {
|
||||
sentMessage.destinationAci = destinationUuid.aci;
|
||||
} else if (destinationUuid?.pni) {
|
||||
sentMessage.destinationPni = destinationUuid.pni;
|
||||
}
|
||||
if (expirationStartTimestamp) {
|
||||
sentMessage.expirationStartTimestamp = Long.fromNumber(
|
||||
|
@ -1262,9 +1265,11 @@ export default class MessageSender {
|
|||
if (e164) {
|
||||
status.destination = e164;
|
||||
}
|
||||
const uuid = conv.get('uuid');
|
||||
if (uuid) {
|
||||
status.destinationUuid = uuid;
|
||||
const taggedUuid = getTaggedConversationUuid(conv.attributes);
|
||||
if (taggedUuid?.aci) {
|
||||
status.destinationAci = taggedUuid.aci;
|
||||
} else if (taggedUuid?.pni) {
|
||||
status.destinationPni = taggedUuid.pni;
|
||||
}
|
||||
}
|
||||
status.unidentified =
|
||||
|
|
21
ts/textsecure/Types.d.ts
vendored
21
ts/textsecure/Types.d.ts
vendored
|
@ -3,7 +3,7 @@
|
|||
|
||||
import type { SignalService as Proto } from '../protobuf';
|
||||
import type { IncomingWebSocketRequest } from './WebsocketResources';
|
||||
import type { UUID, UUIDStringType } from '../types/UUID';
|
||||
import type { UUID, UUIDStringType, TaggedUUIDStringType } from '../types/UUID';
|
||||
import type { TextAttachmentType } from '../types/Attachment';
|
||||
import type { GiftBadgeStates } from '../components/conversation/Message';
|
||||
import type { MIMEType } from '../types/MIME';
|
||||
|
@ -222,18 +222,31 @@ export type ProcessedDataMessage = {
|
|||
|
||||
export type ProcessedUnidentifiedDeliveryStatus = Omit<
|
||||
Proto.SyncMessage.Sent.IUnidentifiedDeliveryStatus,
|
||||
'destinationUuid'
|
||||
'destinationAci' | 'destinationPni'
|
||||
> & {
|
||||
destinationUuid?: string;
|
||||
destinationUuid?: TaggedUUIDStringType;
|
||||
isAllowedToReplyToStory?: boolean;
|
||||
};
|
||||
|
||||
export type ProcessedStoryMessageRecipient = Omit<
|
||||
Proto.SyncMessage.Sent.IStoryMessageRecipient,
|
||||
'destinationAci' | 'destinationPni'
|
||||
> & {
|
||||
destinationUuid?: TaggedUUIDStringType;
|
||||
};
|
||||
|
||||
export type ProcessedSent = Omit<
|
||||
Proto.SyncMessage.ISent,
|
||||
'destinationId' | 'unidentifiedStatus'
|
||||
| 'destinationId'
|
||||
| 'unidentifiedStatus'
|
||||
| 'storyMessageRecipients'
|
||||
| 'destinationAci'
|
||||
| 'destinationPni'
|
||||
> & {
|
||||
destinationId?: string;
|
||||
destinationUuid?: TaggedUUIDStringType;
|
||||
unidentifiedStatus?: Array<ProcessedUnidentifiedDeliveryStatus>;
|
||||
storyMessageRecipients?: Array<ProcessedStoryMessageRecipient>;
|
||||
};
|
||||
|
||||
export type ProcessedSyncMessage = Omit<Proto.ISyncMessage, 'sent'> & {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
import type { PublicKey } from '@signalapp/libsignal-client';
|
||||
|
||||
import type { SignalService as Proto } from '../protobuf';
|
||||
import type { UUIDStringType } from '../types/UUID';
|
||||
import type { UUIDStringType, TaggedUUIDStringType } from '../types/UUID';
|
||||
import type {
|
||||
ProcessedEnvelope,
|
||||
ProcessedDataMessage,
|
||||
|
@ -193,7 +193,7 @@ export class RetryRequestEvent extends ConfirmableEvent {
|
|||
|
||||
export type SentEventData = Readonly<{
|
||||
destination?: string;
|
||||
destinationUuid?: string;
|
||||
destinationUuid?: TaggedUUIDStringType;
|
||||
timestamp?: number;
|
||||
serverTimestamp?: number;
|
||||
device: number | undefined;
|
||||
|
|
|
@ -1,30 +1,50 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { SignalService as Proto } from '../protobuf';
|
||||
import type { SignalService as Proto } from '../protobuf';
|
||||
import { normalizeUuid } from '../util/normalizeUuid';
|
||||
import type {
|
||||
ProcessedUnidentifiedDeliveryStatus,
|
||||
ProcessedSent,
|
||||
ProcessedSyncMessage,
|
||||
} from './Types.d';
|
||||
import type { ProcessedSent, ProcessedSyncMessage } from './Types.d';
|
||||
import type { TaggedUUIDStringType } from '../types/UUID';
|
||||
|
||||
import UnidentifiedDeliveryStatus = Proto.SyncMessage.Sent.IUnidentifiedDeliveryStatus;
|
||||
type ProtoUUIDTriple = Readonly<{
|
||||
destinationAci?: string | null;
|
||||
destinationPni?: string | null;
|
||||
}>;
|
||||
|
||||
function processUnidentifiedDeliveryStatus(
|
||||
status: UnidentifiedDeliveryStatus
|
||||
): ProcessedUnidentifiedDeliveryStatus {
|
||||
const { destinationUuid } = status;
|
||||
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;
|
||||
|
||||
return {
|
||||
...status,
|
||||
...remaining,
|
||||
|
||||
destinationUuid: destinationUuid
|
||||
? normalizeUuid(
|
||||
destinationUuid,
|
||||
'syncMessage.sent.unidentifiedStatus.destinationUuid'
|
||||
)
|
||||
: undefined,
|
||||
destinationUuid: toTaggedUuid({
|
||||
destinationAci,
|
||||
destinationPni,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -35,17 +55,26 @@ function processSent(
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const { destinationUuid, unidentifiedStatus } = sent;
|
||||
const {
|
||||
destinationAci,
|
||||
destinationPni,
|
||||
unidentifiedStatus,
|
||||
storyMessageRecipients,
|
||||
...remaining
|
||||
} = sent;
|
||||
|
||||
return {
|
||||
...sent,
|
||||
|
||||
destinationUuid: destinationUuid
|
||||
? normalizeUuid(destinationUuid, 'syncMessage.sent.destinationUuid')
|
||||
: undefined,
|
||||
...remaining,
|
||||
|
||||
destinationUuid: toTaggedUuid({
|
||||
destinationAci,
|
||||
destinationPni,
|
||||
}),
|
||||
unidentifiedStatus: unidentifiedStatus
|
||||
? unidentifiedStatus.map(processUnidentifiedDeliveryStatus)
|
||||
? unidentifiedStatus.map(processProtoWithDestinationUuid)
|
||||
: undefined,
|
||||
storyMessageRecipients: storyMessageRecipients
|
||||
? storyMessageRecipients.map(processProtoWithDestinationUuid)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue