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

pull/1/head
yflory 6 years ago
parent 2a86db2001
commit 498703384f

@ -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;

@ -985,7 +985,7 @@ define([
/////////////////////// PAD //////////////////////////////////////
//////////////////////////////////////////////////////////////////
var channels = Store.channels = {};
var channels = Store.channels = store.channels = {};
Store.joinPad = function (clientId, data) {
var isNew = typeof channels[data.channel] === "undefined";
@ -1093,12 +1093,12 @@ define([
});
}
};
CpNfWorker.start(conf);
channel.cpNf = CpNfWorker.start(conf);
};
Store.leavePad = function (clientId, data, cb) {
var channel = channels[data.channel];
if (!channel || !channel.wc) { return void cb ({error: 'EINVAL'}); }
channel.wc.leave();
if (!channel || !channel.cpNf) { return void cb ({error: 'EINVAL'}); }
channel.cpNf.stop();
delete channels[data.channel];
cb();
};
@ -1278,9 +1278,12 @@ define([
var dropChannel = function (chanId) {
if (!Store.channels[chanId]) { return; }
if (Store.channels[chanId].wc) {
Store.channels[chanId].wc.leave('');
if (Store.channels[chanId].cpNf) {
Store.channels[chanId].cpNf.stop();
}
store.messenger.leavePad(chanId);
delete Store.channels[chanId];
};
Store._removeClient = function (clientId) {

@ -45,6 +45,7 @@ define([], function () {
conf = undefined;
var initializing = true;
var stopped = false;
var lastKnownHash;
var messageFromOuter = function () {};
@ -239,6 +240,12 @@ define([], function () {
onOpen(wc, network, firstConnection);
}, function(err) {
console.error(err);
if (onError) {
onError({
type: err && (err.type || err),
loaded: !initializing
});
}
});
};
@ -250,11 +257,13 @@ define([], function () {
});
network.on('reconnect', function () {
if (stopped) { return; }
initializing = true;
connectTo(network, false);
});
network.on('message', function (msg, sender) { // Direct message
if (stopped) { return; }
var wchan = findChannelById(network.webChannels, channel);
if (wchan) {
onMsg(sender, msg, wchan, network, true);
@ -262,6 +271,14 @@ define([], function () {
});
connectTo(network, true);
return {
stop: function () {
var wchan = findChannelById(network.webChannels, channel);
if (wchan) { wchan.leave(''); }
stopped = true;
}
};
};
return {

Loading…
Cancel
Save