Remove 3 more

This commit is contained in:
Romaric Mourgues
2023-04-20 15:00:26 +02:00
parent c74ce7799a
commit 335301612a
9 changed files with 6 additions and 307 deletions
@@ -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;
@@ -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) {
@@ -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();
}
}
@@ -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();
}
}
@@ -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();
}
@@ -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;
};
@@ -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<typeof setTimeout>;
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;
@@ -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()) {
@@ -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();