Skip to content

Commit

Permalink
Refactor SendMessage.ts to named parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Jul 2, 2021
1 parent 5693319 commit 615ae1c
Show file tree
Hide file tree
Showing 9 changed files with 539 additions and 469 deletions.
6 changes: 3 additions & 3 deletions ts/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ export async function startApp(): Promise<void> {
} = await window.ConversationController.prepareForSend(c.get('id'));
// eslint-disable-next-line no-await-in-loop
await wrap(
window.textsecure.messaging.sendDeliveryReceipt(
window.textsecure.messaging.sendDeliveryReceipt({
e164,
uuid,
timestamps,
sendOptions
)
options: sendOptions,
})
);
} catch (error) {
window.log.error(
Expand Down
48 changes: 23 additions & 25 deletions ts/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1298,8 +1298,8 @@ export async function modifyGroupV2({
const { ContentHint } = Proto.UnidentifiedSenderMessage.Message;

const promise = handleMessageSend(
window.Signal.Util.sendToGroup(
{
window.Signal.Util.sendToGroup({
groupSendOptions: {
groupV2: conversation.getGroupV2Info({
groupChange: typedArrayToArrayBuffer(groupChangeBuffer),
includePendingMembers: true,
Expand All @@ -1309,9 +1309,9 @@ export async function modifyGroupV2({
profileKey,
},
conversation,
ContentHint.DEFAULT,
sendOptions
)
contentHint: ContentHint.DEFAULT,
sendOptions,
})
);

// We don't save this message; we just use it to ensure that a sync message is
Expand Down Expand Up @@ -1676,16 +1676,16 @@ export async function createGroupV2({
conversation,
logId: `sendToGroup/${logId}`,
send: async () =>
window.Signal.Util.sendToGroup(
{
window.Signal.Util.sendToGroup({
groupSendOptions: {
groupV2: groupV2Info,
timestamp,
profileKey,
},
conversation,
ContentHint.DEFAULT,
sendOptions
),
contentHint: ContentHint.DEFAULT,
sendOptions,
}),
timestamp,
});

Expand Down Expand Up @@ -2207,18 +2207,18 @@ export async function initiateMigrationToGroupV2(
logId: `sendToGroup/${logId}`,
send: async () =>
// Minimal message to notify group members about migration
window.Signal.Util.sendToGroup(
{
window.Signal.Util.sendToGroup({
groupSendOptions: {
groupV2: conversation.getGroupV2Info({
includePendingMembers: true,
}),
timestamp,
profileKey: ourProfileKey,
},
conversation,
ContentHint.DEFAULT,
sendOptions
),
contentHint: ContentHint.DEFAULT,
sendOptions,
}),
timestamp,
});
}
Expand Down Expand Up @@ -2278,17 +2278,15 @@ export async function wrapWithSyncMessageSend({
);
}

await sender.sendSyncMessage(
dataMessage,
await sender.sendSyncMessage({
encodedDataMessage: dataMessage,
timestamp,
ourConversation.get('e164'),
ourConversation.get('uuid'),
null, // expirationStartTimestamp
[], // sentTo
[], // unidentifiedDeliveries
undefined, // isUpdate
undefined // options
);
destination: ourConversation.get('e164'),
destinationUuid: ourConversation.get('uuid'),
expirationStartTimestamp: null,
sentTo: [],
unidentifiedDeliveries: [],
});
}

export async function waitThenRespondToGroupV2Migration(
Expand Down
132 changes: 66 additions & 66 deletions ts/models/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand All @@ -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));
Expand Down Expand Up @@ -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(),
Expand All @@ -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));
Expand Down

0 comments on commit 615ae1c

Please sign in to comment.