web-apps/apps/common/mobile/lib/controller/collaboration/Collaboration.jsx

93 lines
4 KiB
React
Raw Normal View History

2020-09-29 18:59:57 +00:00
import React, { Component } from 'react'
import { f7 } from 'framework7-react';
2020-09-29 18:59:57 +00:00
import {observer, inject} from "mobx-react"
import { LocalStorage } from '../../../utils/LocalStorage';
import { withTranslation } from 'react-i18next';
2020-08-31 17:31:05 +00:00
2020-09-29 18:59:57 +00:00
class CollaborationController extends Component {
constructor(props){
2021-02-11 23:34:01 +00:00
super(props);
2020-09-29 18:59:57 +00:00
Common.Notifications.on('engineCreated', (api) => {
2020-09-29 18:59:57 +00:00
api.asc_registerCallback('asc_onAuthParticipantsChanged', this.onChangeEditUsers.bind(this));
api.asc_registerCallback('asc_onParticipantsChanged', this.onChangeEditUsers.bind(this));
api.asc_registerCallback('asc_onConnectionStateChanged', this.onUserConnection.bind(this));
api.asc_registerCallback('asc_onCoAuthoringDisconnect', this.onCoAuthoringDisconnect.bind(this));
api.asc_registerCallback('asc_OnTryUndoInFastCollaborative', this.onTryUndoInFastCollaborative.bind(this));
2020-09-29 18:59:57 +00:00
});
2021-06-18 17:49:51 +00:00
Common.Notifications.on('api:disconnect', this.onCoAuthoringDisconnect.bind(this));
Common.Notifications.on('document:ready', this.onDocumentReady.bind(this));
}
onDocumentReady() {
const api = Common.EditorApi.get();
const appOptions = this.props.storeAppOptions;
/** coauthoring begin **/
let isFastCoauth;
if (appOptions.isEdit && appOptions.canLicense && !appOptions.isOffline && appOptions.canCoAuthoring) {
// Force ON fast co-authoring mode
isFastCoauth = true;
api.asc_SetFastCollaborative(isFastCoauth);
if (window.editorType === 'de') {
const value = LocalStorage.getItem((isFastCoauth) ? "de-settings-showchanges-fast" : "de-settings-showchanges-strict");
if (value !== null) {
api.SetCollaborativeMarksShowType(
value === 'all' ? Asc.c_oAscCollaborativeMarksShowType.All :
value === 'none' ? Asc.c_oAscCollaborativeMarksShowType.None : Asc.c_oAscCollaborativeMarksShowType.LastChanges);
} else {
api.SetCollaborativeMarksShowType(isFastCoauth ? Asc.c_oAscCollaborativeMarksShowType.None : Asc.c_oAscCollaborativeMarksShowType.LastChanges);
}
}
} else if (!appOptions.isEdit && appOptions.isRestrictedEdit) {
isFastCoauth = true;
api.asc_SetFastCollaborative(isFastCoauth);
window.editorType === 'de' && api.SetCollaborativeMarksShowType(Asc.c_oAscCollaborativeMarksShowType.None);
api.asc_setAutoSaveGap(1);
} else {
isFastCoauth = false;
api.asc_SetFastCollaborative(isFastCoauth);
window.editorType === 'de' && api.SetCollaborativeMarksShowType(Asc.c_oAscCollaborativeMarksShowType.None);
}
if (appOptions.isEdit) {
let value;
if (window.editorType === 'sse') {
value = appOptions.canAutosave ? 1 : 0; // FORCE AUTOSAVE
} else {
value = isFastCoauth; // Common.localStorage.getItem("de-settings-autosave");
value = (!isFastCoauth && value !== null) ? parseInt(value) : (appOptions.canCoAuthoring ? 1 : 0);
}
api.asc_setAutoSaveGap(value);
}
/** coauthoring end **/
2020-09-29 18:59:57 +00:00
}
onChangeEditUsers(users) {
const storeUsers = this.props.users;
storeUsers.reset(users);
2021-02-18 15:40:54 +00:00
storeUsers.setCurrentUser(this.props.storeAppOptions.user.id);
}
onUserConnection(change) {
this.props.users.connection(change);
}
onCoAuthoringDisconnect() {
this.props.users.resetDisconnected(true);
}
onTryUndoInFastCollaborative() {
const { t } = this.props;
const _t = t("Common.Collaboration", { returnObjects: true });
f7.dialog.alert(_t.textTryUndoRedo, _t.notcriticalErrorTitle);
}
2020-09-29 18:59:57 +00:00
render() {
return null
2020-08-31 17:31:05 +00:00
}
2021-02-11 23:34:01 +00:00
}
2020-08-31 17:31:05 +00:00
export default inject('users', 'storeAppOptions')(observer(withTranslation()(CollaborationController)));