From 7048f0d814b12c28f6385dcf1fc4b24a3aac8e4d Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 31 Aug 2020 11:58:08 +0200 Subject: [PATCH] Fix an issue that could result in a self-kick from a team --- www/common/outer/roster.js | 12 +++++++++--- www/common/outer/team.js | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/www/common/outer/roster.js b/www/common/outer/roster.js index cd73c074c..1db1bf5c7 100644 --- a/www/common/outer/roster.js +++ b/www/common/outer/roster.js @@ -578,6 +578,12 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { console.error("CHANNEL_ERROR", info); }; + var onConnectionChange = function (info) { + if (info.state) { return; } + // Disconnect: don't send event anymore until ready + ready = false; + }; + var onConnect = function (/* wc, sendMessage */) { console.log("ROSTER CONNECTED"); }; @@ -621,12 +627,12 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { // if a checkpoint was successfully applied, emit an event if (parsed[0] === 'CHECKPOINT' && changed) { - events.checkpoint.fire(hash); + if (isReady()) { events.checkpoint.fire(hash); } // reset the counter for messages since the last checkpoint ref.internal.sinceLastCheckpoint = 0; ref.internal.lastCheckpointHash = hash; } else if (changed) { - events.change.fire(); + if (isReady()) { events.change.fire(); } } // CHECKPOINT logic... @@ -833,7 +839,7 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { onChannelError: onChannelError, onReady: onReady, onConnect: onConnect, - onConnectionChange: function () {}, + onConnectionChange: onConnectionChange, onMessage: onMessage, noChainPad: true, diff --git a/www/common/outer/team.js b/www/common/outer/team.js index 7cffb1b2a..e51edc2d1 100644 --- a/www/common/outer/team.js +++ b/www/common/outer/team.js @@ -221,6 +221,11 @@ define([ roster.on('change', function () { var state = roster.getState(); var me = Util.find(ctx, ['store', 'proxy', 'curvePublic']); + if (!state.members || !Object.keys(state.members).length) { + // invalid roster, don't leave the team + console.error(JSON.stringify(state)); + return; + } if (!state.members[me]) { return void closeTeam(ctx, id); }