♻️Removed unused websockets
This commit is contained in:
@@ -1,12 +1,6 @@
|
||||
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
||||
import _ from "lodash";
|
||||
import { v4 } from "uuid";
|
||||
import { CrudException } from "../../../../core/platform/framework/api/crud-service";
|
||||
import { localEventBus } from "../../../../core/platform/framework/event-bus";
|
||||
import {
|
||||
RealtimeApplicationEvent,
|
||||
RealtimeBaseBusEvent,
|
||||
} from "../../../../core/platform/services/realtime/types";
|
||||
import { ResourceGetResponse } from "../../../../utils/types";
|
||||
import {
|
||||
ApplicationObject,
|
||||
@@ -84,26 +78,6 @@ export class ApplicationsApiController {
|
||||
throw CrudException.forbidden("Application not found");
|
||||
}
|
||||
|
||||
const body = request.body;
|
||||
|
||||
const data = {
|
||||
action: "configure",
|
||||
application: {
|
||||
id: app_id,
|
||||
identity: application.identity,
|
||||
},
|
||||
form: body.form,
|
||||
connection_id: body.connection_id,
|
||||
hidden_data: {},
|
||||
configurator_id: v4(),
|
||||
};
|
||||
|
||||
localEventBus.publish("realtime:event", {
|
||||
room: "/me/" + body.user_id,
|
||||
type: "application",
|
||||
data,
|
||||
} as RealtimeBaseBusEvent<RealtimeApplicationEvent>);
|
||||
|
||||
return { status: "ok" };
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import { WebsocketMetadata } from "../../utils/types";
|
||||
|
||||
export function getCompanyApplicationRooms(companyId: string): WebsocketMetadata[] {
|
||||
return [
|
||||
{
|
||||
room: getCompanyApplicationRoom(companyId),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export function getCompanyApplicationRoom(companyApplicationId: string): string {
|
||||
return `/company-application/${companyApplicationId}`;
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
import { PublicApplicationObject } from "../../entities/application";
|
||||
import { CompanyExecutionContext } from "../types";
|
||||
import { CrudController } from "../../../../core/platform/services/webserver/types";
|
||||
import { getCompanyApplicationRooms } from "../../realtime";
|
||||
import gr from "../../../global-resolver";
|
||||
|
||||
export class CompanyApplicationController
|
||||
@@ -55,11 +54,6 @@ export class CompanyApplicationController
|
||||
return {
|
||||
resources: resources.getEntities().map(ca => ca.application),
|
||||
next_page_token: resources.nextPage?.page_token,
|
||||
websockets:
|
||||
gr.platformServices.realtime.sign(
|
||||
getCompanyApplicationRooms(request.params.company_id),
|
||||
context.user.id,
|
||||
) || [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,13 +53,8 @@ import {
|
||||
makeStandaloneAccessLevel,
|
||||
getItemScope,
|
||||
} from "./access-check";
|
||||
import { websocketEventBus } from "../../../core/platform/services/realtime/bus";
|
||||
import archiver from "archiver";
|
||||
import internal from "stream";
|
||||
import {
|
||||
RealtimeEntityActionType,
|
||||
ResourcePath,
|
||||
} from "../../../core/platform/services/realtime/types";
|
||||
import config from "config";
|
||||
export class DocumentsService {
|
||||
version: "1";
|
||||
@@ -410,9 +405,6 @@ export class DocumentsService {
|
||||
//TODO[ASH] update item size only for files, there is not need to do during direcotry creation
|
||||
await updateItemSize(driveItem.parent_id, this.repository, context);
|
||||
|
||||
//TODO[ASH] there is no need to notify websocket, until we implement user notification
|
||||
await this.notifyWebsocket(driveItem.parent_id, context);
|
||||
|
||||
await globalResolver.platformServices.messageQueue.publish<DocumentsMessageQueueRequest>(
|
||||
"services:documents:process",
|
||||
{
|
||||
@@ -681,11 +673,7 @@ export class DocumentsService {
|
||||
await this.update(item.id, item, context);
|
||||
}
|
||||
await updateItemSize(previousParentId, this.repository, context);
|
||||
|
||||
await this.notifyWebsocket(previousParentId, context);
|
||||
}
|
||||
|
||||
await this.notifyWebsocket("trash", context);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -963,19 +951,6 @@ export class DocumentsService {
|
||||
return archive;
|
||||
};
|
||||
|
||||
notifyWebsocket = async (id: string, context: DriveExecutionContext) => {
|
||||
websocketEventBus.publish(RealtimeEntityActionType.Event, {
|
||||
type: "documents:updated",
|
||||
room: ResourcePath.get(`/companies/${context.company.id}/documents/item/${id}`),
|
||||
entity: {
|
||||
companyId: context.company.id,
|
||||
id: id,
|
||||
},
|
||||
resourcePath: null,
|
||||
result: null,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Search for Drive items.
|
||||
*
|
||||
|
||||
@@ -5,11 +5,7 @@ import { CrudException, ListResult } from "../../../../core/platform/framework/a
|
||||
import { File } from "../../../../services/files/entities/file";
|
||||
import { UploadOptions } from "../../../../services/files/types";
|
||||
import globalResolver from "../../../../services/global-resolver";
|
||||
import {
|
||||
CompanyUserRole,
|
||||
PaginationQueryParameters,
|
||||
ResourceWebsocket,
|
||||
} from "../../../../utils/types";
|
||||
import { CompanyUserRole, PaginationQueryParameters } from "../../../../utils/types";
|
||||
import { DriveFile } from "../../entities/drive-file";
|
||||
import { FileVersion } from "../../entities/file-version";
|
||||
import {
|
||||
@@ -160,18 +156,12 @@ export class DocumentsController {
|
||||
Params: ItemRequestParams;
|
||||
Querystring: PaginationQueryParameters & { public_token?: string };
|
||||
}>,
|
||||
): Promise<DriveItemDetails & { websockets: ResourceWebsocket[] }> => {
|
||||
): Promise<DriveItemDetails> => {
|
||||
const context = getDriveExecutionContext(request);
|
||||
const { id } = request.params;
|
||||
|
||||
return {
|
||||
...(await globalResolver.services.documents.documents.get(id, context)),
|
||||
websockets: request.currentUser?.id
|
||||
? globalResolver.platformServices.realtime.sign(
|
||||
[{ room: `/companies/${context.company.id}/documents/item/${id}` }],
|
||||
request.currentUser?.id,
|
||||
)
|
||||
: [],
|
||||
};
|
||||
};
|
||||
|
||||
@@ -188,7 +178,7 @@ export class DocumentsController {
|
||||
Body: SearchDocumentsBody;
|
||||
Querystring: PaginationQueryParameters & { public_token?: string };
|
||||
}>,
|
||||
): Promise<DriveItemDetails & { websockets: ResourceWebsocket[] }> => {
|
||||
): Promise<DriveItemDetails> => {
|
||||
const context = getDriveExecutionContext(request);
|
||||
const { id } = request.params;
|
||||
|
||||
@@ -202,7 +192,6 @@ export class DocumentsController {
|
||||
|
||||
return {
|
||||
...(await globalResolver.services.documents.documents.browse(id, options, context)),
|
||||
websockets: [],
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -9,12 +9,10 @@ import { DatabaseServiceAPI } from "../core/platform/services/database/api";
|
||||
import EmailPusherAPI from "../core/platform/services/email-pusher/provider";
|
||||
import { MessageQueueServiceAPI } from "../core/platform/services/message-queue/api";
|
||||
import { PushServiceAPI } from "../core/platform/services/push/api";
|
||||
import { RealtimeServiceAPI } from "../core/platform/services/realtime/api";
|
||||
import { SearchServiceAPI } from "../core/platform/services/search/api";
|
||||
import StorageAPI from "../core/platform/services/storage/provider";
|
||||
import TrackerAPI from "../core/platform/services/tracker/provider";
|
||||
import WebServerAPI from "../core/platform/services/webserver/provider";
|
||||
import WebSocketAPI from "../core/platform/services/websocket/provider";
|
||||
|
||||
import assert from "assert";
|
||||
import { logger } from "../core/platform/framework";
|
||||
@@ -42,12 +40,10 @@ type PlatformServices = {
|
||||
cron: CronAPI;
|
||||
messageQueue: MessageQueueServiceAPI;
|
||||
push: PushServiceAPI;
|
||||
realtime: RealtimeServiceAPI;
|
||||
search: SearchServiceAPI;
|
||||
storage: StorageAPI;
|
||||
tracker: TrackerAPI;
|
||||
webserver: WebServerAPI;
|
||||
websocket: WebSocketAPI;
|
||||
emailPusher: EmailPusherAPI;
|
||||
};
|
||||
|
||||
@@ -96,12 +92,10 @@ class GlobalResolver {
|
||||
cron: platform.getProvider<CronAPI>("cron"),
|
||||
messageQueue: platform.getProvider<MessageQueueServiceAPI>("message-queue"),
|
||||
push: platform.getProvider<PushServiceAPI>("push"),
|
||||
realtime: platform.getProvider<RealtimeServiceAPI>("realtime"),
|
||||
search: platform.getProvider<SearchServiceAPI>("search"),
|
||||
storage: platform.getProvider<StorageAPI>("storage"),
|
||||
tracker: platform.getProvider<TrackerAPI>("tracker"),
|
||||
webserver: platform.getProvider<WebServerAPI>("webserver"),
|
||||
websocket: platform.getProvider<WebSocketAPI>("websocket"),
|
||||
emailPusher: platform.getProvider<EmailPusherAPI>("email-pusher"),
|
||||
};
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import { WebsocketMetadata } from "../../utils/types";
|
||||
import CompanyEntity from "./entities/company";
|
||||
import UserEntity from "./entities/user";
|
||||
|
||||
/**
|
||||
* User Rooms
|
||||
*/
|
||||
export function getUserRooms(user: UserEntity): WebsocketMetadata[] {
|
||||
return [
|
||||
{
|
||||
room: getUserRoom(user.id),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export function getUserRoom(userId: string): string {
|
||||
return `/me/${userId}`;
|
||||
}
|
||||
|
||||
export function getPublicUserRoom(userId: string): string {
|
||||
return `/users/${userId}`;
|
||||
}
|
||||
|
||||
export function getUserName(userId: string): string {
|
||||
return `user-room-${userId}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Company Rooms
|
||||
*/
|
||||
export function getCompanyRooms(company: CompanyEntity): WebsocketMetadata[] {
|
||||
return [
|
||||
{
|
||||
room: getCompanyRoom(company.id),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export function getCompanyRoom(companyId: string): string {
|
||||
return `/company/${companyId}`;
|
||||
}
|
||||
|
||||
export function getCompanyName(companyId: string): string {
|
||||
return `company-room-${companyId}`;
|
||||
}
|
||||
@@ -30,8 +30,7 @@ import ExternalGroup, {
|
||||
ExternalGroupPrimaryKey,
|
||||
getInstance as getExternalGroupInstance,
|
||||
} from "../entities/external_company";
|
||||
import { logger, RealtimeSaved } from "../../../core/platform/framework";
|
||||
import { getCompanyRoom, getUserRoom } from "../realtime";
|
||||
import { logger } from "../../../core/platform/framework";
|
||||
import gr from "../../global-resolver";
|
||||
import { localEventBus } from "../../../core/platform/framework/event-bus";
|
||||
|
||||
@@ -59,15 +58,6 @@ export class CompanyServiceImpl {
|
||||
return this.externalCompanyRepository.findOne(pk, {}, context);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
@RealtimeSaved<Company>((company, _context) => {
|
||||
return [
|
||||
{
|
||||
room: getCompanyRoom(company.id),
|
||||
resource: company,
|
||||
},
|
||||
];
|
||||
})
|
||||
async updateCompany<SaveOptions>(
|
||||
company: Company,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
@@ -186,14 +176,6 @@ export class CompanyServiceImpl {
|
||||
);
|
||||
}
|
||||
|
||||
@RealtimeSaved<CompanyUser>((companyUser, _) => {
|
||||
return [
|
||||
{
|
||||
room: getUserRoom(companyUser?.user_id),
|
||||
resource: companyUser,
|
||||
},
|
||||
];
|
||||
})
|
||||
async removeUserFromCompany(
|
||||
companyPk: CompanyPrimaryKey,
|
||||
userPk: UserPrimaryKey,
|
||||
@@ -249,14 +231,6 @@ export class CompanyServiceImpl {
|
||||
return new DeleteResult<Company>("company", instance, !!instance);
|
||||
}
|
||||
|
||||
@RealtimeSaved<CompanyUser>((companyUser, _) => {
|
||||
return [
|
||||
{
|
||||
room: getUserRoom(companyUser?.user_id),
|
||||
resource: companyUser,
|
||||
},
|
||||
];
|
||||
})
|
||||
async setUserRole(
|
||||
companyId: uuid,
|
||||
userId: uuid,
|
||||
|
||||
@@ -28,11 +28,8 @@ import assert from "assert";
|
||||
import { localEventBus } from "../../../../core/platform/framework/event-bus";
|
||||
import { ResourceEventsPayload } from "../../../../utils/types";
|
||||
import { isNumber, isString } from "lodash";
|
||||
import { RealtimeSaved } from "../../../../core/platform/framework";
|
||||
import { getPublicUserRoom, getUserRoom } from "../../realtime";
|
||||
import NodeCache from "node-cache";
|
||||
import gr from "../../../global-resolver";
|
||||
import { formatUser } from "../../../../utils/users";
|
||||
import { TYPE as DriveFileType, DriveFile } from "../../../documents/entities/drive-file";
|
||||
|
||||
export class UserServiceImpl {
|
||||
@@ -99,34 +96,11 @@ export class UserServiceImpl {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
@RealtimeSaved<User>((user, _context) => {
|
||||
return [
|
||||
{
|
||||
room: getPublicUserRoom(user.id),
|
||||
resource: user,
|
||||
},
|
||||
];
|
||||
})
|
||||
async publishPublicUserRealtime(userId: string): Promise<void> {
|
||||
const user = await this.get({ id: userId });
|
||||
new SaveResult("user", formatUser(user, { includeCompanies: true }), OperationType.UPDATE);
|
||||
}
|
||||
|
||||
@RealtimeSaved<User>((user, _context) => {
|
||||
return [
|
||||
{
|
||||
room: getUserRoom(user.id),
|
||||
resource: formatUser(user), // FIX ME we should formatUser here
|
||||
},
|
||||
];
|
||||
})
|
||||
async save(user: User, context?: ExecutionContext): Promise<SaveResult<User>> {
|
||||
this.assignDefaults(user);
|
||||
await this.repository.save(user, context);
|
||||
await this.updateExtRepository(user);
|
||||
|
||||
await this.publishPublicUserRealtime(user.id);
|
||||
|
||||
return new SaveResult("user", user, OperationType.UPDATE);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,19 +20,18 @@ import {
|
||||
CompanyParameters,
|
||||
CompanyStatsObject,
|
||||
CompanyUserObject,
|
||||
CompanyUsersParameters,
|
||||
DeregisterDeviceParams,
|
||||
RegisterDeviceBody,
|
||||
RegisterDeviceParams,
|
||||
UserListQueryParameters,
|
||||
UserObject,
|
||||
UserParameters,
|
||||
CompanyUsersParameters,
|
||||
UserQuota,
|
||||
} from "./types";
|
||||
import Company from "../entities/company";
|
||||
import CompanyUser from "../entities/company_user";
|
||||
import coalesce from "../../../utils/coalesce";
|
||||
import { getCompanyRooms, getUserRooms } from "../realtime";
|
||||
import { formatCompany, getCompanyStats } from "../utils";
|
||||
import { formatUser } from "../../../utils/users";
|
||||
import gr from "../../global-resolver";
|
||||
@@ -70,9 +69,6 @@ export class UsersCrudController
|
||||
|
||||
return {
|
||||
resource: userObject,
|
||||
websocket: context.user.id
|
||||
? gr.platformServices.realtime.sign(getUserRooms(user), context.user.id)[0]
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -100,11 +96,7 @@ export class UsersCrudController
|
||||
async setPreferences(
|
||||
request: FastifyRequest<{ Body: User["preferences"] }>,
|
||||
): Promise<User["preferences"]> {
|
||||
const preferences = await gr.services.users.setPreferences(
|
||||
{ id: request.currentUser.id },
|
||||
request.body,
|
||||
);
|
||||
return preferences;
|
||||
return await gr.services.users.setPreferences({ id: request.currentUser.id }, request.body);
|
||||
}
|
||||
|
||||
async list(
|
||||
@@ -143,7 +135,6 @@ export class UsersCrudController
|
||||
// return users;
|
||||
return {
|
||||
resources: resUsers,
|
||||
websockets: gr.platformServices.realtime.sign([], context.user.id),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -220,7 +211,6 @@ export class UsersCrudController
|
||||
|
||||
return {
|
||||
resources: combos.map(combo => formatCompany(...combo)),
|
||||
websockets: gr.platformServices.realtime.sign([], context.user.id),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -253,9 +243,6 @@ export class UsersCrudController
|
||||
companyUserObj,
|
||||
getCompanyStats(company, await gr.services.statistics.get(company.id, "messages")),
|
||||
),
|
||||
websocket: context.user?.id
|
||||
? gr.platformServices.realtime.sign(getCompanyRooms(company), context.user.id)[0]
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { webSocketSchema } from "../../../utils/types";
|
||||
import { CompanyFeaturesEnum, CompanyLimitsEnum } from "./types";
|
||||
|
||||
export const userObjectSchema = {
|
||||
@@ -126,7 +125,6 @@ export const getUserSchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
resource: userObjectSchema,
|
||||
websocket: webSocketSchema,
|
||||
},
|
||||
required: ["resource"],
|
||||
},
|
||||
@@ -231,7 +229,6 @@ export const getCompanySchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
resource: companyObjectSchema,
|
||||
websocket: webSocketSchema,
|
||||
},
|
||||
required: ["resource"],
|
||||
},
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import { WebsocketMetadata } from "../../utils/types";
|
||||
import Workspace from "./entities/workspace";
|
||||
import { WorkspaceExecutionContext } from "./types";
|
||||
|
||||
export function getWebsocketInformation(workspace: Workspace): WebsocketMetadata {
|
||||
return {
|
||||
name: workspace.name,
|
||||
room: getWorkspacePath(workspace),
|
||||
};
|
||||
}
|
||||
|
||||
export function getWorkspaceRooms(context: WorkspaceExecutionContext): WebsocketMetadata[] {
|
||||
return [
|
||||
{
|
||||
name: "workspaces",
|
||||
room: getRoomName(context),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export function getRoomName(context: Pick<Workspace, "company_id">): string {
|
||||
return `/companies/${context.company_id}/workspaces`;
|
||||
}
|
||||
|
||||
export function getWorkspacePath(
|
||||
workspace: Pick<Workspace, "id">,
|
||||
context?: WorkspaceExecutionContext,
|
||||
): string {
|
||||
return `/companies/${context?.company_id}/workspaces/${workspace.id}`;
|
||||
}
|
||||
@@ -41,13 +41,7 @@ import {
|
||||
WorkspaceCounterPrimaryKey,
|
||||
} from "../entities/workspace_counters";
|
||||
import { countRepositoryItems } from "../../../utils/counters";
|
||||
import {
|
||||
Initializable,
|
||||
RealtimeSaved,
|
||||
TdriveServiceProvider,
|
||||
} from "../../../core/platform/framework";
|
||||
import { ResourcePath } from "../../../core/platform/services/realtime/types";
|
||||
import { getRoomName, getWorkspacePath } from "../realtime";
|
||||
import { Initializable, TdriveServiceProvider } from "../../../core/platform/framework";
|
||||
import { InviteTokenObject, WorkspaceInviteTokenObject } from "../web/types";
|
||||
import WorkspaceInviteTokens, {
|
||||
getInstance as getWorkspaceInviteTokensInstance,
|
||||
@@ -149,15 +143,6 @@ export class WorkspaceServiceImpl implements TdriveServiceProvider, Initializabl
|
||||
return new CreateResult<Workspace>(TYPE, created.entity);
|
||||
}
|
||||
|
||||
// TODO: remove logic from context
|
||||
@RealtimeSaved<Workspace>((workspace, context) => [
|
||||
{
|
||||
// FIXME: For now the room is defined at the company level
|
||||
// It meay be good to have a special room where just some users are receiving this event
|
||||
room: ResourcePath.get(getRoomName(workspace)),
|
||||
path: getWorkspacePath(workspace, context as WorkspaceExecutionContext),
|
||||
},
|
||||
])
|
||||
async save<SaveOptions>(
|
||||
item: Partial<Workspace>,
|
||||
options?: SaveOptions & { logo_b64?: string },
|
||||
|
||||
@@ -19,7 +19,6 @@ import { WorkspaceExecutionContext } from "../../types";
|
||||
import { plainToClass } from "class-transformer";
|
||||
import { hasCompanyAdminLevel, hasCompanyMemberLevel } from "../../../../utils/company";
|
||||
import { hasWorkspaceAdminLevel } from "../../../../utils/workspace";
|
||||
import { getWorkspaceRooms } from "../../realtime";
|
||||
import {
|
||||
CrudException,
|
||||
ExecutionContext,
|
||||
@@ -166,7 +165,6 @@ export class WorkspacesCrudController
|
||||
this.formatWorkspace(ws, await this.getWorkspaceUsersCount(ws.id), context.user.id),
|
||||
),
|
||||
),
|
||||
websockets: gr.platformServices.realtime.sign(getWorkspaceRooms(context), context.user.id),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { webSocketSchema } from "../../../utils/types";
|
||||
import { companyObjectSchema, userObjectSchema } from "../../user/web/schemas";
|
||||
|
||||
const workspaceObjectSchema = {
|
||||
@@ -35,7 +34,6 @@ export const getWorkspacesSchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
resources: { type: "array", items: workspaceObjectSchema },
|
||||
websockets: { type: "array", items: webSocketSchema },
|
||||
},
|
||||
required: ["resources"],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user