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

This commit is contained in:
yflory 2020-08-31 11:58:08 +02:00
parent e69df1b7dd
commit 7048f0d814
2 changed files with 14 additions and 3 deletions

View file

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

View file

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