From fbba5575bad21cf501f690f96e71f9dec23ee5da Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 19 Jun 2020 15:11:18 +1000 Subject: [PATCH] remove buildSessionRequest message --- js/background.js | 2 +- js/models/conversations.js | 1 + libloki/api.js | 27 +++++++++------------------ libtextsecure/outgoing_message.js | 27 --------------------------- ts/receiver/groups.ts | 2 +- 5 files changed, 12 insertions(+), 47 deletions(-) diff --git a/js/background.js b/js/background.js index 0c9df8993..47d603795 100644 --- a/js/background.js +++ b/js/background.js @@ -1956,7 +1956,7 @@ }); // send a session request for all the members we do not have a session with - window.libloki.api.sendSessionRequestsToMembers(updates.members); + await window.libloki.api.sendSessionRequestsToMembers(updates.members); const { expireTimer } = details; const isValidExpireTimer = typeof expireTimer === 'number'; diff --git a/js/models/conversations.js b/js/models/conversations.js index 310852c20..3e22333d7 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1720,6 +1720,7 @@ await libsession.getMessageQueue().sendToGroup(expirationTimerMessage); } + return message; }, isSearchable() { diff --git a/libloki/api.js b/libloki/api.js index 6c831a3a3..8b7044b81 100644 --- a/libloki/api.js +++ b/libloki/api.js @@ -1,4 +1,4 @@ -/* global window, textsecure, dcodeIO, StringView, ConversationController, _, libsession */ +/* global window, textsecure, dcodeIO, StringView, ConversationController, libsession */ /* eslint-disable no-bitwise */ // eslint-disable-next-line func-names @@ -172,24 +172,15 @@ }); return syncMessage; } - function sendSessionRequestsToMembers(members = []) { - // For every member, see if we need to establish a session: - members.forEach(memberPubKey => { - const haveSession = _.some( - textsecure.storage.protocol.sessions, - s => s.number === memberPubKey - ); - + async function sendSessionRequestsToMembers(members = []) { + // For every member, trigger a session request if needed + members.forEach(async memberStr => { const ourPubKey = textsecure.storage.user.getNumber(); - if (!haveSession && memberPubKey !== ourPubKey) { - // eslint-disable-next-line more/no-then - ConversationController.getOrCreateAndWait(memberPubKey, 'private').then( - () => { - const sessionRequestMessage = textsecure.OutgoingMessage.buildSessionRequestMessage( - memberPubKey - ); - sessionRequestMessage.sendToNumber(memberPubKey); - } + if (memberStr !== ourPubKey) { + await ConversationController.getOrCreateAndWait(memberStr, 'private'); + const memberPubkey = new libsession.Types.PubKey(memberStr); + await libsession.Protocols.SessionProtocol.sendSessionRequestIfNeeded( + memberPubkey ); } }); diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 3b229714b..821cfaf63 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -644,33 +644,6 @@ OutgoingMessage.prototype = { }, }; -OutgoingMessage.buildSessionRequestMessage = function buildSessionRequestMessage( - pubKey -) { - const body = - '(If you see this message, you must be using an out-of-date client)'; - - const flags = textsecure.protobuf.DataMessage.Flags.SESSION_REQUEST; - - const dataMessage = new textsecure.protobuf.DataMessage({ flags, body }); - - const content = new textsecure.protobuf.Content({ - dataMessage, - }); - - const options = {}; - // Send a empty message with information about how to contact us directly - return new OutgoingMessage( - null, // server - Date.now(), // timestamp, - [pubKey], // numbers - content, // message - true, // silent - () => null, // callback - options - ); -}; - OutgoingMessage.DebugMessageType = DebugMessageType; window.textsecure = window.textsecure || {}; diff --git a/ts/receiver/groups.ts b/ts/receiver/groups.ts index 7709eeb0f..a7d950c62 100644 --- a/ts/receiver/groups.ts +++ b/ts/receiver/groups.ts @@ -111,7 +111,7 @@ export async function preprocessGroupMessage( } } // send a session request for all the members we do not have a session with - window.libloki.api.sendSessionRequestsToMembers(group.members); + await window.libloki.api.sendSessionRequestsToMembers(group.members); } else if (newGroup) { // We have an unknown group, we should request info from the sender const requestInfo = {