From 335301612a4b3596a4b23ffeaeb3b567bf09261d Mon Sep 17 00:00:00 2001 From: Romaric Mourgues Date: Thu, 20 Apr 2023 15:00:26 +0200 Subject: [PATCH] Remove 3 more --- .../frontend/src/app/components/user/user.jsx | 7 - .../CollectionsV1/Collections/Collection.js | 38 +---- .../src/app/deprecated/user/CurrentUser.ts | 9 +- .../app/deprecated/workspaces/workspaces.jsx | 3 - .../services/application-service.ts | 4 - .../users/hooks/use-users-listener.ts | 26 --- .../users/services/listen-users-service.ts | 156 ------------------ .../services/workspace-members-service.ts | 17 +- .../services/workspaces-listener-service.ts | 53 ------ 9 files changed, 6 insertions(+), 307 deletions(-) delete mode 100644 tdrive/frontend/src/app/features/users/hooks/use-users-listener.ts delete mode 100755 tdrive/frontend/src/app/features/users/services/listen-users-service.ts delete mode 100755 tdrive/frontend/src/app/features/workspaces/services/workspaces-listener-service.ts diff --git a/tdrive/frontend/src/app/components/user/user.jsx b/tdrive/frontend/src/app/components/user/user.jsx index 0e9ff5ef..cb86cad3 100755 --- a/tdrive/frontend/src/app/components/user/user.jsx +++ b/tdrive/frontend/src/app/components/user/user.jsx @@ -2,7 +2,6 @@ import React, { Component } from 'react'; import UserService from '@features/users/services/current-user-service'; -import ListenUsers from '@features/users/services/listen-users-service'; import UserOnlineStatus from '../online-user-status/online-user-status'; import './user.scss'; @@ -11,12 +10,6 @@ export default class User extends Component { constructor(props) { super(); } - UNSAFE_componentWillMount() { - ListenUsers.listenUser(this.props.user.id); - } - componentWillUnmount() { - ListenUsers.cancelListenUser(this.props.user.id); - } render() { var user = this.props.user; var notifications_disabled = false; diff --git a/tdrive/frontend/src/app/deprecated/CollectionsV1/Collections/Collection.js b/tdrive/frontend/src/app/deprecated/CollectionsV1/Collections/Collection.js index 5f375182..3b6cfa4d 100755 --- a/tdrive/frontend/src/app/deprecated/CollectionsV1/Collections/Collection.js +++ b/tdrive/frontend/src/app/deprecated/CollectionsV1/Collections/Collection.js @@ -1,7 +1,6 @@ import Api from '@features/global/framework/api-service'; import Observable from '@deprecated/CollectionsV1/observable.js'; import Number from '@features/global/utils/Numbers'; -import MultipleSecuredConnections from './MultipleSecuredConnections.js'; import LocalStorage from '@features/global/framework/local-storage-service'; /** Collection * Act like a doctrine repository and try to be allways in sync with server in realtime @@ -65,24 +64,6 @@ export default class Collection extends Observable { this.sources_to_be_removed_timeout = {}; this.sources_on_event = {}; this._last_modified = {}; - - this.connections = new MultipleSecuredConnections((event, data) => { - Object.keys(this.sources_on_event).forEach(source_key => { - if (this.sources_on_event[source_key].routes.indexOf(data._route) >= 0) { - this.sources_on_event[source_key].callback(event, data); - } - }); - - if (event === 'event') { - if (data.multiple && data.multiple.forEach) { - data.multiple.forEach(item => { - this.ws_message(item); - }); - } else { - this.ws_message(data); - } - } - }); } updatedOptions() { @@ -345,7 +326,6 @@ export default class Collection extends Observable { var ws_identifier = collection_id || this.collection_id; // eslint-disable-next-line no-redeclare var options = options || this.options || {}; - this.connections.addConnection(ws_identifier, options, http_options, key); return true; } @@ -363,7 +343,6 @@ export default class Collection extends Observable { if (this.total_subscribe_by_route[collection_id] <= 0) { var ws_identifier = collection_id || this.collection_id; - this.connections.removeConnection(ws_identifier); } return; @@ -865,14 +844,7 @@ export default class Collection extends Observable { } //To use only on very specific cases !!! - shareRemove(deleted_front_id) { - this.connections.publish({ - client_id: this.client_id, - action: 'remove', - object_type: this.object_type, - front_id: deleted_front_id, - }); - } + shareRemove(deleted_front_id) {} //To use only on very specific cases !!! share(object) { @@ -884,13 +856,6 @@ export default class Collection extends Observable { delete object[key]; } }); - - this.connections.publish({ - client_id: this.client_id, - action: 'save', - object_type: this.object_type, - object: object, - }); } ws_message(data) { @@ -927,7 +892,6 @@ export default class Collection extends Observable { data: data, client_id: this.client_id, }; - this.connections.publish(_d); } addWebsocketListener(callback) { diff --git a/tdrive/frontend/src/app/deprecated/user/CurrentUser.ts b/tdrive/frontend/src/app/deprecated/user/CurrentUser.ts index b89dd360..e3fff98d 100755 --- a/tdrive/frontend/src/app/deprecated/user/CurrentUser.ts +++ b/tdrive/frontend/src/app/deprecated/user/CurrentUser.ts @@ -4,7 +4,6 @@ import $ from 'jquery'; import Login from '@features/auth/login-service'; import Collections from '@deprecated/CollectionsV1/Collections/Collections'; import Api from '@features/global/framework/api-service'; -import ws from '@deprecated/websocket/websocket'; import Observable from '@deprecated/CollectionsV1/observable'; import Number from '@features/global/utils/Numbers'; import AlertManager from '@features/global/services/alert-manager-service'; @@ -87,11 +86,7 @@ class CurrentUser extends Observable { const data = { status: user.tutorial_status, }; - Api.post('/ajax/users/account/set_tutorial_status', data, () => { - ws.publish('users/' + Login.currentUserId, { - user: { tutorial_status: user.tutorial_status }, - }); - }); + Api.post('/ajax/users/account/set_tutorial_status', data, () => {}); } updateUserName(username: string) { @@ -106,7 +101,6 @@ class CurrentUser extends Observable { Api.post('/ajax/users/account/username', { username }, (res: any) => { that.loading = false; if (res.errors.length === 0) { - ws.publish('users/' + Login.currentUserId, { user: update }); that.errorUsernameExist = false; } else { that.errorUsernameExist = true; @@ -166,7 +160,6 @@ class CurrentUser extends Observable { update.thumbnail = resp.data.thumbnail || ''; } Collections.get('users').updateObject(update); - ws.publish('users/' + Login.currentUserId, { user: update }); that.notify(); } } diff --git a/tdrive/frontend/src/app/deprecated/workspaces/workspaces.jsx b/tdrive/frontend/src/app/deprecated/workspaces/workspaces.jsx index 069eec7c..56da0d52 100755 --- a/tdrive/frontend/src/app/deprecated/workspaces/workspaces.jsx +++ b/tdrive/frontend/src/app/deprecated/workspaces/workspaces.jsx @@ -1,7 +1,6 @@ import DepreciatedCollections from '@deprecated/CollectionsV1/Collections/Collections.js'; import Observable from '@deprecated/CollectionsV1/observable.js'; import { default as popupManager, default as PopupManager } from '@deprecated/popupManager/popupManager.js'; -import ws from '@deprecated/websocket/websocket.js'; import JWTStorage from '@features/auth/jwt-storage-service'; import loginService from '@features/auth/login-service'; import ConsoleService from '@features/console/services/console-service'; @@ -239,8 +238,6 @@ class Workspaces extends Observable { that.error_identity_badimage = true; that.notify(); } else { - var update = resp.data; - ws.publish('workspace/' + update.id, { workspace: update }); that.notify(); } } diff --git a/tdrive/frontend/src/app/features/applications/services/application-service.ts b/tdrive/frontend/src/app/features/applications/services/application-service.ts index 9fbc240c..a144741d 100644 --- a/tdrive/frontend/src/app/features/applications/services/application-service.ts +++ b/tdrive/frontend/src/app/features/applications/services/application-service.ts @@ -3,7 +3,6 @@ import Logger from 'app/features/global/framework/logger-service'; import AccessRightsService from 'app/features/workspace-members/services/workspace-members-access-rights-service'; import CurrentUser from 'app/deprecated/user/CurrentUser'; import JWT from 'app/features/auth/jwt-storage-service'; -import WorkspacesListener from '../../workspaces/services/workspaces-listener-service'; import LocalStorage from '../../global/framework/local-storage-service'; import WebSocket from '../../global/types/websocket-types'; @@ -29,14 +28,11 @@ class Application { const ws = WebSocket.get(); ws.connect(); - WorkspacesListener.startListen(); AccessRightsService.resetLevels(); - CurrentUser.start(); } stop(): void { - WorkspacesListener.cancelListen(); LocalStorage.clear(); JWT.clear(); } diff --git a/tdrive/frontend/src/app/features/users/hooks/use-users-listener.ts b/tdrive/frontend/src/app/features/users/hooks/use-users-listener.ts deleted file mode 100644 index fed5c751..00000000 --- a/tdrive/frontend/src/app/features/users/hooks/use-users-listener.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { useState, useEffect } from 'react'; -import { isArray } from 'lodash'; -import UserListenerService from '@features/users/services/listen-users-service'; -import Collections from '@deprecated/CollectionsV1/Collections/Collections'; -import UsersService from '@features/users/services/current-user-service'; -import userAsyncGet from '@features/users/utils/async-get'; - -export const useUsersListener = (usersIds: string[] = []) => { - const users = (isArray(usersIds) ? usersIds : []).filter( - e => (usersIds.length || 0) === 1 || e !== UsersService.getCurrentUserId(), - ); - Collections.get('users').useListener(useState, users); - - useEffect(() => { - users.forEach(userId => { - UserListenerService.listenUser(userId); - userAsyncGet(userId); - }); - - return () => { - users.forEach(userId => UserListenerService.cancelListenUser(userId)); - }; - }, [users]); - - return users; -}; diff --git a/tdrive/frontend/src/app/features/users/services/listen-users-service.ts b/tdrive/frontend/src/app/features/users/services/listen-users-service.ts deleted file mode 100755 index d98ba887..00000000 --- a/tdrive/frontend/src/app/features/users/services/listen-users-service.ts +++ /dev/null @@ -1,156 +0,0 @@ -/* eslint-disable @typescript-eslint/no-this-alias */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import ws from '@deprecated/websocket/websocket'; -import Collections from '@deprecated/CollectionsV1/Collections/Collections'; -import UserService from './current-user-service'; -import Globals from '@features/global/services/globals-tdrive-app-service'; -import userAsyncGet from '@features/users/utils/async-get'; - -type Timeout = ReturnType; - -class ListenUsers { - users_repository: any; - connectedPing: { [key: string]: Timeout }; - listenerCount: { [key: string]: number }; - pingTimeouts: { [key: string]: Timeout }; - was_connected_last_check: { [key: string]: boolean }; - lastPong: number; - - constructor() { - this.users_repository = Collections.get('users'); - this.listenerCount = {}; - this.connectedPing = {}; - this.pingTimeouts = {}; - this.was_connected_last_check = {}; - this.lastPong = 0; - (Globals.window as any).listenUsers = this; - } - - /** - * Check if the given user is active: new Date().getTime() - ws.lastAlive < 1000*60*5 - * - * @param idUser - */ - ping(idUser: string): void { - ws.publish(`users/${idUser}`, { - ping: true, - user: { connected: true, id: UserService.getCurrentUserId() }, - }); - - if (this.pingTimeouts[idUser]) { - clearTimeout(this.pingTimeouts[idUser]); - } - - this.pingTimeouts[idUser] = setTimeout(() => { - //Only say this to me ! - const user = Collections.get('users').find(idUser); - - if (user) { - if (user.connected) { - user.connected = false; - this.users_repository.updateObject(user); - } - } - this.was_connected_last_check[idUser] = false; - }, 5000); - } - - pong(): void { - this.lastPong = new Date().getTime(); - - ws.publish(`users/${UserService.getCurrentUserId()}`, { - user: { connected: true, id: UserService.getCurrentUserId() }, - }); - } - - listenUser(idUser: string): void { - if (!idUser) { - return; - } - - if (!this.listenerCount[idUser]) { - this.listenerCount[idUser] = 0; - } - this.listenerCount[idUser] += 1; - - const that = this; - if (this.listenerCount[idUser] === 1) { - ws.subscribe( - `users/${idUser}`, - (_uri: string, data: any) => { - /*if (idUser == UserServiceImpl.getCurrentUserId()) { - if (data.ping) { - that.pong(); - } - }*/ - if (data.user && data.user.id) { - /*that.setUserPingTimeout(data.user.id); - if (data.user.connected && that.pingTimeouts[idUser]) { - clearTimeout(that.pingTimeouts[idUser]); - }*/ - if (that.users_repository.find(data.user.id)) { - that.was_connected_last_check[idUser] = data.user.connected; - if ( - data.user.username || - data.user.notifications_preferences || - data.user.connected !== that.users_repository.find(data.user.id).connected - ) { - that.users_repository.updateObject(data.user); - } - } else if (data.user.id) { - userAsyncGet(data.user.id); - } - } - }, - null, - ); - - if (idUser !== UserService.getCurrentUserId()) { - /*setTimeout(() => { - if (idUser != UserServiceImpl.getCurrentUserId()) { - this.setUserPingTimeout(idUser); - this.ping(idUser); - } - }, 1000); - - if (new Date().getTime() - this.lastPong > 60000) { - this.pong(); - }*/ - } - } - } - - setUserPingTimeout(idUser: string): void { - if (this.connectedPing[idUser]) { - clearTimeout(this.connectedPing[idUser]); - } - - this.connectedPing[idUser] = setTimeout(() => { - this.ping(idUser); - this.setUserPingTimeout(idUser); - }, 600000); - } - - cancelListenUser(idUser: string) { - if (!idUser) { - return; - } - - if (this.listenerCount[idUser]) { - this.listenerCount[idUser] += -1; - } - - if (!this.listenerCount[idUser] || this.listenerCount[idUser] === 0) { - ws.unsubscribe(`users/${idUser}`, null, null); - - if (this.connectedPing[idUser]) { - clearInterval(this.connectedPing[idUser]); - } - } - } -} - -const service = new ListenUsers(); -(Globals.services as any) = service; - -export default service; diff --git a/tdrive/frontend/src/app/features/workspace-members/services/workspace-members-service.ts b/tdrive/frontend/src/app/features/workspace-members/services/workspace-members-service.ts index b66b9dd9..0683464d 100755 --- a/tdrive/frontend/src/app/features/workspace-members/services/workspace-members-service.ts +++ b/tdrive/frontend/src/app/features/workspace-members/services/workspace-members-service.ts @@ -2,18 +2,14 @@ /* eslint-disable @typescript-eslint/no-this-alias */ /* eslint-disable @typescript-eslint/no-empty-function */ /* eslint-disable @typescript-eslint/no-explicit-any */ -import Languages from '@features/global/services/languages-service'; import Observable from '@deprecated/CollectionsV1/observable.js'; -import User from '@features/users/services/current-user-service'; -import Api from '@features/global/framework/api-service'; -import ws from '@deprecated/websocket/websocket.js'; -import Collections from '@deprecated/CollectionsV1/Collections/Collections.js'; import workspaceService from '@deprecated/workspaces/workspaces.jsx'; -import Numbers from '@features/global/utils/Numbers'; -import WorkspaceUserRights from '@features/workspaces/services/workspace-user-rights-service'; -import CurrentUser from '@deprecated/user/CurrentUser'; +import Api from '@features/global/framework/api-service'; import AlertManager from '@features/global/services/alert-manager-service'; import Globals from '@features/global/services/globals-tdrive-app-service'; +import Languages from '@features/global/services/languages-service'; +import User from '@features/users/services/current-user-service'; +import WorkspaceUserRights from '@features/workspaces/services/workspace-user-rights-service'; const prefixRoute = '/internal/services/workspaces/v1'; @@ -68,11 +64,6 @@ class WorkspacesUsers extends Observable { return (this.users_by_workspace || {})[workspace_id] || {}; } - unload(workspace_id: string) { - ws.unsubscribe('workspace_users/' + workspace_id, null, null); - } - - load(workspace_id: string, reset_offset: string, options: any) {} canShowUserInWorkspaceList(member: any) { // if user is interne or wexterne => no restriction if (!WorkspaceUserRights.isInvite()) { diff --git a/tdrive/frontend/src/app/features/workspaces/services/workspaces-listener-service.ts b/tdrive/frontend/src/app/features/workspaces/services/workspaces-listener-service.ts deleted file mode 100755 index c5a9b675..00000000 --- a/tdrive/frontend/src/app/features/workspaces/services/workspaces-listener-service.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import ws from '@deprecated/websocket/websocket.js'; -import Workspaces from '@deprecated/workspaces/workspaces.jsx'; -import User from '@features/users/services/current-user-service'; -import LoginService from '@features/auth/login-service'; -import { RightsOrNone } from '../../workspace-members/services/workspace-members-access-rights-service'; -import Logger from '@features/global/framework/logger-service'; - -type WebsocketWorkspace = { - type: 'remove' | 'add' | 'update_group_privileges' | 'update_workspace_level'; - group_id: string; - workspace_id: string; - level: RightsOrNone; - workspace: any; // TODO - privileges: any; // TODO -}; - -class WorkspacesListener { - private logger: Logger.Logger; - - constructor() { - this.logger = Logger.getLogger('WorkspacesListener'); - } - - startListen() { - this.logger.debug('Start listener'); - - ws.subscribe( - `workspaces_of_user/${User.getCurrentUserId()}`, - (_uri: any, data: WebsocketWorkspace) => { - this.logger.debug('Got a message', data); - LoginService.updateUser(); - - if (data.workspace) { - if (data.type === 'remove') { - Workspaces.removeFromUser(data.workspace); - Workspaces.notify(); - } else if (data.type === 'add') { - Workspaces.notify(); - } - } - }, - null, - ); - } - - cancelListen() { - this.logger.debug('Cancel listener'); - ws.unsubscribe(`workspaces_of_user/${User.getCurrentUserId()}`, null, null); - } -} - -export default new WorkspacesListener();