ref(base/conference): clear the 'conference' field on WILL_LEAVE

Pawel Domas said:
The conference state field is referring to the current conference in
progress, so it feels like this field should be cleared as soon as we
declare that the conference is being left and the asynchronous process
of leaving the conference starts (which happens on
CONFERENCE_WILL_LEAVE).

Lyubo Marinov said:
Merely setting conference to undefined is incomplete because there are
other redux state properties associated with conference.

What we're doing here is redefining the redux action
CONFERENCE_WILL_LEAVE:

The redux action CONFERENCE_WILL_LEAVE represents the order of the user
to leave a JitsiConference instance. From the user's perspective, there's
no going back (with respect to the instance itself). The app will perform
due clean-up like leaving the associated room, but the instance is no
longer the focus of the attention of the user and, consequently, the app.

Now CONFERENCE_LEFT and CONFERENCE_WILL_LEAVE have more in common than
before and we can do a much better job by expressing the common parts in
source code. Additionally, our source code can be rewritten to better
express the meaning of any of these two actions.

Co-authored-by: Pawel Domas <pawel.domas@jitsi.org>
Co-authored-by: Lyubo Marinov <lmarinov@atlassian.com>
This commit is contained in:
paweldomas 2018-05-25 13:24:36 -05:00 committed by Saúl Ibarra Corretgé
parent 92fee790f2
commit 11b7144ad0
1 changed files with 58 additions and 61 deletions

View File

@ -38,14 +38,12 @@ ReducerRegistry.register('features/base/conference', (state = {}, action) => {
return _conferenceJoined(state, action);
case CONFERENCE_LEFT:
return _conferenceLeft(state, action);
case CONFERENCE_WILL_LEAVE:
return _conferenceLeftOrWillLeave(state, action);
case CONFERENCE_WILL_JOIN:
return _conferenceWillJoin(state, action);
case CONFERENCE_WILL_LEAVE:
return _conferenceWillLeave(state, action);
case CONNECTION_WILL_CONNECT:
return set(state, 'authRequired', undefined);
@ -197,41 +195,70 @@ function _conferenceJoined(state, { conference }) {
}
/**
* Reduces a specific Redux action CONFERENCE_LEFT of the feature
* base/conference.
* Reduces a specific redux action {@link CONFERENCE_LEFT} or
* {@link CONFERENCE_WILL_LEAVE} for the feature base/conference.
*
* @param {Object} state - The Redux state of the feature base/conference.
* @param {Action} action - The Redux action CONFERENCE_LEFT to reduce.
* @param {Object} state - The redux state of the feature base/conference.
* @param {Action} action - The redux action {@code CONFERENCE_LEFT} or
* {@code CONFERENCE_WILL_LEAVE} to reduce.
* @private
* @returns {Object} The new state of the feature base/conference after the
* @returns {Object} The next/new state of the feature base/conference after the
* reduction of the specified action.
*/
function _conferenceLeft(state, { conference }) {
function _conferenceLeftOrWillLeave(state, { conference, type }) {
let nextState = state;
if (state.authRequired === conference) {
nextState = set(nextState, 'authRequired', undefined);
}
if (state.conference === conference) {
nextState = assign(nextState, {
conference: undefined,
joining: undefined,
leaving: undefined,
// The redux action CONFERENCE_LEFT is the last time that we should be
// hearing from a JitsiConference instance.
//
// The redux action CONFERENCE_WILL_LEAVE represents the order of the user
// to leave a JitsiConference instance. From the user's perspective, there's
// no going back (with respect to the instance itself). The app will perform
// due clean-up like leaving the associated room, but the instance is no
// longer the focus of the attention of the user and, consequently, the app.
for (const p in state) {
if (p !== 'leaving' && state[p] === conference) {
nextState = set(nextState, p, undefined);
// XXX Clear/unset locked & password here for a conference which has
// been LOCKED_LOCALLY.
locked: undefined,
password: undefined
});
switch (p) {
case 'conference':
// XXX Clear/unset locked & password for a conference which has
// been LOCKED_LOCALLY.
delete nextState.locked;
delete nextState.password;
break;
case 'passwordRequired':
// XXX Clear/unset locked & password for a conference which has
// been LOCKED_REMOTELY.
delete nextState.locked;
delete nextState.password;
break;
}
}
}
if (state.passwordRequired === conference) {
nextState = assign(nextState, {
// XXX Clear/unset locked & password here for a conference which has
// been LOCKED_REMOTELY.
locked: undefined,
password: undefined,
passwordRequired: undefined
});
// leaving
switch (type) {
case CONFERENCE_LEFT:
if (state.leaving === conference) {
nextState = set(nextState, 'leaving', undefined);
}
break;
case CONFERENCE_WILL_LEAVE:
// A CONFERENCE_WILL_LEAVE is of further consequence only if it is
// expected i.e. if the specified conference is joining or joined.
if (conference === state.joining || conference === state.conference) {
/**
* The JitsiConference instance which is currently in the process of
* being left.
*
* @type {JitsiConference}
*/
nextState = set(nextState, 'leaving', conference);
}
break;
}
return nextState;
@ -254,36 +281,6 @@ function _conferenceWillJoin(state, { conference }) {
});
}
/**
* Reduces a specific Redux action CONFERENCE_WILL_LEAVE of the feature
* base/conference.
*
* @param {Object} state - The Redux state of the feature base/conference.
* @param {Action} action - The Redux action CONFERENCE_WILL_LEAVE to reduce.
* @private
* @returns {Object} The new state of the feature base/conference after the
* reduction of the specified action.
*/
function _conferenceWillLeave(state, { conference }) {
if (state.conference !== conference) {
return state;
}
return assign(state, {
authRequired: undefined,
joining: undefined,
/**
* The JitsiConference instance which is currently in the process of
* being left.
*
* @type {JitsiConference}
*/
leaving: conference,
passwordRequired: undefined
});
}
/**
* Reduces a specific Redux action LOCK_STATE_CHANGED of the feature
* base/conference.