From 6d1c9700b15f9979df09cc8b3e41720c383431ce Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 3 Sep 2019 23:04:44 -0700 Subject: [PATCH 1/4] this.stop guard on channelAPI --- js/modules/loki_public_chat_api.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index deafffe87..9706bc78a 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -212,6 +212,7 @@ class LokiPublicChannelAPI { this.modStatus = false; this.deleteLastId = 1; this.timers = {}; + this.stop = false; // end properties log.info(`registered LokiPublicChannel ${channelId}`); @@ -223,6 +224,7 @@ class LokiPublicChannelAPI { } stop() { + this.stop = true; if (this.timers.channel) { clearTimeout(this.timers.channel); } @@ -387,9 +389,11 @@ class LokiPublicChannelAPI { } catch (e) { log.warn(`Error while polling for public chat deletions: ${e}`); } - this.timers.channel = setTimeout(() => { - this.pollForChannelOnce(); - }, PUBLICCHAT_CHAN_POLL_EVERY); + if (!this.stop) { + this.timers.channel = setTimeout(() => { + this.pollForChannelOnce(); + }, PUBLICCHAT_CHAN_POLL_EVERY); + } } // update room details @@ -429,9 +433,11 @@ class LokiPublicChannelAPI { } catch (e) { log.warn(`Error while polling for public chat deletions: ${e}`); } - this.timers.delete = setTimeout(() => { - this.pollForDeletions(); - }, PUBLICCHAT_DELETION_POLL_EVERY); + if (!this.stop) { + this.timers.delete = setTimeout(() => { + this.pollForDeletions(); + }, PUBLICCHAT_DELETION_POLL_EVERY); + } } async pollOnceForDeletions() { @@ -481,9 +487,11 @@ class LokiPublicChannelAPI { } catch (e) { log.warn(`Error while polling for public chat messages: ${e}`); } - setTimeout(() => { - this.timers.message = this.pollForMessages(); - }, PUBLICCHAT_MSG_POLL_EVERY); + if (!this.stop) { + setTimeout(() => { + this.timers.message = this.pollForMessages(); + }, PUBLICCHAT_MSG_POLL_EVERY); + } } async pollOnceForMessages() { From eea6bac7e666d9b52ebecaa07db72abee0cf4ca4 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 3 Sep 2019 23:28:14 -0700 Subject: [PATCH 2/4] add setGroupName() --- js/models/conversations.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/js/models/conversations.js b/js/models/conversations.js index c48b3458f..2a393e39f 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -2151,6 +2151,15 @@ }); } }, + 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, + }); + } + }, async setGroupNameAndAvatar(name, avatarPath) { const currentName = this.get('name'); const profileAvatar = this.get('profileAvatar'); From c97f26465c622b9a3f4dca9c3c0ec3ecaab59229 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 3 Sep 2019 23:28:35 -0700 Subject: [PATCH 3/4] set correct name on conversation --- js/modules/loki_public_chat_api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index 9706bc78a..b7233ca39 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -415,7 +415,7 @@ class LokiPublicChannelAPI { // this.conversation.setGroupNameAndAvatar(note.value.name, // note.value.avatar); if (note.value && note.value.name) { - this.conversation.setProfileName(note.value.name); + this.conversation.setGroupName(note.value.name); } if (note.value && note.value.avatar) { this.conversation.setProfileAvatar(note.value.avatar); From eb3d22f2b0edc6294ba5e61dc3eb591fc6757a99 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 3 Sep 2019 23:32:32 -0700 Subject: [PATCH 4/4] remove unneeded comment --- js/modules/loki_public_chat_api.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index b7233ca39..f2f312206 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -412,8 +412,6 @@ class LokiPublicChannelAPI { res.response.data.annotations.forEach(note => { if (note.type === 'net.patter-app.settings') { // note.value.description only needed for directory - // this.conversation.setGroupNameAndAvatar(note.value.name, - // note.value.avatar); if (note.value && note.value.name) { this.conversation.setGroupName(note.value.name); }