Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
孙永强 committed Nov 25, 2024
1 parent 3b3af38 commit 71a55c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
20 changes: 12 additions & 8 deletions frontend/src/pages/lib-content-view/lib-content-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Detail from '../../components/dirent-detail';
import DirColumnView from '../../components/dir-view-mode/dir-column-view';
import SelectedDirentsToolbar from '../../components/toolbar/selected-dirents-toolbar';
import { VIEW_TYPE } from '../../metadata/constants';
import WebSocketService from '../../utils/websocket-service';
import WebSocketClient from '../../utils/websocket-service';
import '../../css/lib-content-view.css';

dayjs.extend(relativeTime);
Expand All @@ -54,7 +54,7 @@ class LibContentView extends React.Component {
if (storedTreePanelState != undefined) {
isTreePanelShown = storedTreePanelState == 'true';
}
this.socket = new WebSocketService(this.onMessageCallback, this.props.repoID);
this.socket = new WebSocketClient(this.onMessageCallback, this.props.repoID);
this.onMessageCallback = this.onMessageCallback.bind(this);
this.state = {
currentMode: cookie.load('seafile_view_mode') || LIST_MODE,
Expand Down Expand Up @@ -164,14 +164,18 @@ class LibContentView extends React.Component {
if (dirRouter === notifRouter) {
const dirent = { name: data.content.path.split('/').pop() };
if (data.content.change_event === 'locked') {
if (dirent.name.endsWith('.sdoc')) {
if (data.content.expire === -1) {
this.updateDirent(dirent, 'is_freezed', true);
this.updateDirent(dirent, 'is_locked', true);
this.updateDirent(dirent, 'locked_by_me', true);
this.updateDirent(dirent, 'lock_owner_name', data.content.lock_user[0]);
} else {
this.updateDirent(dirent, 'is_freezed', false);
this.updateDirent(dirent, 'is_locked', true);
this.updateDirent(dirent, 'locked_by_me', false);
this.updateDirent(dirent, 'lock_owner_name', data.content.lock_user[0]);
}
this.updateDirent(dirent, 'is_locked', true);
this.updateDirent(dirent, 'locked_by_me', true);
this.updateDirent(dirent, 'lock_owner_name', data.content.lock_user[0]);
}
else if (data.content.change_event === 'unlocked') {
} else if (data.content.change_event === 'unlocked') {
this.updateDirent(dirent, 'is_locked', false);
this.updateDirent(dirent, 'locked_by_me', false);
this.updateDirent(dirent, 'lock_owner_name', '');
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/utils/websocket-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { userAPI } from './user-api';
import { notificationServerUrl } from './constants';


class WebSocketService {
class WebSocketClient {
constructor(onMessageCallback, repoId) {

this.url = notificationServerUrl; // WebSocket address;
Expand All @@ -24,7 +24,13 @@ class WebSocketService {
// listen message from WebSocket server
this.socket.onmessage = (event) => {
const parsedData = JSON.parse(event.data);
this.onMessageCallback(parsedData);
// jwt-expire reconnect
if (parsedData.type === 'jwt-expired') {
const msg = this.formatSubscriptionMsg();
this.socket.send(JSON.stringify(msg));
} else {
this.onMessageCallback(parsedData);
}
};

this.socket.onerror = (error) => {
Expand Down Expand Up @@ -94,4 +100,4 @@ class WebSocketService {
}
}

export default WebSocketService;
export default WebSocketClient;

0 comments on commit 71a55c2

Please sign in to comment.