|
|
|
@ -736,10 +736,25 @@
|
|
|
|
|
const quoteWithData = await loadQuoteData(this.get('quote'));
|
|
|
|
|
const previewWithData = await loadPreviewData(this.get('preview'));
|
|
|
|
|
|
|
|
|
|
const conversation = this.getConversation();
|
|
|
|
|
const options = conversation.getSendOptions();
|
|
|
|
|
// Special-case the self-send case - we send only a sync message
|
|
|
|
|
if (numbers.length === 1 && numbers[0] === this.OUR_NUMBER) {
|
|
|
|
|
const [number] = numbers;
|
|
|
|
|
const dataMessage = await textsecure.messaging.getMessageProto(
|
|
|
|
|
number,
|
|
|
|
|
this.get('body'),
|
|
|
|
|
attachmentsWithData,
|
|
|
|
|
quoteWithData,
|
|
|
|
|
previewWithData,
|
|
|
|
|
this.get('sent_at'),
|
|
|
|
|
this.get('expireTimer'),
|
|
|
|
|
profileKey
|
|
|
|
|
);
|
|
|
|
|
return this.sendSyncMessageOnly(dataMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let promise;
|
|
|
|
|
const conversation = this.getConversation();
|
|
|
|
|
const options = conversation.getSendOptions();
|
|
|
|
|
|
|
|
|
|
if (conversation.isPrivate()) {
|
|
|
|
|
const [number] = numbers;
|
|
|
|
@ -794,7 +809,11 @@
|
|
|
|
|
// One caller today: ConversationView.forceSend()
|
|
|
|
|
async resend(number) {
|
|
|
|
|
const error = this.removeOutgoingErrors(number);
|
|
|
|
|
if (error) {
|
|
|
|
|
if (!error) {
|
|
|
|
|
window.log.warn('resend: requested number was not present in errors');
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const profileKey = null;
|
|
|
|
|
const attachmentsWithData = await Promise.all(
|
|
|
|
|
(this.get('attachments') || []).map(loadAttachmentData)
|
|
|
|
@ -802,6 +821,21 @@
|
|
|
|
|
const quoteWithData = await loadQuoteData(this.get('quote'));
|
|
|
|
|
const previewWithData = await loadPreviewData(this.get('preview'));
|
|
|
|
|
|
|
|
|
|
// Special-case the self-send case - we send only a sync message
|
|
|
|
|
if (number === this.OUR_NUMBER) {
|
|
|
|
|
const dataMessage = await textsecure.messaging.getMessageProto(
|
|
|
|
|
number,
|
|
|
|
|
this.get('body'),
|
|
|
|
|
attachmentsWithData,
|
|
|
|
|
quoteWithData,
|
|
|
|
|
previewWithData,
|
|
|
|
|
this.get('sent_at'),
|
|
|
|
|
this.get('expireTimer'),
|
|
|
|
|
profileKey
|
|
|
|
|
);
|
|
|
|
|
return this.sendSyncMessageOnly(dataMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { wrap, sendOptions } = ConversationController.prepareForSend(
|
|
|
|
|
number
|
|
|
|
|
);
|
|
|
|
@ -817,8 +851,7 @@
|
|
|
|
|
sendOptions
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
this.send(wrap(promise));
|
|
|
|
|
}
|
|
|
|
|
return this.send(wrap(promise));
|
|
|
|
|
},
|
|
|
|
|
removeOutgoingErrors(number) {
|
|
|
|
|
const errors = _.partition(
|
|
|
|
@ -912,7 +945,7 @@
|
|
|
|
|
this.trigger('done');
|
|
|
|
|
|
|
|
|
|
// This is used by sendSyncMessage, then set to null
|
|
|
|
|
if (result.dataMessage) {
|
|
|
|
|
if (!this.get('synced') && result.dataMessage) {
|
|
|
|
|
this.set({ dataMessage: result.dataMessage });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1013,6 +1046,35 @@
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async sendSyncMessageOnly(dataMessage) {
|
|
|
|
|
this.set({ dataMessage });
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await this.sendSyncMessage();
|
|
|
|
|
this.set({
|
|
|
|
|
delivered_to: [this.OUR_NUMBER],
|
|
|
|
|
read_by: [this.OUR_NUMBER],
|
|
|
|
|
});
|
|
|
|
|
} catch (result) {
|
|
|
|
|
const errors = (result && result.errors) || [
|
|
|
|
|
new Error('Unknown error'),
|
|
|
|
|
];
|
|
|
|
|
this.set({ errors });
|
|
|
|
|
} finally {
|
|
|
|
|
await window.Signal.Data.saveMessage(this.attributes, {
|
|
|
|
|
Message: Whisper.Message,
|
|
|
|
|
});
|
|
|
|
|
this.trigger('done');
|
|
|
|
|
|
|
|
|
|
const errors = this.get('errors');
|
|
|
|
|
if (errors) {
|
|
|
|
|
this.trigger('send-error', errors);
|
|
|
|
|
} else {
|
|
|
|
|
this.trigger('sent');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
sendSyncMessage() {
|
|
|
|
|
const ourNumber = textsecure.storage.user.getNumber();
|
|
|
|
|
const { wrap, sendOptions } = ConversationController.prepareForSend(
|
|
|
|
@ -1021,7 +1083,7 @@
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
this.syncPromise = this.syncPromise || Promise.resolve();
|
|
|
|
|
this.syncPromise = this.syncPromise.then(() => {
|
|
|
|
|
const next = () => {
|
|
|
|
|
const dataMessage = this.get('dataMessage');
|
|
|
|
|
if (this.get('synced') || !dataMessage) {
|
|
|
|
|
return Promise.resolve();
|
|
|
|
@ -1036,16 +1098,20 @@
|
|
|
|
|
this.get('unidentifiedDeliveries'),
|
|
|
|
|
sendOptions
|
|
|
|
|
)
|
|
|
|
|
).then(() => {
|
|
|
|
|
).then(result => {
|
|
|
|
|
this.set({
|
|
|
|
|
synced: true,
|
|
|
|
|
dataMessage: null,
|
|
|
|
|
});
|
|
|
|
|
return window.Signal.Data.saveMessage(this.attributes, {
|
|
|
|
|
Message: Whisper.Message,
|
|
|
|
|
}).then(() => result);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.syncPromise = this.syncPromise.then(next, next);
|
|
|
|
|
|
|
|
|
|
return this.syncPromise;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async saveErrors(providedErrors) {
|
|
|
|
@ -1312,6 +1378,14 @@
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A sync'd message to ourself is automatically considered read and delivered
|
|
|
|
|
if (conversation.isMe()) {
|
|
|
|
|
message.set({
|
|
|
|
|
read_by: conversation.getRecipients(),
|
|
|
|
|
delivered_to: conversation.getRecipients(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
message.set({ recipients: conversation.getRecipients() });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|