Merge pull request #479 from neuroscr/use-user-obj

Make sure public chat timers can't be restarted / Channel name bug fix
pull/483/head
Beaudan Campbell-Brown 6 years ago committed by GitHub
commit 6e6428928c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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) { async setGroupNameAndAvatar(name, avatarPath) {
const currentName = this.get('name'); const currentName = this.get('name');
const profileAvatar = this.get('profileAvatar'); const profileAvatar = this.get('profileAvatar');

@ -212,6 +212,7 @@ class LokiPublicChannelAPI {
this.modStatus = false; this.modStatus = false;
this.deleteLastId = 1; this.deleteLastId = 1;
this.timers = {}; this.timers = {};
this.stop = false;
// end properties // end properties
log.info(`registered LokiPublicChannel ${channelId}`); log.info(`registered LokiPublicChannel ${channelId}`);
@ -223,6 +224,7 @@ class LokiPublicChannelAPI {
} }
stop() { stop() {
this.stop = true;
if (this.timers.channel) { if (this.timers.channel) {
clearTimeout(this.timers.channel); clearTimeout(this.timers.channel);
} }
@ -387,9 +389,11 @@ class LokiPublicChannelAPI {
} catch (e) { } catch (e) {
log.warn(`Error while polling for public chat deletions: ${e}`); log.warn(`Error while polling for public chat deletions: ${e}`);
} }
this.timers.channel = setTimeout(() => { if (!this.stop) {
this.pollForChannelOnce(); this.timers.channel = setTimeout(() => {
}, PUBLICCHAT_CHAN_POLL_EVERY); this.pollForChannelOnce();
}, PUBLICCHAT_CHAN_POLL_EVERY);
}
} }
// update room details // update room details
@ -408,10 +412,8 @@ class LokiPublicChannelAPI {
res.response.data.annotations.forEach(note => { res.response.data.annotations.forEach(note => {
if (note.type === 'net.patter-app.settings') { if (note.type === 'net.patter-app.settings') {
// note.value.description only needed for directory // note.value.description only needed for directory
// this.conversation.setGroupNameAndAvatar(note.value.name,
// note.value.avatar);
if (note.value && note.value.name) { if (note.value && note.value.name) {
this.conversation.setProfileName(note.value.name); this.conversation.setGroupName(note.value.name);
} }
if (note.value && note.value.avatar) { if (note.value && note.value.avatar) {
this.conversation.setProfileAvatar(note.value.avatar); this.conversation.setProfileAvatar(note.value.avatar);
@ -429,9 +431,11 @@ class LokiPublicChannelAPI {
} catch (e) { } catch (e) {
log.warn(`Error while polling for public chat deletions: ${e}`); log.warn(`Error while polling for public chat deletions: ${e}`);
} }
this.timers.delete = setTimeout(() => { if (!this.stop) {
this.pollForDeletions(); this.timers.delete = setTimeout(() => {
}, PUBLICCHAT_DELETION_POLL_EVERY); this.pollForDeletions();
}, PUBLICCHAT_DELETION_POLL_EVERY);
}
} }
async pollOnceForDeletions() { async pollOnceForDeletions() {
@ -481,9 +485,11 @@ class LokiPublicChannelAPI {
} catch (e) { } catch (e) {
log.warn(`Error while polling for public chat messages: ${e}`); log.warn(`Error while polling for public chat messages: ${e}`);
} }
setTimeout(() => { if (!this.stop) {
this.timers.message = this.pollForMessages(); setTimeout(() => {
}, PUBLICCHAT_MSG_POLL_EVERY); this.timers.message = this.pollForMessages();
}, PUBLICCHAT_MSG_POLL_EVERY);
}
} }
async pollOnceForMessages() { async pollOnceForMessages() {

Loading…
Cancel
Save