From b050a3740d2902f4084600ad2047ad31fec52a08 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 7 Oct 2020 15:25:57 +1100 Subject: [PATCH] clean all updateConversation calls to convo.commit() --- js/models/conversations.js | 84 +++++-------------- js/modules/debug.js | 6 +- js/modules/loki_app_dot_net_api.js | 9 +- .../session/LeftPaneMessageSection.tsx | 1 - ts/receiver/errors.ts | 9 +- ts/receiver/multidevice.ts | 5 +- ts/state/selectors/conversations.ts | 1 - 7 files changed, 26 insertions(+), 89 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index e958588fc..1336a0c01 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -641,9 +641,7 @@ this.set({ verified }); // we don't await here because we don't need to wait for this to finish - window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + this.commit(); return; } @@ -706,9 +704,7 @@ } this.set({ verified }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); // Three situations result in a verification notice in the conversation: // 1) The message came from an explicit verification in another client (not @@ -813,16 +809,12 @@ secondaryStatus: newStatus, primaryDevicePubKey, }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); } }, async updateGroupAdmins(groupAdmins) { this.set({ groupAdmins }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); }, isUnverified() { if (this.isPrivate()) { @@ -1307,9 +1299,7 @@ timestamp: now, isArchived: false, }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); // We're offline! if (!textsecure.messaging) { @@ -1494,17 +1484,13 @@ this.set(lastMessageUpdate); if (this.hasChanged()) { - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); } }, async setArchived(isArchived) { this.set({ isArchived }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); }, async updateExpirationTimer( @@ -1541,9 +1527,7 @@ const timestamp = (receivedAt || Date.now()) - 1; this.set({ expireTimer }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); const message = this.messageCollection.add({ // Even though this isn't reflected to the user, we want to place the last seen @@ -1636,9 +1620,7 @@ } if (this.get('sessionResetStatus') !== newStatus) { this.set({ sessionResetStatus: newStatus }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); } }, async onSessionResetInitiated() { @@ -1917,9 +1899,7 @@ this.set({ mentionedUs: false }); } - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); // If a message has errors, we don't want to send anything out about it. // read syncs - let's wait for a client that really understands the message @@ -1978,18 +1958,14 @@ } this.set({ nickname: trimmed }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); await this.updateProfileName(); }, async setLokiProfile(newProfile) { if (!_.isEqual(this.get('profile'), newProfile)) { this.set({ profile: newProfile }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); } // if set to null, it will show a placeholder with color and first letter @@ -2041,9 +2017,7 @@ channelId: newChannelId, active_at: Date.now(), }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); } }, getPublicSource() { @@ -2080,9 +2054,7 @@ } if (this.get('lastPublicMessage') !== newLastMessageId) { this.set({ lastPublicMessage: newLastMessageId }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); } }, isModerator(pubKey) { @@ -2099,9 +2071,7 @@ // TODO: compare array properly if (!_.isEqual(this.get('moderators'), moderators)) { this.set({ moderators }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); } }, @@ -2136,18 +2106,14 @@ const profileName = this.get('profileName'); if (profileName !== name) { this.set({ profileName: name }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); } }, async setGroupName(name) { const profileName = this.get('name'); if (profileName !== name) { this.set({ name }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); } }, async setSubscriberCount(count) { @@ -2166,18 +2132,14 @@ this.set({ name }); } // save - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); } }, async setProfileAvatar(avatar) { const profileAvatar = this.get('profileAvatar'); if (profileAvatar !== avatar) { this.set({ profileAvatar: avatar }); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); } }, async setProfileKey(profileKey) { @@ -2194,9 +2156,7 @@ await this.deriveAccessKeyIfNeeded(); - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); } }, @@ -2426,9 +2386,7 @@ }); } - await window.Signal.Data.updateConversation(this.id, this.attributes, { - Conversation: Whisper.Conversation, - }); + await this.commit(); }, getName() { diff --git a/js/modules/debug.js b/js/modules/debug.js index 5f0e4037c..e763758aa 100644 --- a/js/modules/debug.js +++ b/js/modules/debug.js @@ -50,11 +50,7 @@ exports.createConversation = async ({ unread: numMessages, }); const conversationId = conversation.get('id'); - await Signal.Data.updateConversation( - conversationId, - conversation.attributes, - { Conversation: Whisper.Conversation } - ); + await conversation.commit(); await Promise.all( range(0, numMessages).map(async index => { diff --git a/js/modules/loki_app_dot_net_api.js b/js/modules/loki_app_dot_net_api.js index efcd5642a..ca78976a1 100644 --- a/js/modules/loki_app_dot_net_api.js +++ b/js/modules/loki_app_dot_net_api.js @@ -1619,14 +1619,7 @@ class LokiPublicChannelAPI { if (data.counts && Number.isInteger(data.counts.subscribers)) { this.conversation.setSubscriberCount(data.counts.subscribers); } - - await window.Signal.Data.updateConversation( - this.conversation.id, - this.conversation.attributes, - { - Conversation: Whisper.Conversation, - } - ); + await this.conversation.commit(); } // get moderation actions diff --git a/ts/components/session/LeftPaneMessageSection.tsx b/ts/components/session/LeftPaneMessageSection.tsx index e426099a1..78c1f2724 100644 --- a/ts/components/session/LeftPaneMessageSection.tsx +++ b/ts/components/session/LeftPaneMessageSection.tsx @@ -161,7 +161,6 @@ export class LeftPaneMessageSection extends React.Component { const length = conversations.length; const listKey = 0; - // Note: conversations is not a known prop for List, but it is required to ensure that // it re-renders when our conversation data changes. Otherwise it would just render // on startup and scroll. diff --git a/ts/receiver/errors.ts b/ts/receiver/errors.ts index a41179f85..26e2201b4 100644 --- a/ts/receiver/errors.ts +++ b/ts/receiver/errors.ts @@ -16,9 +16,7 @@ async function onNoSession(ev: any) { if (!convo.get('sessionRestoreSeen')) { convo.set({ sessionRestoreSeen: true }); - await window.Signal.Data.updateConversation(convo.id, convo.attributes, { - Conversation: Whisper.Conversation, - }); + await convo.commit(); await SessionProtocol.sendSessionRequestIfNeeded(new PubKey(pubkey)); } else { @@ -85,10 +83,7 @@ export async function onError(ev: any) { if (ev.confirm) { ev.confirm(); } - - await window.Signal.Data.updateConversation(id, conversation.attributes, { - Conversation: Whisper.Conversation, - }); + await conversation.commit(); } throw error; diff --git a/ts/receiver/multidevice.ts b/ts/receiver/multidevice.ts index 35f30e591..a46de5286 100644 --- a/ts/receiver/multidevice.ts +++ b/ts/receiver/multidevice.ts @@ -409,10 +409,7 @@ async function onContactReceived(details: any) { ); conversation.set(newAttributes); } - - await window.Signal.Data.updateConversation(id, conversation.attributes, { - Conversation: Whisper.Conversation, - }); + await conversation.commit(); const { expireTimer } = details; const isValidExpireTimer = typeof expireTimer === 'number'; if (isValidExpireTimer) { diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 63b86af9e..c4b772fed 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -193,7 +193,6 @@ export const _getLeftPaneLists = ( }; const contacts: Array = filterToPrimary(allContacts); - return { conversations, archivedConversations,