Refactor SendMessage.ts to named parameters

This commit is contained in:
Scott Nonnenberg 2021-07-02 11:34:17 -07:00 committed by GitHub
parent 56933192ba
commit 615ae1ccf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 540 additions and 470 deletions

View file

@ -1186,20 +1186,21 @@ export class ConversationModel extends window.Backbone
const {
ContentHint,
} = window.textsecure.protobuf.UnidentifiedSenderMessage.Message;
const sendOptions = await getSendOptions(this.attributes);
if (isDirectConversation(this.attributes)) {
handleMessageSend(
window.textsecure.messaging.sendMessageProtoAndWait(
window.textsecure.messaging.sendMessageProtoAndWait({
timestamp,
groupMembers,
contentMessage,
ContentHint.IMPLICIT,
undefined,
{
recipients: groupMembers,
proto: contentMessage,
contentHint: ContentHint.IMPLICIT,
groupId: undefined,
options: {
...sendOptions,
online: true,
}
)
},
})
);
} else {
handleMessageSend(
@ -3204,7 +3205,7 @@ export class ConversationModel extends window.Backbone
throw new Error('Cannot send DOE while offline!');
}
const options = await getSendOptions(this.attributes);
const sendOptions = await getSendOptions(this.attributes);
const promise = (async () => {
let profileKey: ArrayBuffer | undefined;
@ -3217,36 +3218,36 @@ export class ConversationModel extends window.Backbone
} = window.textsecure.protobuf.UnidentifiedSenderMessage.Message;
if (isDirectConversation(this.attributes)) {
return window.textsecure.messaging.sendMessageToIdentifier(
destination,
undefined, // body
[], // attachments
undefined, // quote
[], // preview
undefined, // sticker
undefined, // reaction
targetTimestamp,
return window.textsecure.messaging.sendMessageToIdentifier({
identifier: destination,
messageText: undefined,
attachments: [],
quote: undefined,
preview: [],
sticker: undefined,
reaction: undefined,
deletedForEveryoneTimestamp: targetTimestamp,
timestamp,
undefined, // expireTimer
ContentHint.DEFAULT,
undefined, // groupId
expireTimer: undefined,
contentHint: ContentHint.DEFAULT,
groupId: undefined,
profileKey,
options
);
options: sendOptions,
});
}
return window.Signal.Util.sendToGroup(
{
return window.Signal.Util.sendToGroup({
groupSendOptions: {
groupV1: this.getGroupV1Info(),
groupV2: this.getGroupV2Info(),
deletedForEveryoneTimestamp: targetTimestamp,
timestamp,
profileKey,
},
this,
ContentHint.DEFAULT,
options
);
conversation: this,
contentHint: ContentHint.DEFAULT,
sendOptions,
});
})();
// This is to ensure that the functions in send() and sendSyncMessage() don't save
@ -3341,7 +3342,6 @@ export class ConversationModel extends window.Backbone
if (this.get('profileSharing')) {
profileKey = await ourProfileKeyService.get();
}
// Special-case the self-send case - we send only a sync message
if (isMe(this.attributes)) {
const dataMessage = await window.textsecure.messaging.getDataMessage({
@ -3369,26 +3369,26 @@ export class ConversationModel extends window.Backbone
const promise = (() => {
if (isDirectConversation(this.attributes)) {
return window.textsecure.messaging.sendMessageToIdentifier(
destination,
undefined, // body
[], // attachments
undefined, // quote
[], // preview
undefined, // sticker
outgoingReaction,
undefined, // deletedForEveryoneTimestamp
return window.textsecure.messaging.sendMessageToIdentifier({
identifier: destination,
messageText: undefined,
attachments: [],
quote: undefined,
preview: [],
sticker: undefined,
reaction: outgoingReaction,
deletedForEveryoneTimestamp: undefined,
timestamp,
expireTimer,
ContentHint.DEFAULT,
undefined, // groupId
contentHint: ContentHint.DEFAULT,
groupId: undefined,
profileKey,
options
);
options,
});
}
return window.Signal.Util.sendToGroup(
{
return window.Signal.Util.sendToGroup({
groupSendOptions: {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
groupV1: this.getGroupV1Info()!,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@ -3398,10 +3398,10 @@ export class ConversationModel extends window.Backbone
expireTimer,
profileKey,
},
this,
ContentHint.DEFAULT,
options
);
conversation: this,
contentHint: ContentHint.DEFAULT,
sendOptions: options,
});
})();
const result = await message.send(handleMessageSend(promise));
@ -3627,8 +3627,8 @@ export class ConversationModel extends window.Backbone
let promise;
if (conversationType === Message.GROUP) {
promise = window.Signal.Util.sendToGroup(
{
promise = window.Signal.Util.sendToGroup({
groupSendOptions: {
attachments: finalAttachments,
expireTimer,
groupV1: this.getGroupV1Info(),
@ -3641,27 +3641,27 @@ export class ConversationModel extends window.Backbone
timestamp: now,
mentions,
},
this,
ContentHint.RESENDABLE,
options
);
conversation: this,
contentHint: ContentHint.RESENDABLE,
sendOptions: options,
});
} else {
promise = window.textsecure.messaging.sendMessageToIdentifier(
destination,
messageBody,
finalAttachments,
promise = window.textsecure.messaging.sendMessageToIdentifier({
identifier: destination,
messageText: messageBody,
attachments: finalAttachments,
quote,
preview,
sticker,
null, // reaction
undefined, // deletedForEveryoneTimestamp
now,
reaction: null,
deletedForEveryoneTimestamp: undefined,
timestamp: now,
expireTimer,
ContentHint.RESENDABLE,
undefined, // groupId
contentHint: ContentHint.RESENDABLE,
groupId: undefined,
profileKey,
options
);
options,
});
}
return message.send(handleMessageSend(promise));

View file

@ -1278,6 +1278,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
sticker: stickerWithData,
timestamp: this.get('sent_at'),
});
return this.sendSyncMessageOnly(dataMessage);
}
@ -1290,22 +1291,23 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
if (isDirectConversation(conversation.attributes)) {
const [identifier] = recipients;
promise = window.textsecure.messaging.sendMessageToIdentifier(
promise = window.textsecure.messaging.sendMessageToIdentifier({
identifier,
body,
messageText: body,
attachments,
quoteWithData,
previewWithData,
stickerWithData,
null,
this.get('deletedForEveryoneTimestamp'),
this.get('sent_at'),
this.get('expireTimer'),
ContentHint.RESENDABLE,
undefined, // groupId
quote: quoteWithData,
preview: previewWithData,
sticker: stickerWithData,
reaction: null,
deletedForEveryoneTimestamp: this.get('deletedForEveryoneTimestamp'),
timestamp: this.get('sent_at'),
expireTimer: this.get('expireTimer'),
contentHint: ContentHint.RESENDABLE,
groupId: undefined,
profileKey,
options
);
options,
});
} else {
const initialGroupV2 = conversation.getGroupV2Info();
const groupId = conversation.get('groupId');
@ -1326,12 +1328,8 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
members: recipients,
};
// Important to ensure that we don't consider this receipient list to be the entire
// member list.
const partialSend = true;
promise = window.Signal.Util.sendToGroup(
{
promise = window.Signal.Util.sendToGroup({
groupSendOptions: {
messageText: body,
timestamp: this.get('sent_at'),
attachments,
@ -1345,10 +1343,12 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
groupV1,
},
conversation,
ContentHint.RESENDABLE,
options,
partialSend
);
contentHint: ContentHint.RESENDABLE,
// Important to ensure that we don't consider this recipient list to be the
// entire member list.
isPartialSend: true,
sendOptions: options,
});
}
return this.send(handleMessageSend(promise));
@ -1423,6 +1423,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
sticker: stickerWithData,
timestamp: this.get('sent_at'),
});
return this.sendSyncMessageOnly(dataMessage);
}
@ -1465,7 +1466,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
senderKeyInfo.distributionId
);
window.dcodeIO.ByteBuffer.wrap(
contentMessage.senderKeyDistributionMessage = window.dcodeIO.ByteBuffer.wrap(
window.Signal.Crypto.typedArrayToArrayBuffer(
senderKeyDistributionMessage.serialize()
)
@ -1473,16 +1474,17 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
}
}
const promise = window.textsecure.messaging.sendMessageProtoAndWait(
const promise = window.textsecure.messaging.sendMessageProtoAndWait({
timestamp,
[identifier],
contentMessage,
ContentHint.RESENDABLE,
groupId && isGroupV2(parentConversation?.attributes)
? groupId
: undefined,
sendOptions
);
recipients: [identifier],
proto: contentMessage,
contentHint: ContentHint.RESENDABLE,
groupId:
groupId && isGroupV2(parentConversation?.attributes)
? groupId
: undefined,
options: sendOptions,
});
return this.send(wrap(promise));
}
@ -1780,18 +1782,18 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
const conv = this.getConversation()!;
return wrap(
window.textsecure.messaging.sendSyncMessage(
dataMessage,
this.get('sent_at'),
conv.get('e164'),
conv.get('uuid'),
this.get('expirationStartTimestamp') || null,
this.get('sent_to'),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.get('unidentifiedDeliveries')!,
window.textsecure.messaging.sendSyncMessage({
encodedDataMessage: dataMessage,
timestamp: this.get('sent_at'),
destination: conv.get('e164'),
destinationUuid: conv.get('uuid'),
expirationStartTimestamp:
this.get('expirationStartTimestamp') || null,
sentTo: this.get('sent_to') || [],
unidentifiedDeliveries: this.get('unidentifiedDeliveries') || [],
isUpdate,
sendOptions
)
options: sendOptions,
})
).then(async (result: unknown) => {
this.set({
synced: true,