Fix an issue that could result in a self-kick from a team

pull/1/head
yflory 4 years ago
parent e69df1b7dd
commit 7048f0d814

@ -578,6 +578,12 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) {
console.error("CHANNEL_ERROR", info); 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 */) { var onConnect = function (/* wc, sendMessage */) {
console.log("ROSTER CONNECTED"); 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 a checkpoint was successfully applied, emit an event
if (parsed[0] === 'CHECKPOINT' && changed) { if (parsed[0] === 'CHECKPOINT' && changed) {
events.checkpoint.fire(hash); if (isReady()) { events.checkpoint.fire(hash); }
// reset the counter for messages since the last checkpoint // reset the counter for messages since the last checkpoint
ref.internal.sinceLastCheckpoint = 0; ref.internal.sinceLastCheckpoint = 0;
ref.internal.lastCheckpointHash = hash; ref.internal.lastCheckpointHash = hash;
} else if (changed) { } else if (changed) {
events.change.fire(); if (isReady()) { events.change.fire(); }
} }
// CHECKPOINT logic... // CHECKPOINT logic...
@ -833,7 +839,7 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) {
onChannelError: onChannelError, onChannelError: onChannelError,
onReady: onReady, onReady: onReady,
onConnect: onConnect, onConnect: onConnect,
onConnectionChange: function () {}, onConnectionChange: onConnectionChange,
onMessage: onMessage, onMessage: onMessage,
noChainPad: true, noChainPad: true,

@ -221,6 +221,11 @@ define([
roster.on('change', function () { roster.on('change', function () {
var state = roster.getState(); var state = roster.getState();
var me = Util.find(ctx, ['store', 'proxy', 'curvePublic']); 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]) { if (!state.members[me]) {
return void closeTeam(ctx, id); return void closeTeam(ctx, id);
} }

Loading…
Cancel
Save