Don't rejoin a dropped channel on reconnect and leave chat channel

This commit is contained in:
yflory
2018-10-04 15:29:34 +02:00
parent 2a86db2001
commit 498703384f
3 changed files with 40 additions and 6 deletions

View File

@@ -585,6 +585,7 @@ define([
id: data.channel,
isFriendChat: data.isFriendChat,
isPadChat: data.isPadChat,
padChan: data.padChan,
sending: false,
encryptor: encryptor,
messages: [],
@@ -655,6 +656,7 @@ define([
console.error(err);
});
network.on('reconnect', function () {
if (channel && channel.stopped) { return; }
if (!channels[data.channel]) { return; }
network.join(data.channel).then(onOpen, function (err) {
console.error(err);
@@ -910,6 +912,7 @@ define([
var cryptKey = keys.viewKeyStr ? Crypto.b64AddSlashes(keys.viewKeyStr) : data.secret.key;
var encryptor = Crypto.createEncryptor(cryptKey);
var chanData = {
padChan: data.secret && data.secret.channel,
encryptor: encryptor,
channel: data.channel,
isPadChat: true,
@@ -931,6 +934,17 @@ define([
emit('RECONNECT');
});
messenger.leavePad = function (padChan) {
// Leave chat and prevent reconnect when we leave a pad
Object.keys(channels).some(function (chatChan) {
var channel = channels[chatChan];
if (channel.padChan !== padChan) { return; }
if (channel.wc) { channel.wc.leave(); }
channel.stopped = true;
return true;
});
};
messenger.execCommand = function (obj, cb) {
var cmd = obj.cmd;
var data = obj.data;