From c9f60826b470f609b7f0cfe21d5c7e5eac3fa310 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 5 Feb 2020 12:19:22 +1100 Subject: [PATCH 1/2] Fix friend request messages being sent to users you don't have a session in closed groups. Disable typing messages and read receipts in groups. Send out session request messages if you don't have a session with a member in the group. --- js/background.js | 17 ++++++++++------- js/models/conversations.js | 14 ++++++++++---- libtextsecure/outgoing_message.js | 8 +++++++- libtextsecure/sendmessage.js | 18 +++++++++++++++++- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/js/background.js b/js/background.js index 3c6330ebf..66ea5bb54 100644 --- a/js/background.js +++ b/js/background.js @@ -2112,13 +2112,16 @@ const { wrap, sendOptions } = ConversationController.prepareForSend( data.source ); - await wrap( - textsecure.messaging.sendDeliveryReceipt( - data.source, - data.timestamp, - sendOptions - ) - ); + const isGroup = data && data.message && data.message.group; + if (!isGroup) { + await wrap( + textsecure.messaging.sendDeliveryReceipt( + data.source, + data.timestamp, + sendOptions + ) + ); + } } catch (error) { window.log.error( `Failed to send delivery receipt to ${data.source} for message ${ diff --git a/js/models/conversations.js b/js/models/conversations.js index f6f81c0a2..52290e7a9 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -382,6 +382,11 @@ }, sendTypingMessage(isTyping) { + // Loki - Temporarily disable typing messages for groups + if (!this.isPrivate()) { + return; + } + const groupId = !this.isPrivate() ? this.id : null; const recipientId = this.isPrivate() ? this.id : null; const groupNumbers = this.getRecipients(); @@ -1518,11 +1523,14 @@ now ); + const conversationType = this.get('type'); + let messageWithSchema = null; // If we are a friend with any of the devices, send the message normally const canSendNormalMessage = await this.isFriendWithAnyDevice(); - if (canSendNormalMessage) { + const isGroup = conversationType === Message.GROUP; + if (canSendNormalMessage || isGroup) { messageWithSchema = await upgradeMessageSchema({ type: 'outgoing', body, @@ -1668,8 +1676,6 @@ return message.sendSyncMessageOnly(dataMessage); } - const conversationType = this.get('type'); - const options = this.getSendOptions(); options.messageType = message.get('type'); options.isPublic = this.isPublic(); @@ -2321,7 +2327,7 @@ return; } - if (!this.isPublic() && read.length && options.sendReadReceipts) { + if (this.isPrivate() && read.length && options.sendReadReceipts) { window.log.info(`Sending ${read.length} read receipts`); // Because syncReadMessages sends to our other devices, and sendReadReceipts goes // to a contact, we need accessKeys for both. diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index c7fd66a99..5be3b7368 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -72,6 +72,11 @@ function OutgoingMessage( options || {}; this.numberInfo = numberInfo; this.isPublic = isPublic; + this.isGroup = !!( + this.message && + this.message.dataMessage && + this.message.dataMessage.group + ); this.publicSendData = publicSendData; this.senderCertificate = senderCertificate; this.online = online; @@ -348,7 +353,8 @@ OutgoingMessage.prototype = { if ( conversation && !conversation.isFriend() && - !conversation.hasReceivedFriendRequest() + !conversation.hasReceivedFriendRequest() && + !this.isGroup ) { // We want to send an automated friend request if: // - We aren't already friends diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index 5b7e824da..43a71b844 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -409,6 +409,8 @@ MessageSender.prototype = { options ); + const ourNumber = textsecure.storage.user.getNumber(); + numbers.forEach(number => { // Note: if we are sending a private group message, we do our best to // ensure we have signal protocol sessions with every member, but if we @@ -419,7 +421,7 @@ MessageSender.prototype = { ); if ( - number === textsecure.storage.user.getNumber() || + number === ourNumber || haveSession || options.isPublic || options.messageType === 'friend-request' @@ -427,6 +429,20 @@ MessageSender.prototype = { this.queueJobForNumber(number, () => outgoing.sendToNumber(number)); } else { window.log.error(`No session for number: ${number}`); + // If it was a message to a group then we need to send a session request + if (outgoing.isGroup && number !== ourNumber) { + this.sendMessageToNumber( + number, + '(If you see this message, you must be using an out-of-date client)', + [], + undefined, + [], + Date.now(), + undefined, + undefined, + { messageType: 'friend-request', sessionRequest: true } + ); + } } }); }, From 164303180fbf28545e85b7d26e195f917216cf53 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 5 Feb 2020 13:06:36 +1100 Subject: [PATCH 2/2] Remove unneeded boolean condition. --- libtextsecure/sendmessage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index 43a71b844..cb1fea2ad 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -430,7 +430,7 @@ MessageSender.prototype = { } else { window.log.error(`No session for number: ${number}`); // If it was a message to a group then we need to send a session request - if (outgoing.isGroup && number !== ourNumber) { + if (outgoing.isGroup) { this.sendMessageToNumber( number, '(If you see this message, you must be using an out-of-date client)',