Introduce Service Id Types
Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
parent
414c0a58d3
commit
366b875fd2
269 changed files with 5832 additions and 5550 deletions
|
@ -13,6 +13,8 @@ import {
|
|||
pick,
|
||||
union,
|
||||
} from 'lodash';
|
||||
import { v4 as generateUuid } from 'uuid';
|
||||
|
||||
import type {
|
||||
CustomError,
|
||||
MessageAttributesType,
|
||||
|
@ -40,10 +42,10 @@ import { SendMessageProtoError } from '../textsecure/Errors';
|
|||
import * as expirationTimer from '../util/expirationTimer';
|
||||
import { getUserLanguages } from '../util/userLanguages';
|
||||
import { getMessageSentTimestamp } from '../util/getMessageSentTimestamp';
|
||||
import { getTaggedConversationUuid } from '../util/getConversationUuid';
|
||||
|
||||
import type { ReactionType } from '../types/Reactions';
|
||||
import { UUID, UUIDKind } from '../types/UUID';
|
||||
import type { ServiceIdString } from '../types/ServiceId';
|
||||
import { normalizeServiceId } from '../types/ServiceId';
|
||||
import * as reactionUtil from '../reactions/util';
|
||||
import * as Stickers from '../types/Stickers';
|
||||
import * as Errors from '../types/errors';
|
||||
|
@ -170,7 +172,6 @@ import {
|
|||
queueUpdateMessage,
|
||||
saveNewMessageBatcher,
|
||||
} from '../util/messageBatcher';
|
||||
import { normalizeUuid } from '../util/normalizeUuid';
|
||||
import { getCallHistorySelector } from '../state/selectors/callHistory';
|
||||
import { getConversationSelector } from '../state/selectors/conversations';
|
||||
|
||||
|
@ -343,7 +344,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
shouldSave?: boolean;
|
||||
} = {}
|
||||
): Promise<void> {
|
||||
const ourUuid = window.textsecure.storage.user.getCheckedUuid().toString();
|
||||
const ourAci = window.textsecure.storage.user.getCheckedAci();
|
||||
const storyId = this.get('storyId');
|
||||
if (!storyId) {
|
||||
return;
|
||||
|
@ -377,7 +378,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
},
|
||||
});
|
||||
if (shouldSave) {
|
||||
await window.Signal.Data.saveMessage(this.attributes, { ourUuid });
|
||||
await window.Signal.Data.saveMessage(this.attributes, { ourAci });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -396,7 +397,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
},
|
||||
});
|
||||
if (shouldSave) {
|
||||
await window.Signal.Data.saveMessage(this.attributes, { ourUuid });
|
||||
await window.Signal.Data.saveMessage(this.attributes, { ourAci });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -486,12 +487,8 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
|
||||
const changes = GroupChange.renderChange<string>(change, {
|
||||
i18n: window.i18n,
|
||||
ourACI: window.textsecure.storage.user
|
||||
.getCheckedUuid(UUIDKind.ACI)
|
||||
.toString(),
|
||||
ourPNI: window.textsecure.storage.user
|
||||
.getCheckedUuid(UUIDKind.PNI)
|
||||
.toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
ourPni: window.textsecure.storage.user.getCheckedPni(),
|
||||
renderContact: (conversationId: string) => {
|
||||
const conversation =
|
||||
window.ConversationController.get(conversationId);
|
||||
|
@ -849,13 +846,11 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
});
|
||||
}
|
||||
|
||||
const ourUuid = window.textsecure.storage.user
|
||||
.getCheckedUuid()
|
||||
.toString();
|
||||
const ourAci = window.textsecure.storage.user.getCheckedAci();
|
||||
|
||||
if (
|
||||
attributes.type === 'incoming' &&
|
||||
attributes.storyReaction.targetAuthorUuid === ourUuid
|
||||
attributes.storyReaction.targetAuthorUuid === ourAci
|
||||
) {
|
||||
return window.i18n('icu:Quote__story-reaction-notification--incoming', {
|
||||
emoji: attributes.storyReaction.emoji,
|
||||
|
@ -1149,7 +1144,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
|
||||
if (shouldPersist) {
|
||||
await window.Signal.Data.saveMessage(this.attributes, {
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1281,7 +1276,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
|
||||
if (!skipSave && !this.doNotSave) {
|
||||
await window.Signal.Data.saveMessage(this.attributes, {
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1374,7 +1369,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
async jobToInsert => {
|
||||
await window.Signal.Data.saveMessage(this.attributes, {
|
||||
jobToInsert,
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -1389,7 +1384,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
async jobToInsert => {
|
||||
await window.Signal.Data.saveMessage(this.attributes, {
|
||||
jobToInsert,
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -1462,7 +1457,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
e =>
|
||||
window.ConversationController.getConversationId(
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
e.identifier || e.number!
|
||||
e.serviceId || e.number!
|
||||
) === incomingConversationId &&
|
||||
(e.name === 'MessageError' ||
|
||||
e.name === 'OutgoingMessageError' ||
|
||||
|
@ -1509,7 +1504,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
|
||||
if (!this.doNotSave) {
|
||||
await window.Signal.Data.saveMessage(this.attributes, {
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1522,17 +1517,17 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
const sendIsFinal = !sendIsNotFinal;
|
||||
|
||||
// Capture successful sends
|
||||
const successfulIdentifiers: Array<string> =
|
||||
const successfulServiceIds: Array<ServiceIdString> =
|
||||
sendIsFinal &&
|
||||
'successfulIdentifiers' in result.value &&
|
||||
Array.isArray(result.value.successfulIdentifiers)
|
||||
? result.value.successfulIdentifiers
|
||||
'successfulServiceIds' in result.value &&
|
||||
Array.isArray(result.value.successfulServiceIds)
|
||||
? result.value.successfulServiceIds
|
||||
: [];
|
||||
const sentToAtLeastOneRecipient =
|
||||
result.success || Boolean(successfulIdentifiers.length);
|
||||
result.success || Boolean(successfulServiceIds.length);
|
||||
|
||||
successfulIdentifiers.forEach(identifier => {
|
||||
const conversation = window.ConversationController.get(identifier);
|
||||
successfulServiceIds.forEach(serviceId => {
|
||||
const conversation = window.ConversationController.get(serviceId);
|
||||
if (!conversation) {
|
||||
return;
|
||||
}
|
||||
|
@ -1588,7 +1583,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
|
||||
errors.forEach(error => {
|
||||
const conversation =
|
||||
window.ConversationController.get(error.identifier) ||
|
||||
window.ConversationController.get(error.serviceId) ||
|
||||
window.ConversationController.get(error.number);
|
||||
|
||||
if (conversation && !saveErrors && sendIsFinal) {
|
||||
|
@ -1663,7 +1658,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
|
||||
if (!this.doNotSave) {
|
||||
await window.Signal.Data.saveMessage(this.attributes, {
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1726,7 +1721,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
throw error;
|
||||
} finally {
|
||||
await window.Signal.Data.saveMessage(this.attributes, {
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
|
||||
if (updateLeftPane) {
|
||||
|
@ -1809,7 +1804,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
...encodedContent,
|
||||
timestamp,
|
||||
destination: conv.get('e164'),
|
||||
destinationUuid: getTaggedConversationUuid(conv.attributes),
|
||||
destinationServiceId: conv.getServiceId(),
|
||||
expirationStartTimestamp:
|
||||
this.get('expirationStartTimestamp') || null,
|
||||
conversationIdsSentTo,
|
||||
|
@ -1856,7 +1851,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
}
|
||||
|
||||
await window.Signal.Data.saveMessage(this.attributes, {
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
return result;
|
||||
});
|
||||
|
@ -2078,7 +2073,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
);
|
||||
originalMessage.set(upgradedMessage);
|
||||
await window.Signal.Data.saveMessage(upgradedMessage, {
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
|
@ -2206,17 +2201,15 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
: [];
|
||||
|
||||
unidentifiedStatus.forEach(
|
||||
({ destinationUuid, destination, unidentified }) => {
|
||||
const identifier =
|
||||
destinationUuid?.aci || destinationUuid?.pni || destination;
|
||||
({ destinationServiceId, destination, unidentified }) => {
|
||||
const identifier = destinationServiceId || destination;
|
||||
if (!identifier) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { conversation: destinationConversation } =
|
||||
window.ConversationController.maybeMergeContacts({
|
||||
aci: destinationUuid?.aci,
|
||||
pni: destinationUuid?.pni,
|
||||
const destinationConversation =
|
||||
window.ConversationController.lookupOrCreate({
|
||||
uuid: destinationServiceId,
|
||||
e164: destination || undefined,
|
||||
reason: `handleDataMessage(${initialMessage.timestamp})`,
|
||||
});
|
||||
|
@ -2255,7 +2248,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
unidentifiedDeliveries: [...unidentifiedDeliveriesSet],
|
||||
});
|
||||
await window.Signal.Data.saveMessage(toUpdate.attributes, {
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
|
||||
confirm();
|
||||
|
@ -2346,9 +2339,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
}
|
||||
}
|
||||
|
||||
const ourACI = window.textsecure.storage.user.getCheckedUuid(
|
||||
UUIDKind.ACI
|
||||
);
|
||||
const ourAci = window.textsecure.storage.user.getCheckedAci();
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const sender = window.ConversationController.lookupOrCreate({
|
||||
e164: source,
|
||||
|
@ -2371,7 +2362,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
}
|
||||
|
||||
const areWeMember =
|
||||
!conversation.get('left') && conversation.hasMember(ourACI);
|
||||
!conversation.get('left') && conversation.hasMember(ourAci);
|
||||
|
||||
// Drop an incoming GroupV2 message if we or the sender are not part of the group
|
||||
// after applying the message's associated group changes.
|
||||
|
@ -2379,8 +2370,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
type === 'incoming' &&
|
||||
!isDirectConversation(conversation.attributes) &&
|
||||
hasGroupV2Prop &&
|
||||
(!areWeMember ||
|
||||
(sourceUuid && !conversation.hasMember(new UUID(sourceUuid))))
|
||||
(!areWeMember || (sourceUuid && !conversation.hasMember(sourceUuid)))
|
||||
) {
|
||||
log.warn(
|
||||
`${idLog}: Received message destined for group, which we or the sender are not a part of. Dropping.`
|
||||
|
@ -2409,15 +2399,15 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
}
|
||||
|
||||
// Drop incoming messages to announcement only groups where sender is not admin
|
||||
if (
|
||||
conversation.get('announcementsOnly') &&
|
||||
!conversation.isAdmin(UUID.checkedLookup(sender?.id))
|
||||
) {
|
||||
confirm();
|
||||
return;
|
||||
if (conversation.get('announcementsOnly')) {
|
||||
const senderServiceId = sender.getServiceId();
|
||||
if (!senderServiceId || !conversation.isAdmin(senderServiceId)) {
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const messageId = message.get('id') || UUID.generate().toString();
|
||||
const messageId = message.get('id') || generateUuid();
|
||||
|
||||
// Send delivery receipts, but only for non-story sealed sender messages
|
||||
// and not for messages from unaccepted conversations
|
||||
|
@ -2451,7 +2441,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
if (storyContext) {
|
||||
storyContextLogId =
|
||||
`storyContext(${storyContext.sentTimestamp}, ` +
|
||||
`${storyContext.authorUuid})`;
|
||||
`${storyContext.authorAci})`;
|
||||
}
|
||||
|
||||
const [quote, storyQuotes] = await Promise.all([
|
||||
|
@ -2466,7 +2456,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
|
||||
const storyQuoteIsFromSelf =
|
||||
candidateQuote.get('sourceUuid') ===
|
||||
window.storage.user.getCheckedUuid().toString();
|
||||
window.storage.user.getCheckedAci();
|
||||
|
||||
if (!storyQuoteIsFromSelf) {
|
||||
return true;
|
||||
|
@ -2581,13 +2571,8 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
);
|
||||
}
|
||||
|
||||
const ourPNI = window.textsecure.storage.user.getCheckedUuid(
|
||||
UUIDKind.PNI
|
||||
);
|
||||
const ourUuids: Set<string> = new Set([
|
||||
ourACI.toString(),
|
||||
ourPNI.toString(),
|
||||
]);
|
||||
const ourPni = window.textsecure.storage.user.getCheckedPni();
|
||||
const ourUuids: Set<ServiceIdString> = new Set([ourAci, ourPni]);
|
||||
|
||||
message.set({
|
||||
id: messageId,
|
||||
|
@ -2609,7 +2594,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
return false;
|
||||
}
|
||||
return ourUuids.has(
|
||||
normalizeUuid(
|
||||
normalizeServiceId(
|
||||
bodyRange.mentionUuid,
|
||||
'handleDataMessage: mentionsMe check'
|
||||
)
|
||||
|
@ -2737,8 +2722,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
const { profileKey } = initialMessage;
|
||||
if (
|
||||
source === window.textsecure.storage.user.getNumber() ||
|
||||
sourceUuid ===
|
||||
window.textsecure.storage.user.getUuid()?.toString()
|
||||
sourceUuid === window.textsecure.storage.user.getAci()
|
||||
) {
|
||||
conversation.set({ profileSharing: true });
|
||||
} else if (isDirectConversation(conversation.attributes)) {
|
||||
|
@ -3026,7 +3010,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
});
|
||||
// Note: generatedMessage comes with an id, so we have to force this save
|
||||
await window.Signal.Data.saveMessage(generatedMessage.attributes, {
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
forceSave: true,
|
||||
});
|
||||
|
||||
|
@ -3112,7 +3096,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
await window.Signal.Data.removeReactionFromConversation({
|
||||
emoji: reaction.get('emoji'),
|
||||
fromId: reaction.get('fromId'),
|
||||
targetAuthorUuid: reaction.get('targetAuthorUuid'),
|
||||
targetAuthorServiceId: reaction.get('targetAuthorUuid'),
|
||||
targetTimestamp: reaction.get('targetTimestamp'),
|
||||
});
|
||||
} else {
|
||||
|
@ -3182,7 +3166,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
shouldSave: false,
|
||||
});
|
||||
await window.Signal.Data.saveMessage(generatedMessage.attributes, {
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
forceSave: true,
|
||||
});
|
||||
|
||||
|
@ -3216,7 +3200,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
);
|
||||
await window.Signal.Data.saveMessage(this.attributes, {
|
||||
jobToInsert,
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
});
|
||||
} else {
|
||||
|
@ -3224,7 +3208,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
}
|
||||
} else if (shouldPersist && !isStory(this.attributes)) {
|
||||
await window.Signal.Data.saveMessage(this.attributes, {
|
||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue