diff --git a/js/models/conversations.js b/js/models/conversations.js index 3e22333d7..d5f0a4768 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -2047,9 +2047,17 @@ await Promise.all( _.map(_.groupBy(read, 'sender'), async (receipts, sender) => { const timestamps = _.map(receipts, 'timestamp'); - await this.wrapSend( - textsecure.messaging.sendReadReceipts(sender, timestamps, {}) + const receiptMessage = new libsession.Messages.Outgoing.ReadReceiptMessage( + { + timestamp: Date.now(), + timestamps, + } ); + + const device = new libsession.Types.PubKey(sender); + await libsession + .getMessageQueue() + .sendUsingMultiDevice(device, receiptMessage); }) ); } diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index a71a376b3..99bbf8fd7 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -749,48 +749,6 @@ MessageSender.prototype = { { debugMessageType } // options ); }, - - sendDeliveryReceipt(recipientId, timestamp, options) { - const myNumber = textsecure.storage.user.getNumber(); - const myDevice = textsecure.storage.user.getDeviceId(); - if (myNumber === recipientId && (myDevice === 1 || myDevice === '1')) { - return Promise.resolve(); - } - - const receiptMessage = new textsecure.protobuf.ReceiptMessage(); - receiptMessage.type = textsecure.protobuf.ReceiptMessage.Type.DELIVERY; - receiptMessage.timestamp = [timestamp]; - - const contentMessage = new textsecure.protobuf.Content(); - contentMessage.receiptMessage = receiptMessage; - - const silent = true; - return this.sendIndividualProto( - recipientId, - contentMessage, - Date.now(), - silent, - options - ); - }, - - sendReadReceipts(sender, timestamps, options) { - const receiptMessage = new textsecure.protobuf.ReceiptMessage(); - receiptMessage.type = textsecure.protobuf.ReceiptMessage.Type.READ; - receiptMessage.timestamp = timestamps; - - const contentMessage = new textsecure.protobuf.Content(); - contentMessage.receiptMessage = receiptMessage; - - const silent = true; - return this.sendIndividualProto( - sender, - contentMessage, - Date.now(), - silent, - options - ); - }, syncReadMessages(reads, options) { const myNumber = textsecure.storage.user.getNumber(); const myDevice = textsecure.storage.user.getDeviceId(); @@ -1221,8 +1179,6 @@ textsecure.MessageSender = function MessageSenderWrapper(username, password) { this.uploadAvatar = sender.uploadAvatar.bind(sender); this.syncReadMessages = sender.syncReadMessages.bind(sender); this.syncVerification = sender.syncVerification.bind(sender); - this.sendDeliveryReceipt = sender.sendDeliveryReceipt.bind(sender); - this.sendReadReceipts = sender.sendReadReceipts.bind(sender); this.makeProxiedRequest = sender.makeProxiedRequest.bind(sender); this.getProxiedSize = sender.getProxiedSize.bind(sender); this.getMessageProto = sender.getMessageProto.bind(sender); diff --git a/ts/receiver/receiver.ts b/ts/receiver/receiver.ts index 48bbd6908..916cff64a 100644 --- a/ts/receiver/receiver.ts +++ b/ts/receiver/receiver.ts @@ -14,9 +14,13 @@ import { SignalService } from './../protobuf'; import { removeFromCache } from './cache'; import { toNumber } from 'lodash'; -import { DataMessage } from '../session/messages/outgoing'; +import { + DataMessage, + DeliveryReceiptMessage, +} from '../session/messages/outgoing'; import { MultiDeviceProtocol } from '../session/protocols'; import { PubKey } from '../session/types'; +import { getMessageQueue } from '../session'; export { handleEndSession, handleMediumGroupUpdate }; @@ -171,22 +175,14 @@ enum ConversationType { PRIVATE = 'private', } -function sendDeliveryReceipt(source: string, timestamp: any) { - const { wrap, sendOptions } = window.ConversationController.prepareForSend( - source - ); - wrap( - window.textsecure.messaging.sendDeliveryReceipt( - source, - timestamp, - sendOptions - ) - ).catch((error: any) => { - window.log.error( - `Failed to send delivery receipt to ${source} for message ${timestamp}:`, - error && error.stack ? error.stack : error - ); +async function sendDeliveryReceipt(source: string, timestamp: any) { + const receiptMessage = new DeliveryReceiptMessage({ + timestamp: Date.now(), + timestamps: [timestamp], }); + + const device = new PubKey(source); + await getMessageQueue().sendUsingMultiDevice(device, receiptMessage); } interface MessageId { @@ -604,11 +600,13 @@ export async function handleMessageEvent(event: any): Promise<void> { return; } + const isOurDevice = await MultiDeviceProtocol.isOurDevice(source); + const shouldSendReceipt = - isIncoming && data.unidentifiedDeliveryReceived && !isGroupMessage; + isIncoming && data.unidentifiedDeliveryReceived && !isGroupMessage && !isOurDevice; if (shouldSendReceipt) { - sendDeliveryReceipt(source, data.timestamp); + await sendDeliveryReceipt(source, data.timestamp); } await window.ConversationController.getOrCreateAndWait(id, type);