From d4dea225768349cdba6c9b0cfb59e7dbaddf9a80 Mon Sep 17 00:00:00 2001 From: Lyubo Marinov Date: Mon, 14 May 2018 12:37:48 -0500 Subject: [PATCH] [RN] If recent-list knows a domain, then the app knows it --- react/features/recent-list/actionTypes.js | 19 +++- react/features/recent-list/actions.js | 18 ++-- react/features/recent-list/middleware.js | 101 +++++++++++++++++----- react/features/recent-list/reducer.js | 8 +- 4 files changed, 110 insertions(+), 36 deletions(-) diff --git a/react/features/recent-list/actionTypes.js b/react/features/recent-list/actionTypes.js index 5df42cb9a..4377b64ef 100644 --- a/react/features/recent-list/actionTypes.js +++ b/react/features/recent-list/actionTypes.js @@ -2,10 +2,25 @@ /** * Action type to signal a new addition to the list. + * + * { + * type: _STORE_CURRENT_CONFERENCE, + * locationURL: Object + * } + * + * @protected */ -export const STORE_CURRENT_CONFERENCE = Symbol('STORE_CURRENT_CONFERENCE'); +export const _STORE_CURRENT_CONFERENCE = Symbol('_STORE_CURRENT_CONFERENCE'); /** * Action type to signal that a new conference duration info is available. + * + * { + * type: _UPDATE_CONFERENCE_DURATION, + * locationURL: Object + * } + * + * @protected */ -export const UPDATE_CONFERENCE_DURATION = Symbol('UPDATE_CONFERENCE_DURATION'); +export const _UPDATE_CONFERENCE_DURATION + = Symbol('_UPDATE_CONFERENCE_DURATION'); diff --git a/react/features/recent-list/actions.js b/react/features/recent-list/actions.js index eb126021f..aab9b8ce4 100644 --- a/react/features/recent-list/actions.js +++ b/react/features/recent-list/actions.js @@ -1,22 +1,23 @@ // @flow import { - STORE_CURRENT_CONFERENCE, - UPDATE_CONFERENCE_DURATION + _STORE_CURRENT_CONFERENCE, + _UPDATE_CONFERENCE_DURATION } from './actionTypes'; /** * Action to initiate a new addition to the list. * * @param {Object} locationURL - The current location URL. + * @protected * @returns {{ - * type: STORE_CURRENT_CONFERENCE, + * type: _STORE_CURRENT_CONFERENCE, * locationURL: Object * }} */ -export function storeCurrentConference(locationURL: Object) { +export function _storeCurrentConference(locationURL: Object) { return { - type: STORE_CURRENT_CONFERENCE, + type: _STORE_CURRENT_CONFERENCE, locationURL }; } @@ -25,14 +26,15 @@ export function storeCurrentConference(locationURL: Object) { * Action to initiate the update of the duration of the last conference. * * @param {Object} locationURL - The current location URL. + * @protected * @returns {{ - * type: UPDATE_CONFERENCE_DURATION, + * type: _UPDATE_CONFERENCE_DURATION, * locationURL: Object * }} */ -export function updateConferenceDuration(locationURL: Object) { +export function _updateConferenceDuration(locationURL: Object) { return { - type: UPDATE_CONFERENCE_DURATION, + type: _UPDATE_CONFERENCE_DURATION, locationURL }; } diff --git a/react/features/recent-list/middleware.js b/react/features/recent-list/middleware.js index 121a8f38f..fcc750f5a 100644 --- a/react/features/recent-list/middleware.js +++ b/react/features/recent-list/middleware.js @@ -1,9 +1,12 @@ // @flow +import { APP_WILL_MOUNT } from '../app'; import { CONFERENCE_WILL_LEAVE, SET_ROOM } from '../base/conference'; +import { addKnownDomains } from '../base/known-domains'; import { MiddlewareRegistry } from '../base/redux'; +import { parseURIString } from '../base/util'; -import { storeCurrentConference, updateConferenceDuration } from './actions'; +import { _storeCurrentConference, _updateConferenceDuration } from './actions'; /** * Middleware that captures joined rooms so they can be saved into @@ -14,45 +17,99 @@ import { storeCurrentConference, updateConferenceDuration } from './actions'; */ MiddlewareRegistry.register(store => next => action => { switch (action.type) { + case APP_WILL_MOUNT: + return _appWillMount(store, next, action); + case CONFERENCE_WILL_LEAVE: - _updateConferenceDuration(store); - break; + return _conferenceWillLeave(store, next, action); case SET_ROOM: - _maybeStoreCurrentConference(store, action); - break; + return _setRoom(store, next, action); } return next(action); }); +/** + * Notifies the feature recent-list that the redux action {@link APP_WILL_MOUNT} + * is being dispatched in a specific redux store. + * + * @param {Store} store - The redux store in which the specified action is being + * dispatched. + * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the + * specified action to the specified store. + * @param {Action} action - The redux action {@code APP_WILL_MOUNT} which is + * being dispatched in the specified redux store. + * @private + * @returns {*} The result returned by {@code next(action)}. + */ +function _appWillMount({ dispatch, getState }, next, action) { + const result = next(action); + + // It's an opportune time to transfer the feature recent-list's knowledge + // about "known domains" (which is local to the feature) to the feature + // base/known-domains (which is global to the app). + // + // XXX Since the feature recent-list predates the feature calendar-sync and, + // consequently, the feature known-domains, it's possible for the feature + // known-list to know of domains which the feature known-domains is yet to + // discover. + const knownDomains = []; + + for (const { conference } of getState()['features/recent-list']) { + const uri = parseURIString(conference); + let host; + + uri && (host = uri.host) && knownDomains.push(host); + } + knownDomains.length && dispatch(addKnownDomains(knownDomains)); + + return result; +} + +/** + * Updates the duration of the last conference stored in the list. + * + * @param {Store} store - The redux store. + * @param {Dispatch} next - The redux {@code dispatch} function. + * @param {Action} action - The redux action {@link CONFERENCE_WILL_LEAVE}. + * @private + * @returns {*} The result returned by {@code next(action)}. + */ +function _conferenceWillLeave({ dispatch, getState }, next, action) { + dispatch( + _updateConferenceDuration( + getState()['features/base/connection'].locationURL)); + + return next(action); +} + /** * Checks if there is a current conference (upon SET_ROOM action), and saves it * if necessary. * * @param {Store} store - The redux store. * @param {Dispatch} next - The redux {@code dispatch} function. - * @param {Action} action - The redux action. + * @param {Action} action - The redux action {@link SET_ROOM}. * @private - * @returns {void} + * @returns {*} The result returned by {@code next(action)}. */ -function _maybeStoreCurrentConference({ dispatch, getState }, { room }) { - if (room) { +function _setRoom({ dispatch, getState }, next, action) { + if (action.room) { const { locationURL } = getState()['features/base/connection']; - dispatch(storeCurrentConference(locationURL)); + if (locationURL) { + dispatch(_storeCurrentConference(locationURL)); + + // Whatever domain the feature recent-list knows about, the app as a + // whole should know about. + // + // XXX Technically, _storeCurrentConference could be turned into an + // asynchronous action creator which dispatches both + // _STORE_CURRENT_CONFERENCE and addKnownDomains but... + dispatch(addKnownDomains(locationURL.host)); + } } -} -/** - * Updates the duration of the last conference stored in the list. - * - * @param {Store} store - The redux store. - * @private - * @returns {void} - */ -function _updateConferenceDuration({ dispatch, getState }) { - const { locationURL } = getState()['features/base/connection']; - - dispatch(updateConferenceDuration(locationURL)); + return next(action); } diff --git a/react/features/recent-list/reducer.js b/react/features/recent-list/reducer.js index 92fccb5d7..aa2abd67b 100644 --- a/react/features/recent-list/reducer.js +++ b/react/features/recent-list/reducer.js @@ -6,8 +6,8 @@ import { ReducerRegistry } from '../base/redux'; import { PersistenceRegistry } from '../base/storage'; import { - STORE_CURRENT_CONFERENCE, - UPDATE_CONFERENCE_DURATION + _STORE_CURRENT_CONFERENCE, + _UPDATE_CONFERENCE_DURATION } from './actionTypes'; const logger = require('jitsi-meet-logger').getLogger(__filename); @@ -54,10 +54,10 @@ ReducerRegistry.register( case APP_WILL_MOUNT: return _appWillMount(state); - case STORE_CURRENT_CONFERENCE: + case _STORE_CURRENT_CONFERENCE: return _storeCurrentConference(state, action); - case UPDATE_CONFERENCE_DURATION: + case _UPDATE_CONFERENCE_DURATION: return _updateConferenceDuration(state, action); default: