2018-03-07 00:28:19 +00:00
|
|
|
// @flow
|
|
|
|
|
2020-05-20 10:57:03 +00:00
|
|
|
import UIEvents from '../../../service/UI/UIEvents';
|
2019-10-04 15:10:19 +00:00
|
|
|
import { getCurrentConference } from '../base/conference';
|
2020-04-06 15:27:03 +00:00
|
|
|
import { setActiveModalId } from '../base/modal';
|
2019-10-04 15:10:19 +00:00
|
|
|
import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
import { TOGGLE_DOCUMENT_EDITING } from './actionTypes';
|
2019-10-04 15:10:19 +00:00
|
|
|
import { setDocumentEditingState, setDocumentUrl } from './actions';
|
2020-04-06 15:27:03 +00:00
|
|
|
import { SHARE_DOCUMENT_VIEW_ID } from './constants';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
declare var APP: Object;
|
|
|
|
|
2019-10-04 15:10:19 +00:00
|
|
|
const ETHERPAD_COMMAND = 'etherpad';
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Middleware that captures actions related to collaborative document editing
|
|
|
|
* and notifies components not hooked into redux.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-10-04 15:10:19 +00:00
|
|
|
MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
|
2018-03-07 00:28:19 +00:00
|
|
|
switch (action.type) {
|
2019-10-04 15:10:19 +00:00
|
|
|
case TOGGLE_DOCUMENT_EDITING: {
|
|
|
|
if (typeof APP === 'undefined') {
|
2020-04-06 15:27:03 +00:00
|
|
|
const editing = !getState()['features/etherpad'].editing;
|
2019-10-04 15:10:19 +00:00
|
|
|
|
2020-04-06 15:27:03 +00:00
|
|
|
dispatch(setDocumentEditingState(editing));
|
|
|
|
|
|
|
|
if (editing) {
|
|
|
|
dispatch(setActiveModalId(SHARE_DOCUMENT_VIEW_ID));
|
|
|
|
} else if (getState()['features/base/modal'].activeModalId === SHARE_DOCUMENT_VIEW_ID) {
|
|
|
|
dispatch(setActiveModalId(undefined));
|
|
|
|
}
|
2019-10-04 15:10:19 +00:00
|
|
|
} else {
|
|
|
|
APP.UI.emitEvent(UIEvents.ETHERPAD_CLICKED);
|
|
|
|
}
|
2018-03-07 00:28:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-10-04 15:10:19 +00:00
|
|
|
}
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
2019-10-04 15:10:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up state change listener to perform maintenance tasks when the conference
|
|
|
|
* is left or failed, e.g. clear messages or close the chat modal if it's left
|
|
|
|
* open.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
state => getCurrentConference(state),
|
|
|
|
(conference, { dispatch, getState }, previousConference) => {
|
|
|
|
if (conference) {
|
|
|
|
conference.addCommandListener(ETHERPAD_COMMAND,
|
|
|
|
({ value }) => {
|
|
|
|
let url;
|
|
|
|
const { etherpad_base: etherpadBase } = getState()['features/base/config'];
|
|
|
|
|
|
|
|
if (etherpadBase) {
|
|
|
|
const u = new URL(value, etherpadBase);
|
|
|
|
|
|
|
|
url = u.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(setDocumentUrl(url));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (previousConference) {
|
|
|
|
dispatch(setDocumentUrl(undefined));
|
|
|
|
}
|
|
|
|
});
|