mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-07 18:03:48 +00:00
modify collab server
This commit is contained in:
@@ -51,6 +51,7 @@ class DirView extends React.Component {
|
|||||||
// eg: http://127.0.0.1:8000/library/repo_id/repo_name/**/**/\
|
// eg: http://127.0.0.1:8000/library/repo_id/repo_name/**/**/\
|
||||||
let location = decodeURIComponent(window.location.href);
|
let location = decodeURIComponent(window.location.href);
|
||||||
let repoID = this.props.repoID;
|
let repoID = this.props.repoID;
|
||||||
|
collabServer.watchRepo(repoID, this.onRepoUpdateEvent);
|
||||||
seafileAPI.getRepoInfo(repoID).then(res => {
|
seafileAPI.getRepoInfo(repoID).then(res => {
|
||||||
let repoInfo = new RepoInfo(res.data);
|
let repoInfo = new RepoInfo(res.data);
|
||||||
this.setState({
|
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) => {
|
updateDirentList = (filePath) => {
|
||||||
let repoID = this.state.repoID;
|
let repoID = this.state.repoID;
|
||||||
this.setState({isDirentListLoading: true});
|
this.setState({isDirentListLoading: true});
|
||||||
@@ -83,7 +104,6 @@ class DirView extends React.Component {
|
|||||||
direntList: direntList,
|
direntList: direntList,
|
||||||
dirID: res.headers.oid,
|
dirID: res.headers.oid,
|
||||||
});
|
});
|
||||||
collabServer.watchRepo(this.state.repoID, this.state.path, this.state.dirID);
|
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
this.setState({pathExist: false});
|
this.setState({pathExist: false});
|
||||||
});
|
});
|
||||||
|
@@ -7,9 +7,6 @@ import ModalPortal from '../modal-portal';
|
|||||||
import CreateFile from '../../components/dialog/create-file-dialog';
|
import CreateFile from '../../components/dialog/create-file-dialog';
|
||||||
|
|
||||||
import '../../css/tip-for-new-md.css';
|
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 = {
|
const propTypes = {
|
||||||
path: PropTypes.string.isRequired,
|
path: PropTypes.string.isRequired,
|
||||||
|
@@ -63,6 +63,7 @@ class Wiki extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
collabServer.watchRepo(repoID, this.onRepoUpdateEvent);
|
||||||
seafileAPI.getRepoInfo(repoID).then(res => {
|
seafileAPI.getRepoInfo(repoID).then(res => {
|
||||||
this.setState({
|
this.setState({
|
||||||
libNeedDecrypt: res.data.lib_need_decrypt,
|
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) {
|
deleteItemAjaxCallback(path, isDir) {
|
||||||
let node = this.state.treeData.getNodeByPath(path);
|
let node = this.state.treeData.getNodeByPath(path);
|
||||||
@@ -282,7 +301,6 @@ class Wiki extends Component {
|
|||||||
isDirentListLoading: false,
|
isDirentListLoading: false,
|
||||||
dirID: res.headers.oid,
|
dirID: res.headers.oid,
|
||||||
});
|
});
|
||||||
collabServer.watchRepo(repoID, this.state.path, this.state.dirID);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,14 +1,11 @@
|
|||||||
import React from 'react';
|
|
||||||
import io from 'socket.io-client';
|
import io from 'socket.io-client';
|
||||||
import toaster from '../components/toast';
|
import { name, username, contactEmail, seafileCollabServer } from './constants';
|
||||||
import { seafileAPI } from './seafile-api';
|
|
||||||
import { gettext, name, username, contactEmail, seafileCollabServer } from './constants';
|
|
||||||
|
|
||||||
const socket = io(seafileCollabServer);
|
const socket = io(seafileCollabServer);
|
||||||
|
|
||||||
class CollabServer {
|
class CollabServer {
|
||||||
|
|
||||||
watchRepo(repoID, path, dirID) {
|
watchRepo(repoID, fn) {
|
||||||
socket.emit('repo_update', {
|
socket.emit('repo_update', {
|
||||||
request: 'watch_update',
|
request: 'watch_update',
|
||||||
repo_id: repoID,
|
repo_id: repoID,
|
||||||
@@ -19,23 +16,19 @@ class CollabServer {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('repo_update', () => {
|
socket.on('repo_update', fn)
|
||||||
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}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unwatchRepo() {
|
unwatchRepo(repoID) {
|
||||||
socket.off()
|
socket.emit('repo_update', {
|
||||||
|
request: 'unwatch_update',
|
||||||
|
repo_id: repoID,
|
||||||
|
user: {
|
||||||
|
name: name,
|
||||||
|
username: username,
|
||||||
|
contact_email: contactEmail,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user