diff --git a/js/models/conversations.js b/js/models/conversations.js index 84ab4c509..062f90032 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -2152,6 +2152,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'); diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index deafffe87..f2f312206 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 @@ -408,10 +412,8 @@ 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.setProfileName(note.value.name); + this.conversation.setGroupName(note.value.name); } if (note.value && note.value.avatar) { this.conversation.setProfileAvatar(note.value.avatar); @@ -429,9 +431,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 +485,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() {