Add sendSyncMessageOnly

pull/1203/head
Mikunj 5 years ago
parent d4dc8aa2ed
commit 1bd1548172

@ -1648,8 +1648,10 @@
};
if (this.isMe()) {
await message.markMessageSyncOnly();
// sending of the message is handled in the 'private' case below
const expirationTimerMessage = new libsession.Messages.Outgoing.ExpirationTimerUpdateMessage(
expireUpdate
);
return message.sendSyncMessageOnly(expirationTimerMessage);
}
if (this.get('type') === 'private') {

@ -1079,8 +1079,7 @@
if (recipients.length === 1 && recipients[0] === this.OUR_NUMBER) {
this.trigger('pending');
// FIXME audric add back profileKey
await this.markMessageSyncOnly();
// sending is done in the private case below
return this.sendSyncMessageOnly(chatMessage);
}
if (conversation.isPrivate()) {
@ -1155,9 +1154,9 @@
// Special-case the self-send case - we send only a sync message
if (number === this.OUR_NUMBER) {
await this.markMessageSyncOnly();
// sending is done in the private case below
return this.sendSyncMessageOnly(chatMessage);
}
const conversation = this.getConversation();
const recipientPubKey = new libsession.Types.PubKey(number);
@ -1316,6 +1315,43 @@
Message: Whisper.Message,
});
},
async sendSyncMessageOnly(dataMessage) {
this.set({
sent_to: [this.OUR_NUMBER],
sent: true,
expirationStartTimestamp: Date.now(),
});
await window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message,
});
const data =
dataMessage instanceof libsession.Message.Outgoing.DataMessage
? dataMessage.dataProto()
: dataMessage;
await this.sendSyncMessage(data);
},
async sendSyncMessage(dataMessage) {
// TODO: Return here if we've already sent a sync message
if (this.get('synced')) {
return;
}
const syncMessage = new libsession.Message.Outgoing.SentSyncMessage({
timestamp: this.get('sent_at'),
dataMessage,
destination: this.id,
expirationStartTimestamp: this.get('expirationStartTimestamp'),
sent_to: this.get('sent_to'),
unidentifiedDeliveries: this.get('unidentifiedDeliveries'),
});
await libsession.getMessageQueue().sendSyncMessage(syncMessage);
},
send(promise) {
this.trigger('pending');
return promise

Loading…
Cancel
Save