1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-05 00:43:53 +00:00

modify collab server

This commit is contained in:
wangjianhui
2018-12-20 17:48:27 +08:00
parent 5d0386bbad
commit 0349918272
4 changed files with 54 additions and 26 deletions

View File

@@ -51,6 +51,7 @@ class DirView extends React.Component {
// eg: http://127.0.0.1:8000/library/repo_id/repo_name/**/**/\
let location = decodeURIComponent(window.location.href);
let repoID = this.props.repoID;
collabServer.watchRepo(repoID, this.onRepoUpdateEvent);
seafileAPI.getRepoInfo(repoID).then(res => {
let repoInfo = new RepoInfo(res.data);
this.setState({
@@ -70,7 +71,27 @@ class DirView extends React.Component {
}
});
}
componentWillUnmount() {
collabServer.unwatchRepo(this.props.repoID);
}
onRepoUpdateEvent = () => {
let repoID = this.props.repoID;
let { path, dirID } = this.state;
seafileAPI.dirMetaData(repoID, path).then((res) => {
if (res.data.id !== dirID) {
toaster.notify(
<span>
{gettext('This folder has been updated. ')}
<a href='' >{gettext('Refresh')}</a>
</span>,
{duration: 3600}
);
}
})
}
updateDirentList = (filePath) => {
let repoID = this.state.repoID;
this.setState({isDirentListLoading: true});
@@ -83,7 +104,6 @@ class DirView extends React.Component {
direntList: direntList,
dirID: res.headers.oid,
});
collabServer.watchRepo(this.state.repoID, this.state.path, this.state.dirID);
}).catch(() => {
this.setState({pathExist: false});
});

View File

@@ -7,9 +7,6 @@ import ModalPortal from '../modal-portal';
import CreateFile from '../../components/dialog/create-file-dialog';
import '../../css/tip-for-new-md.css';
import io from 'socket.io-client';
import { seafileAPI } from '../../utils/seafile-api';
import toaster from '../../components/toast';
const propTypes = {
path: PropTypes.string.isRequired,

View File

@@ -63,6 +63,7 @@ class Wiki extends Component {
}
componentDidMount() {
collabServer.watchRepo(repoID, this.onRepoUpdateEvent);
seafileAPI.getRepoInfo(repoID).then(res => {
this.setState({
libNeedDecrypt: res.data.lib_need_decrypt,
@@ -82,6 +83,24 @@ class Wiki extends Component {
});
}
componentWillUnmount() {
collabServer.unwatchRepo(repoID);
}
onRepoUpdateEvent = () => {
let { path, dirID } = this.state;
seafileAPI.dirMetaData(repoID, path).then((res) => {
if (res.data.id !== dirID) {
toaster.notify(
<span>
{gettext('This folder has been updated. ')}
<a href='' >{gettext('Refresh')}</a>
</span>,
{duration: 3600}
);
}
})
}
deleteItemAjaxCallback(path, isDir) {
let node = this.state.treeData.getNodeByPath(path);
@@ -282,7 +301,6 @@ class Wiki extends Component {
isDirentListLoading: false,
dirID: res.headers.oid,
});
collabServer.watchRepo(repoID, this.state.path, this.state.dirID);
});
}

View File

@@ -1,14 +1,11 @@
import React from 'react';
import io from 'socket.io-client';
import toaster from '../components/toast';
import { seafileAPI } from './seafile-api';
import { gettext, name, username, contactEmail, seafileCollabServer } from './constants';
import { name, username, contactEmail, seafileCollabServer } from './constants';
const socket = io(seafileCollabServer);
class CollabServer {
watchRepo(repoID, path, dirID) {
watchRepo(repoID, fn) {
socket.emit('repo_update', {
request: 'watch_update',
repo_id: repoID,
@@ -19,23 +16,19 @@ class CollabServer {
},
});
socket.on('repo_update', () => {
seafileAPI.dirMetaData(repoID, path).then((res) => {
if (res.data.id !== dirID) {
toaster.notify(
<span>
{gettext('This folder has been updated. ')}
<a href='' >{gettext('Refresh')}</a>
</span>,
{duration: 3600}
);
}
})
})
socket.on('repo_update', fn)
}
unwatchRepo() {
socket.off()
unwatchRepo(repoID) {
socket.emit('repo_update', {
request: 'unwatch_update',
repo_id: repoID,
user: {
name: name,
username: username,
contact_email: contactEmail,
},
});
}
}