diff --git a/js/models/conversations.js b/js/models/conversations.js index a99ccbccc..3b99c6bda 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1205,10 +1205,10 @@ const expireTimer = this.get('expireTimer'); const recipients = this.getRecipients(); - let profileKey; - if (this.get('profileSharing')) { - profileKey = storage.get('profileKey'); - } + // let profileKey; + // if (this.get('profileSharing')) { + // profileKey = storage.get('profileKey'); + // } this.queueJob(async () => { const now = Date.now(); @@ -1304,19 +1304,22 @@ now, }); + // FIXME audric add back profileKey + const chatMessage = new libsession.Messages.Outgoing.ChatMessage({ + body: messageBody, + timestamp: Date.now(), + attachments: finalAttachments, + expireTimer, + preview, + quote, + }); + // Start handle ChatMessages (attachments/quote/preview/body) + // FIXME AUDRIC handle attachments, quote, preview, profileKey + // Special-case the self-send case - we send only a sync message if (this.isMe()) { - const dataMessage = await textsecure.messaging.getMessageProto( - destination, - messageBody, - finalAttachments, - quote, - preview, - now, - expireTimer, - profileKey - ); - return message.sendSyncMessageOnly(dataMessage); + await message.markMessageSyncOnly(); + return libsession.getMessageQueue().sendSyncMessage(chatMessage); } const options = {}; @@ -1364,42 +1367,14 @@ .getMessageQueue() .sendUsingMultiDevice(destinationPubkey, groupInvitMessage); } - const chatMessage = new libsession.Messages.Outgoing.ChatMessage({ - body, - timestamp: Date.now(), - }); - // Start handle ChatMessages (attachments/quote/preview/body) - // FIXME AUDRIC handle attachments, quote, preview + if (conversationType === Message.PRIVATE) { - await libsession + return libsession .getMessageQueue() .sendUsingMultiDevice(destinationPubkey, chatMessage); + } - // return textsecure.messaging.sendMessageToNumber( - // destination, - // messageBody, - // finalAttachments, - // quote, - // preview, - // now, - // expireTimer, - // profileKey, - // {} - // ); - } else if (conversationType === Message.GROUP) { - // return textsecure.messaging.sendMessageToGroup( - // dest, - // numbers, - // messageBody, - // finalAttachments, - // quote, - // preview, - // now, - // expireTimer, - // profileKey, - // {} - // ); - + if (conversationType === Message.GROUP) { // let dest = destination; // let numbers = groupNumbers; if (this.isMediumGroup()) { @@ -1408,7 +1383,7 @@ // dest = this.id; // numbers = [destination]; // options.isMediumGroup = true; - throw new Error('To implement'); + throw new Error('To implement back'); } else { const closedGroupChatMessage = new libsession.Messages.Outgoing.ClosedGroupChatMessage( { @@ -1658,28 +1633,22 @@ profileKey = storage.get('profileKey'); } - if (this.isMe()) { - const flags = - textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE; - const dataMessage = await textsecure.messaging.getMessageProto( - this.get('id'), - null, - [], - null, - [], - message.get('sent_at'), - expireTimer, - profileKey, - flags - ); - return message.sendSyncMessageOnly(dataMessage); - } const expireUpdate = { timestamp: message.get('sent_at'), expireTimer, profileKey, }; + if (this.isMe()) { + const expirationTimerMessage = new libsession.Messages.Outgoing.ExpirationTimerUpdateMessage( + expireUpdate + ); + await message.markMessageSyncOnly(); + return libsession + .getMessageQueue() + .sendSyncMessage(expirationTimerMessage); + } + if (this.get('type') === 'private') { const expirationTimerMessage = new libsession.Messages.Outgoing.ExpirationTimerUpdateMessage( expireUpdate diff --git a/js/models/messages.js b/js/models/messages.js index cdb5fa3b4..343db5831 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -1043,6 +1043,7 @@ if (recipients.length === 1 && recipients[0] === this.OUR_NUMBER) { this.trigger('pending'); // FIXME audric add back profileKey + await this.markMessageSyncOnly(); return libsession.getMessageQueue().sendSyncMessage(chatMessage); } @@ -1055,8 +1056,7 @@ .getMessageQueue() .sendUsingMultiDevice(recipientPubKey, chatMessage); } - // Because this is a partial group send, we manually construct the request like - // sendMessageToGroup does. + this.trigger('pending'); // TODO should we handle open groups message here too? // Not sure there is the concept of retrySend for those @@ -1066,7 +1066,16 @@ groupId: this.get('conversationId'), } ); - return libsession.getMessageQueue().sendToGroup(closedGroupChatMessage); + // Because this is a partial group send, we send the message with the groupId field set, but individually + // to each recipient listed + return Promise.all( + recipients.map(async r => { + const recipientPubKey = new libsession.Types.PubKey(r); + return libsession + .getMessageQueue() + .sendUsingMultiDevice(recipientPubKey, closedGroupChatMessage); + }) + ); }, isReplayableError(e) { return ( @@ -1113,6 +1122,7 @@ // Special-case the self-send case - we send only a sync message if (number === this.OUR_NUMBER) { this.trigger('pending'); + await this.markMessageSyncOnly(); return libsession.getMessageQueue().sendSyncMessage(chatMessage); } const conversation = this.getConversation(); @@ -1387,46 +1397,21 @@ return false; }, - async sendSyncMessageOnly(dataMessage) { - this.set({ dataMessage }); - - try { - this.set({ - // These are the same as a normal send() - sent_to: [this.OUR_NUMBER], - sent: true, - expirationStartTimestamp: Date.now(), - }); - const result = await this.sendSyncMessage(); - this.set({ - // We have to do this afterward, since we didn't have a previous send! - unidentifiedDeliveries: result ? result.unidentifiedDeliveries : null, - - // These are unique to a Note to Self message - immediately read/delivered - 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'); + async markMessageSyncOnly(dataMessage) { + this.set({ + // These are the same as a normal send() + dataMessage, + sent_to: [this.OUR_NUMBER], + sent: true, + expirationStartTimestamp: Date.now(), + }); - const errors = this.get('errors'); - if (errors) { - this.trigger('send-error', errors); - } else { - this.trigger('sent'); - } - } + return window.Signal.Data.saveMessage(this.attributes, { + Message: Whisper.Message, + }); }, - async sendSyncMessage() { + sendSyncMessage() { this.syncPromise = this.syncPromise || Promise.resolve(); const next = async () => { const encodedDataMessage = this.get('dataMessage'); diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index ceae67c30..73058949e 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -661,98 +661,6 @@ MessageSender.prototype = { } }, - async sendMessageToNumber( - number, - messageText, - attachments, - quote, - preview, - timestamp, - expireTimer, - profileKey, - options - ) { - const profile = this.getOurProfile(); - - const { groupInvitation, sessionRestoration } = options; - - return this.sendMessage( - { - recipients: [number], - body: messageText, - timestamp, - attachments, - quote, - preview, - needsSync: true, - expireTimer, - profileKey, - profile, - undefined, - groupInvitation, - sessionRestoration, - }, - options - ); - }, - async sendMessageToGroup( - groupId, - groupNumbers, - messageText, - attachments, - quote, - preview, - timestamp, - expireTimer, - profileKey, - options - ) { - // We always assume that only primary device is a member in the group - const primaryDeviceKey = - window.storage.get('primaryDevicePubKey') || - textsecure.storage.user.getNumber(); - let numbers = groupNumbers.filter(number => number !== primaryDeviceKey); - if (options.isPublic) { - numbers = [groupId]; - } - const profile = this.getOurProfile(); - - let group; - // Medium groups don't need this info - if (!options.isMediumGroup) { - group = { - id: groupId, - type: textsecure.protobuf.GroupContext.Type.DELIVER, - }; - } - - const attrs = { - recipients: numbers, - body: messageText, - timestamp, - attachments, - quote, - preview, - needsSync: true, - expireTimer, - profileKey, - profile, - group, - }; - - if (numbers.length === 0) { - return { - successfulNumbers: [], - failoverNumbers: [], - errors: [], - unidentifiedDeliveries: [], - dataMessage: await this.getMessageProtoObj(attrs), - }; - } - - return this.sendMessage(attrs, options); - }, - async updateMediumGroup(members, groupUpdateProto) { // Automatically request session if not found (updates use pairwise sessions) const autoSession = true; @@ -791,9 +699,7 @@ textsecure.MessageSender = function MessageSenderWrapper(username, password) { this.sendOpenGroupsSyncMessage = sender.sendOpenGroupsSyncMessage.bind( sender ); - this.sendMessageToNumber = sender.sendMessageToNumber.bind(sender); this.sendMessage = sender.sendMessage.bind(sender); - this.sendMessageToGroup = sender.sendMessageToGroup.bind(sender); this.updateMediumGroup = sender.updateMediumGroup.bind(sender); this.requestSenderKeys = sender.requestSenderKeys.bind(sender); this.uploadAvatar = sender.uploadAvatar.bind(sender);