From 24f86de0879acb73f820190cd8ccd2ba0bf41e70 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 29 Jun 2020 11:07:13 +1000 Subject: [PATCH] use SyncMessage when we are only sending a syncMessage --- js/background.js | 4 +-- libtextsecure/sendmessage.js | 46 ++++------------------------------- libtextsecure/sync_request.js | 12 +++------ 3 files changed, 9 insertions(+), 53 deletions(-) diff --git a/js/background.js b/js/background.js index 6e96fa7ff..03aa24766 100644 --- a/js/background.js +++ b/js/background.js @@ -1628,11 +1628,9 @@ timestamp: Date.now(), reqestType: CONFIGURATION, }); - const myPubKey = textsecure.storage.user.getNumber(); - const currentPubKey = new libsession.Types.PubKey(myPubKey); await libsession .getMessageQueue() - .sendUsingMultiDevice(currentPubKey, requestConfigurationSyncMessage); + .sendSyncMessage(requestConfigurationSyncMessage); // sending of the message is handled in the 'private' case below } } diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index d70be1d7f..73d8bad7a 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -379,14 +379,9 @@ MessageSender.prototype = { const syncMessages = await Promise.all( chunked.map(c => libloki.api.createContactSyncMessage(c)) ); - const pubKey = textsecure.storage.user.getNumber(); - - const currentPubKey = new libsession.Types.PubKey(pubKey); const syncPromises = syncMessages.map(syncMessage => - libsession - .getMessageQueue() - .sendUsingMultiDevice(currentPubKey, syncMessage) + libsession.getMessageQueue().sendSyncMessage(syncMessage) ); return Promise.all(syncPromises); @@ -412,17 +407,13 @@ MessageSender.prototype = { window.console.info('No closed group to sync.'); return Promise.resolve(); } - const pubKey = textsecure.storage.user.getNumber(); - const currentPubKey = new libsession.Types.PubKey(pubKey); // We need to sync across 1 group at a time // This is because we could hit the storage server limit with one group const syncPromises = sessionGroups .map(c => libloki.api.createGroupSyncMessage(c)) .map(syncMessage => - libsession - .getMessageQueue() - .sendUsingMultiDevice(currentPubKey, syncMessage) + libsession.getMessageQueue().sendSyncMessage(syncMessage) ); return Promise.all(syncPromises); @@ -458,12 +449,7 @@ MessageSender.prototype = { openGroupsSyncParams ); - const pubKey = textsecure.storage.user.getNumber(); - const currentPubKey = new libsession.Types.PubKey(pubKey); - - return libsession - .getMessageQueue() - .sendUsingMultiDevice(currentPubKey, openGroupsSyncMessage); + return libsession.getMessageQueue().sendSyncMessage(openGroupsSyncMessage); }, syncReadMessages(reads) { const myDevice = textsecure.storage.user.getDeviceId(); @@ -474,11 +460,7 @@ MessageSender.prototype = { readMessages: reads, } ); - const pubKey = textsecure.storage.user.getNumber(); - const currentPubKey = new libsession.Types.PubKey(pubKey); - return libsession - .getMessageQueue() - .sendUsingMultiDevice(currentPubKey, syncReadMessages); + return libsession.getMessageQueue().sendSyncMessage(syncReadMessages); } return Promise.resolve(); @@ -510,26 +492,8 @@ MessageSender.prototype = { const verifiedSyncMessage = new window.libsession.Messages.Outgoing.VerifiedSyncMessage( verifiedSyncParams ); - const pubKey = textsecure.storage.user.getNumber(); - const currentPubKey = new libsession.Types.PubKey(pubKey); - - return libsession - .getMessageQueue() - .sendUsingMultiDevice(currentPubKey, verifiedSyncMessage); - }, - - getOurProfile() { - try { - // Secondary devices have their profile stored - // in their primary device's conversation - const ourNumber = window.storage.get('primaryDevicePubKey'); - const conversation = window.ConversationController.get(ourNumber); - return conversation.getLokiProfile(); - } catch (e) { - window.log.error(`Failed to get our profile: ${e}`); - return null; - } + return libsession.getMessageQueue().sendSyncMessage(verifiedSyncMessage); }, makeProxiedRequest(url, options) { diff --git a/libtextsecure/sync_request.js b/libtextsecure/sync_request.js index d5b4ea043..069eda64a 100644 --- a/libtextsecure/sync_request.js +++ b/libtextsecure/sync_request.js @@ -24,13 +24,9 @@ reqestType: CONFIGURATION, }); - const pubKey = textsecure.storage.user.getNumber(); - - const currentPubKey = new libsession.Types.PubKey(pubKey); - await libsession .getMessageQueue() - .sendUsingMultiDevice(currentPubKey, requestConfigurationSyncMessage); + .sendSyncMessage(requestConfigurationSyncMessage); window.log.info('SyncRequest now sending contact sync message...'); const { CONTACTS } = textsecure.protobuf.SyncMessage.Request.Type; @@ -40,7 +36,7 @@ }); await libsession .getMessageQueue() - .sendUsingMultiDevice(currentPubKey, requestContactSyncMessage); + .sendSyncMessage(requestContactSyncMessage); window.log.info('SyncRequest now sending group sync messsage...'); const { GROUPS } = textsecure.protobuf.SyncMessage.Request.Type; @@ -48,9 +44,7 @@ timestamp: Date.now(), reqestType: GROUPS, }); - await libsession - .getMessageQueue() - .sendUsingMultiDevice(currentPubKey, requestGroupSyncMessage); + await libsession.getMessageQueue().sendSyncMessage(requestGroupSyncMessage); this.timeout = setTimeout(this.onTimeout.bind(this), 60000); }