From 4f6dd7a8d5f5c6aed4f0430102729925d5b871b2 Mon Sep 17 00:00:00 2001 From: Mikunj Varsani Date: Tue, 11 Feb 2020 11:02:06 +1100 Subject: [PATCH] Rename functions to be less confusing --- js/models/conversations.js | 12 +++++++----- libtextsecure/sendmessage.js | 4 ++++ ts/components/session/SessionClosableOverlay.tsx | 5 +---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 39b8f2979..3abcecb58 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -198,15 +198,20 @@ isOnline() { return this.isMe() || this.get('isOnline'); }, - isMe() { + return this.isOurLocalDevice() || this.isOurPrimaryDevice(); + }, + isOurPrimaryDevice() { return this.id === window.storage.get('primaryDevicePubKey'); }, async isOurDevice() { const ourDevices = await window.libloki.storage.getPairedDevicesFor( this.ourNumber ); - return this.id === this.ourNumber || ourDevices.includes(this.id); + return this.isOurLocalDevice() || ourDevices.includes(this.id); + }, + isOurLocalDevice() { + return this.id === this.ourNumber; }, isPublic() { return !!(this.id && this.id.match(/^publicChat:/)); @@ -892,9 +897,6 @@ throw new Error('Invalid friend request state'); } }, - isOurConversation() { - return this.id === this.ourNumber; - }, isSecondaryDevice() { return !!this.get('secondaryStatus'); }, diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index a53c0c258..2f0dbc001 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -411,6 +411,10 @@ MessageSender.prototype = { const ourNumber = textsecure.storage.user.getNumber(); + // Note: Since we're just doing independant tasks, + // using `async` in the `forEach` loop should be fine. + // If however we want to use the results from forEach then + // we would need to convert this to a Promise.all(numbers.map(...)) numbers.forEach(async 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 diff --git a/ts/components/session/SessionClosableOverlay.tsx b/ts/components/session/SessionClosableOverlay.tsx index d0d33cf14..88024618c 100644 --- a/ts/components/session/SessionClosableOverlay.tsx +++ b/ts/components/session/SessionClosableOverlay.tsx @@ -55,11 +55,8 @@ export class SessionClosableOverlay extends React.Component { const conversations = window.getConversations() || []; const conversationList = conversations.filter((conversation: any) => { - // TODO: We need to handle the case with > 1 secondary device - const isOurDevice = - conversation.isMe() || conversation.isOurConversation(); return ( - !isOurDevice && + !conversation.isMe() && conversation.isPrivate() && !conversation.isSecondaryDevice() && conversation.isFriend()