From 65b87ac0d627d5e1deb19a8fc2404b3c78b5e1e3 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 29 Dec 2022 10:54:07 -0300 Subject: [PATCH 01/13] Remove getAppUsername --- src/definition/App.ts | 12 ------------ src/definition/IApp.ts | 10 ---------- 2 files changed, 22 deletions(-) diff --git a/src/definition/App.ts b/src/definition/App.ts index 464814ee4..97d53048e 100644 --- a/src/definition/App.ts +++ b/src/definition/App.ts @@ -57,18 +57,6 @@ export abstract class App implements IApp { return this.info.nameSlug; } - /** - * Gets the username of this App's app user. - * - * @return {string} the username of the app user - * - * @deprecated This method will be removed in the next major version. - * Please use read.getUserReader().getAppUser() instead. - */ - public getAppUserUsername(): string { - return `${ this.info.nameSlug }.bot`; - } - /** * Get the ID of this App, please see for how to obtain an ID for your App. * diff --git a/src/definition/IApp.ts b/src/definition/IApp.ts index b355c3b11..1837d641e 100644 --- a/src/definition/IApp.ts +++ b/src/definition/IApp.ts @@ -26,16 +26,6 @@ export interface IApp { */ getNameSlug(): string; - /** - * Gets the username of this App's app user. - * - * @return {string} the username of the app user - * - * @deprecated This method will be removed in the next major version. - * Please use read.getAppUser instead. - */ - getAppUserUsername(): string; - /** * Get the ID of this App, please see for how to obtain an ID for your App. * From 4973fa5d28e74f881e188e130eb646de821422c0 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 29 Dec 2022 10:56:17 -0300 Subject: [PATCH 02/13] Remove getLivechatVisitors --- src/definition/accessors/ILivechatRead.ts | 6 ------ src/server/accessors/LivechatRead.ts | 9 --------- 2 files changed, 15 deletions(-) diff --git a/src/definition/accessors/ILivechatRead.ts b/src/definition/accessors/ILivechatRead.ts index 11dee0c23..6e249e416 100644 --- a/src/definition/accessors/ILivechatRead.ts +++ b/src/definition/accessors/ILivechatRead.ts @@ -17,12 +17,6 @@ export interface ILivechatRead { isOnlineAsync(departmentId?: string): Promise; getDepartmentsEnabledWithAgents(): Promise>; getLivechatRooms(visitor: IVisitor, departmentId?: string): Promise>; - /** - * @deprecated This method does not adhere to the conversion practices applied - * elsewhere in the Apps-Engine and will be removed in the next major version. - * Prefer the alternative methods to fetch visitors. - */ - getLivechatVisitors(query: object): Promise>; getLivechatVisitorById(id: string): Promise; getLivechatVisitorByEmail(email: string): Promise; getLivechatVisitorByToken(token: string): Promise; diff --git a/src/server/accessors/LivechatRead.ts b/src/server/accessors/LivechatRead.ts index 7a73cffda..a018e1243 100644 --- a/src/server/accessors/LivechatRead.ts +++ b/src/server/accessors/LivechatRead.ts @@ -29,15 +29,6 @@ export class LivechatRead implements ILivechatRead { return this.livechatBridge.doFindRooms(visitor, departmentId, this.appId); } - /** - * @deprecated This method does not adhere to the conversion practices applied - * elsewhere in the Apps-Engine and will be removed in the next major version. - * Prefer the alternative methods to fetch visitors. - */ - public getLivechatVisitors(query: object): Promise> { - return this.livechatBridge.doFindVisitors(query, this.appId); - } - public getLivechatVisitorById(id: string): Promise { return this.livechatBridge.doFindVisitorById(id, this.appId); } From fc0285ab9294e63ef99e70b1ed6aa428c2c9b3bf Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 29 Dec 2022 10:59:16 -0300 Subject: [PATCH 03/13] Remove addUsername --- src/definition/accessors/IRoomBuilder.ts | 8 -------- src/server/accessors/RoomBuilder.ts | 8 -------- tests/server/accessors/RoomBuilder.spec.ts | 9 --------- 3 files changed, 25 deletions(-) diff --git a/src/definition/accessors/IRoomBuilder.ts b/src/definition/accessors/IRoomBuilder.ts index 4c375f460..d343f6fad 100644 --- a/src/definition/accessors/IRoomBuilder.ts +++ b/src/definition/accessors/IRoomBuilder.ts @@ -67,14 +67,6 @@ export interface IRoomBuilder { */ getCreator(): IUser; - /** - * Adds a user to the room, these are by username until further notice. - * - * @param username the user's username to add to the room - * @deprecated in favor of `addMemberToBeAddedByUsername`. This method will be removed on version 2.0.0 - */ - addUsername(username: string): IRoomBuilder; - /** * Sets the usernames of who are joined to the room. * diff --git a/src/server/accessors/RoomBuilder.ts b/src/server/accessors/RoomBuilder.ts index 7c3de167d..8a2dd5ff9 100644 --- a/src/server/accessors/RoomBuilder.ts +++ b/src/server/accessors/RoomBuilder.ts @@ -57,14 +57,6 @@ export class RoomBuilder implements IRoomBuilder { return this.room.creator; } - /** - * @deprecated - */ - public addUsername(username: string): IRoomBuilder { - this.addMemberToBeAddedByUsername(username); - return this; - } - /** * @deprecated */ diff --git a/tests/server/accessors/RoomBuilder.spec.ts b/tests/server/accessors/RoomBuilder.spec.ts index a83b37ad2..cf754166c 100644 --- a/tests/server/accessors/RoomBuilder.spec.ts +++ b/tests/server/accessors/RoomBuilder.spec.ts @@ -37,15 +37,6 @@ export class RoomBuilderAccessorTestFixture { Expect(room.creator).toEqual(TestData.getUser()); Expect(rb.getCreator()).toEqual(TestData.getUser()); - Expect(rb.addUsername('testing.username')).toBe(rb); - Expect(room.usernames).not.toBeDefined(); - Expect(rb.getUsernames()).not.toBeEmpty(); - Expect(room.usernames).not.toBeDefined(); - Expect(rb.getUsernames()[0]).toEqual('testing.username'); - Expect(rb.addUsername('another.username')).toBe(rb); - Expect(room.usernames).not.toBeDefined(); - Expect(rb.getUsernames().length).toBe(2); - Expect(rb.setUsernames([])).toBe(rb); Expect(room.usernames).not.toBeDefined(); Expect(rb.getUsernames()).toBeEmpty(); From 2a755eb1e86599d69c613f81aaa71329e4e6c677 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 29 Dec 2022 11:02:30 -0300 Subject: [PATCH 04/13] Remove setUsername --- src/definition/accessors/IRoomBuilder.ts | 8 -------- src/server/accessors/RoomBuilder.ts | 8 -------- tests/server/accessors/RoomBuilder.spec.ts | 4 ---- 3 files changed, 20 deletions(-) diff --git a/src/definition/accessors/IRoomBuilder.ts b/src/definition/accessors/IRoomBuilder.ts index d343f6fad..5026ac161 100644 --- a/src/definition/accessors/IRoomBuilder.ts +++ b/src/definition/accessors/IRoomBuilder.ts @@ -67,14 +67,6 @@ export interface IRoomBuilder { */ getCreator(): IUser; - /** - * Sets the usernames of who are joined to the room. - * - * @param usernames the list of usernames - * @deprecated in favor of `setMembersByUsernames`. This method will be removed on version 2.0.0 - */ - setUsernames(usernames: Array): IRoomBuilder; - /** * Gets the usernames of users in the room. * @deprecated in favor of `getMembersUsernames`. This method will be removed on version 2.0.0 diff --git a/src/server/accessors/RoomBuilder.ts b/src/server/accessors/RoomBuilder.ts index 8a2dd5ff9..ae8c86c23 100644 --- a/src/server/accessors/RoomBuilder.ts +++ b/src/server/accessors/RoomBuilder.ts @@ -57,14 +57,6 @@ export class RoomBuilder implements IRoomBuilder { return this.room.creator; } - /** - * @deprecated - */ - public setUsernames(usernames: Array): IRoomBuilder { - this.setMembersToBeAddedByUsernames(usernames); - return this; - } - /** * @deprecated */ diff --git a/tests/server/accessors/RoomBuilder.spec.ts b/tests/server/accessors/RoomBuilder.spec.ts index cf754166c..c4a52c4c2 100644 --- a/tests/server/accessors/RoomBuilder.spec.ts +++ b/tests/server/accessors/RoomBuilder.spec.ts @@ -37,10 +37,6 @@ export class RoomBuilderAccessorTestFixture { Expect(room.creator).toEqual(TestData.getUser()); Expect(rb.getCreator()).toEqual(TestData.getUser()); - Expect(rb.setUsernames([])).toBe(rb); - Expect(room.usernames).not.toBeDefined(); - Expect(rb.getUsernames()).toBeEmpty(); - Expect(rb.addMemberToBeAddedByUsername('testing.username')).toBe(rb); Expect(rb.getMembersToBeAddedUsernames()).not.toBeEmpty(); Expect(rb.getMembersToBeAddedUsernames()[0]).toEqual('testing.username'); From e4545d414820909a51b89d83cc956f55e2ec6eac Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 29 Dec 2022 11:03:39 -0300 Subject: [PATCH 05/13] Remove getUsernames --- src/definition/accessors/IRoomBuilder.ts | 6 ------ src/server/accessors/RoomBuilder.ts | 11 ----------- 2 files changed, 17 deletions(-) diff --git a/src/definition/accessors/IRoomBuilder.ts b/src/definition/accessors/IRoomBuilder.ts index 5026ac161..88d536e38 100644 --- a/src/definition/accessors/IRoomBuilder.ts +++ b/src/definition/accessors/IRoomBuilder.ts @@ -67,12 +67,6 @@ export interface IRoomBuilder { */ getCreator(): IUser; - /** - * Gets the usernames of users in the room. - * @deprecated in favor of `getMembersUsernames`. This method will be removed on version 2.0.0 - */ - getUsernames(): Array; - /** * Adds a member to the room by username * diff --git a/src/server/accessors/RoomBuilder.ts b/src/server/accessors/RoomBuilder.ts index ae8c86c23..cefb18c67 100644 --- a/src/server/accessors/RoomBuilder.ts +++ b/src/server/accessors/RoomBuilder.ts @@ -57,17 +57,6 @@ export class RoomBuilder implements IRoomBuilder { return this.room.creator; } - /** - * @deprecated - */ - public getUsernames(): Array { - const usernames = this.getMembersToBeAddedUsernames(); - if (usernames && usernames.length > 0) { - return usernames; - } - return this.room.usernames || []; - } - public addMemberToBeAddedByUsername(username: string): IRoomBuilder { this.members.push(username); return this; From 5f99eea652414fb142e28ef62aa7f6e1e9cddb92 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 29 Dec 2022 11:08:19 -0300 Subject: [PATCH 06/13] Remove ILivechatRoomClosed --- .../livechat/ILivechatRoomClosedHandler.ts | 19 -------------- src/definition/livechat/index.ts | 2 -- src/definition/metadata/AppInterface.ts | 4 --- src/server/managers/AppListenerManager.ts | 25 ------------------- 4 files changed, 50 deletions(-) delete mode 100644 src/definition/livechat/ILivechatRoomClosedHandler.ts diff --git a/src/definition/livechat/ILivechatRoomClosedHandler.ts b/src/definition/livechat/ILivechatRoomClosedHandler.ts deleted file mode 100644 index 5c2e80314..000000000 --- a/src/definition/livechat/ILivechatRoomClosedHandler.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { IHttp, IPersistence, IRead } from '../accessors'; -import { AppMethod } from '../metadata'; -import { ILivechatRoom } from './ILivechatRoom'; - -/** - * Handler called after a livechat room is closed. - * @deprecated please prefer the IPostLivechatRoomClosed event - */ -export interface ILivechatRoomClosedHandler { - /** - * Method called *after* a livechat room is closed. - * - * @param livechatRoom The livechat room which is closed. - * @param read An accessor to the environment - * @param http An accessor to the outside world - * @param persistence An accessor to the App's persistence - */ - [AppMethod.EXECUTE_LIVECHAT_ROOM_CLOSED_HANDLER](data: ILivechatRoom, read: IRead, http: IHttp, persistence: IPersistence): Promise; -} diff --git a/src/definition/livechat/index.ts b/src/definition/livechat/index.ts index 5ea8d9f42..b40aa7769 100644 --- a/src/definition/livechat/index.ts +++ b/src/definition/livechat/index.ts @@ -2,7 +2,6 @@ import { IDepartment } from './IDepartment'; import { ILivechatEventContext } from './ILivechatEventContext'; import { ILivechatMessage } from './ILivechatMessage'; import { ILivechatRoom } from './ILivechatRoom'; -import { ILivechatRoomClosedHandler } from './ILivechatRoomClosedHandler'; import { ILivechatTransferData } from './ILivechatTransferData'; import { ILivechatTransferEventContext, LivechatTransferEventType } from './ILivechatTransferEventContext'; import { IPostLivechatAgentAssigned } from './IPostLivechatAgentAssigned'; @@ -27,7 +26,6 @@ export { IPostLivechatRoomClosed, IPostLivechatRoomSaved, IPostLivechatRoomTransferred, - ILivechatRoomClosedHandler, ILivechatTransferData, ILivechatTransferEventContext, IDepartment, diff --git a/src/definition/metadata/AppInterface.ts b/src/definition/metadata/AppInterface.ts index b84a0e18b..77adec92c 100644 --- a/src/definition/metadata/AppInterface.ts +++ b/src/definition/metadata/AppInterface.ts @@ -35,10 +35,6 @@ export enum AppInterface { // Livechat IPostLivechatRoomStarted = 'IPostLivechatRoomStarted', IPostLivechatRoomClosed = 'IPostLivechatRoomClosed', - /** - * @deprecated please use the AppMethod.EXECUTE_POST_LIVECHAT_ROOM_CLOSED method - */ - ILivechatRoomClosedHandler = 'ILivechatRoomClosedHandler', IPostLivechatAgentAssigned = 'IPostLivechatAgentAssigned', IPostLivechatAgentUnassigned = 'IPostLivechatAgentUnassigned', IPostLivechatRoomTransferred = 'IPostLivechatRoomTransferred', diff --git a/src/server/managers/AppListenerManager.ts b/src/server/managers/AppListenerManager.ts index 4054e248b..543373f78 100644 --- a/src/server/managers/AppListenerManager.ts +++ b/src/server/managers/AppListenerManager.ts @@ -238,11 +238,6 @@ export class AppListenerManager { // Livechat case AppInterface.IPostLivechatRoomStarted: return this.executePostLivechatRoomStarted(data as ILivechatRoom); - /** - * @deprecated please prefer the AppInterface.IPostLivechatRoomClosed event - */ - case AppInterface.ILivechatRoomClosedHandler: - return this.executeLivechatRoomClosedHandler(data as ILivechatRoom); case AppInterface.IPostLivechatRoomClosed: return this.executePostLivechatRoomClosed(data as ILivechatRoom); case AppInterface.IPostLivechatRoomSaved: @@ -1060,26 +1055,6 @@ export class AppListenerManager { } } - private async executeLivechatRoomClosedHandler(data: ILivechatRoom): Promise { - const cfLivechatRoom = Utilities.deepCloneAndFreeze(data); - - for (const appId of this.listeners.get(AppInterface.ILivechatRoomClosedHandler)) { - const app = this.manager.getOneById(appId); - - if (!app.hasMethod(AppMethod.EXECUTE_LIVECHAT_ROOM_CLOSED_HANDLER)) { - continue; - } - - await app.call(AppMethod.EXECUTE_LIVECHAT_ROOM_CLOSED_HANDLER, - cfLivechatRoom, - this.am.getReader(appId), - this.am.getHttp(appId), - this.am.getPersistence(appId), - this.am.getModifier(appId), - ); - } - } - private async executePostLivechatRoomClosed(data: ILivechatRoom): Promise { const cfLivechatRoom = Utilities.deepCloneAndFreeze(data); From 838d3da3099d32258ede158761e3bcf8674aa352 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 29 Dec 2022 14:17:24 -0300 Subject: [PATCH 07/13] Change isOnline method --- src/definition/accessors/ILivechatRead.ts | 8 +------- src/server/accessors/LivechatRead.ts | 12 +----------- src/server/bridges/LivechatBridge.ts | 21 ++------------------- tests/test-data/bridges/livechatBridge.ts | 2 +- 4 files changed, 5 insertions(+), 38 deletions(-) diff --git a/src/definition/accessors/ILivechatRead.ts b/src/definition/accessors/ILivechatRead.ts index 6e249e416..3cb233ab7 100644 --- a/src/definition/accessors/ILivechatRead.ts +++ b/src/definition/accessors/ILivechatRead.ts @@ -7,14 +7,8 @@ export interface ILivechatRead { /** * Gets online status of the livechat. * @param departmentId (optional) the id of the livechat department - * @deprecated use `isOnlineAsync` instead */ - isOnline(departmentId?: string): boolean; - /** - * Gets online status of the livechat. - * @param departmentId (optional) the id of the livechat department - */ - isOnlineAsync(departmentId?: string): Promise; + isOnline(departmentId?: string): Promise; getDepartmentsEnabledWithAgents(): Promise>; getLivechatRooms(visitor: IVisitor, departmentId?: string): Promise>; getLivechatVisitorById(id: string): Promise; diff --git a/src/server/accessors/LivechatRead.ts b/src/server/accessors/LivechatRead.ts index a018e1243..af9ac7386 100644 --- a/src/server/accessors/LivechatRead.ts +++ b/src/server/accessors/LivechatRead.ts @@ -7,20 +7,10 @@ import { LivechatBridge } from '../bridges/LivechatBridge'; export class LivechatRead implements ILivechatRead { constructor(private readonly livechatBridge: LivechatBridge, private readonly appId: string) { } - /** - * @deprecated please use the `isOnlineAsync` method instead. - * In the next major, this method will be `async` - */ - public isOnline(departmentId?: string): boolean { - console.warn('The `LivechatRead.isOnline` method is deprecated and won\'t behave as intended. Please use `LivechatRead.isOnlineAsync` instead'); - + public isOnline(departmentId?: string): Promise { return this.livechatBridge.doIsOnline(departmentId, this.appId); } - public isOnlineAsync(departmentId?: string): Promise { - return this.livechatBridge.doIsOnlineAsync(departmentId, this.appId); - } - public getDepartmentsEnabledWithAgents(): Promise> { return this.livechatBridge.doFindDepartmentsEnabledWithAgents(this.appId); } diff --git a/src/server/bridges/LivechatBridge.ts b/src/server/bridges/LivechatBridge.ts index edd04f96f..5de440d87 100644 --- a/src/server/bridges/LivechatBridge.ts +++ b/src/server/bridges/LivechatBridge.ts @@ -39,18 +39,12 @@ type LivechatMultiplePermissions = keyof Pick< >; export abstract class LivechatBridge extends BaseBridge { - public doIsOnline(departmentId?: string, appId?: string): boolean { + public async doIsOnline(departmentId?: string, appId?: string): Promise { if (this.hasReadPermission(appId, 'livechat-status')) { return this.isOnline(departmentId, appId); } } - public async doIsOnlineAsync(departmentId?: string, appId?: string): Promise { - if (this.hasReadPermission(appId, 'livechat-status')) { - return this.isOnlineAsync(departmentId, appId); - } - } - public async doCreateMessage(message: ILivechatMessage, appId: string): Promise { if (this.hasWritePermission(appId, 'livechat-message')) { return this.createMessage(message, appId); @@ -75,12 +69,6 @@ export abstract class LivechatBridge extends BaseBridge { } } - public async doFindVisitors(query: object, appId: string): Promise> { - if (this.hasReadPermission(appId, 'livechat-visitor')) { - return this.findVisitors(query, appId); - } - } - public async doFindVisitorById(id: string, appId: string): Promise { if (this.hasReadPermission(appId, 'livechat-visitor')) { return this.findVisitorById(id, appId); @@ -153,12 +141,7 @@ export abstract class LivechatBridge extends BaseBridge { } } - /** - * @deprecated please use the `isOnlineAsync` method instead. - * In the next major, this method will be `async` - */ - protected abstract isOnline(departmentId?: string, appId?: string): boolean; - protected abstract isOnlineAsync(departmentId?: string, appId?: string): Promise; + protected abstract isOnline(departmentId?: string, appId?: string): Promise; protected abstract createMessage(message: ILivechatMessage, appId: string): Promise; protected abstract getMessageById(messageId: string, appId: string): Promise; protected abstract updateMessage(message: ILivechatMessage, appId: string): Promise; diff --git a/tests/test-data/bridges/livechatBridge.ts b/tests/test-data/bridges/livechatBridge.ts index 67faa32e8..a4f284484 100644 --- a/tests/test-data/bridges/livechatBridge.ts +++ b/tests/test-data/bridges/livechatBridge.ts @@ -11,7 +11,7 @@ export class TestLivechatBridge extends LivechatBridge { public isOnline(departmentId?: string): boolean { throw new Error('Method not implemented'); } - public isOnlineAsync(departmentId?: string): Promise { + public isOnline(departmentId?: string): Promise { throw new Error('Method not implemented'); } public createMessage(message: ILivechatMessage, appId: string): Promise { From e002a7b1c446032e6037b5c36e237ec600a1acdf Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 29 Dec 2022 14:20:29 -0300 Subject: [PATCH 08/13] Fix tests --- src/server/ProxiedApp.ts | 4 ---- src/server/bridges/LivechatBridge.ts | 6 ------ tests/test-data/bridges/livechatBridge.ts | 7 ------- 3 files changed, 17 deletions(-) diff --git a/src/server/ProxiedApp.ts b/src/server/ProxiedApp.ts index 2e60fd316..4c4d087ea 100644 --- a/src/server/ProxiedApp.ts +++ b/src/server/ProxiedApp.ts @@ -117,10 +117,6 @@ export class ProxiedApp implements IApp { return this.app.getNameSlug(); } - public getAppUserUsername(): string { - return this.app.getAppUserUsername(); - } - public getID(): string { return this.app.getID(); } diff --git a/src/server/bridges/LivechatBridge.ts b/src/server/bridges/LivechatBridge.ts index 5de440d87..01702cc0d 100644 --- a/src/server/bridges/LivechatBridge.ts +++ b/src/server/bridges/LivechatBridge.ts @@ -146,12 +146,6 @@ export abstract class LivechatBridge extends BaseBridge { protected abstract getMessageById(messageId: string, appId: string): Promise; protected abstract updateMessage(message: ILivechatMessage, appId: string): Promise; protected abstract createVisitor(visitor: IVisitor, appId: string): Promise; - /** - * @deprecated This method does not adhere to the conversion practices applied - * elsewhere in the Apps-Engine and will be removed in the next major version. - * Prefer other methods that fetch visitors. - */ - protected abstract findVisitors(query: object, appId: string): Promise>; protected abstract findVisitorById(id: string, appId: string): Promise; protected abstract findVisitorByEmail(email: string, appId: string): Promise; protected abstract findVisitorByToken(token: string, appId: string): Promise; diff --git a/tests/test-data/bridges/livechatBridge.ts b/tests/test-data/bridges/livechatBridge.ts index a4f284484..08e88dec8 100644 --- a/tests/test-data/bridges/livechatBridge.ts +++ b/tests/test-data/bridges/livechatBridge.ts @@ -8,9 +8,6 @@ export class TestLivechatBridge extends LivechatBridge { public findDepartmentsEnabledWithAgents(appId: string): Promise> { throw new Error('Method not implemented.'); } - public isOnline(departmentId?: string): boolean { - throw new Error('Method not implemented'); - } public isOnline(departmentId?: string): Promise { throw new Error('Method not implemented'); } @@ -29,10 +26,6 @@ export class TestLivechatBridge extends LivechatBridge { public transferVisitor(visitor: IVisitor, transferData: ILivechatTransferData, appId: string): Promise { throw new Error('Method not implemented'); } - public findVisitors(query: object, appId: string): Promise> { - console.warn('The method AppLivechatBridge.findVisitors is deprecated. Please consider using its alternatives'); - throw new Error('Method not implemented'); - } public findVisitorById(id: string, appId: string): Promise { throw new Error('Method not implemented'); } From 7578680798edd75848b0d1d0826f979a4a8e8f42 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 29 Dec 2022 14:30:28 -0300 Subject: [PATCH 09/13] Change getAppUser --- src/definition/accessors/IUserRead.ts | 2 +- src/server/AppManager.ts | 5 ++--- src/server/accessors/UserRead.ts | 4 ++-- src/server/bridges/IInternalUserBridge.ts | 2 +- src/server/bridges/UserBridge.ts | 4 ++-- tests/server/accessors/UserRead.spec.ts | 6 ++---- tests/test-data/bridges/userBridge.ts | 2 +- 7 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/definition/accessors/IUserRead.ts b/src/definition/accessors/IUserRead.ts index 4fce21a37..d89dd516a 100644 --- a/src/definition/accessors/IUserRead.ts +++ b/src/definition/accessors/IUserRead.ts @@ -12,7 +12,7 @@ export interface IUserRead { /** * Gets the app user of this app. */ - getAppUser(appId?: string): Promise; + getAppUser(): Promise; /** * Gets the user's badge count (unread messages count). diff --git a/src/server/AppManager.ts b/src/server/AppManager.ts index 7dac3a270..9fa45c19e 100644 --- a/src/server/AppManager.ts +++ b/src/server/AppManager.ts @@ -482,7 +482,6 @@ export class AppManager { undoSteps.push(() => this.removeAppUser(app)); } catch (err) { aff.setAppUserError({ - username: app.getAppUserUsername(), message: 'Failed to create an app user for this app.', }); @@ -973,7 +972,7 @@ export class AppManager { } private async createAppUser(appInfo: IAppInfo): Promise { - const appUser = await (this.bridges.getUserBridge() as IInternalUserBridge & UserBridge).getAppUser(appInfo.id); + const appUser = await (this.bridges.getUserBridge() as IInternalUserBridge & UserBridge).getAppUser(); if (appUser) { return appUser.id; @@ -997,7 +996,7 @@ export class AppManager { } private async removeAppUser(app: ProxiedApp): Promise { - const appUser = await (this.bridges.getUserBridge() as IInternalUserBridge & UserBridge).getAppUser(app.getID()); + const appUser = await (this.bridges.getUserBridge() as IInternalUserBridge & UserBridge).getAppUser(); if (!appUser) { return true; diff --git a/src/server/accessors/UserRead.ts b/src/server/accessors/UserRead.ts index 5f9eb1999..f2eccbd08 100644 --- a/src/server/accessors/UserRead.ts +++ b/src/server/accessors/UserRead.ts @@ -13,8 +13,8 @@ export class UserRead implements IUserRead { return this.userBridge.doGetByUsername(username, this.appId); } - public getAppUser(appId: string = this.appId): Promise { - return this.userBridge.doGetAppUser(appId); + public getAppUser(): Promise { + return this.userBridge.doGetAppUser(this.appId); } public getUserUnreadMessageCount(uid: string): Promise { diff --git a/src/server/bridges/IInternalUserBridge.ts b/src/server/bridges/IInternalUserBridge.ts index 50597ea5c..8219a95d0 100644 --- a/src/server/bridges/IInternalUserBridge.ts +++ b/src/server/bridges/IInternalUserBridge.ts @@ -2,7 +2,7 @@ import { IUser, IUserCreationOptions } from '../../definition/users'; export interface IInternalUserBridge { create(data: Partial, appId: string, options?: IUserCreationOptions): Promise; - getAppUser(appId?: string): Promise; + getAppUser(): Promise; remove(user: IUser, appId: string): Promise; getActiveUserCount(): Promise; } diff --git a/src/server/bridges/UserBridge.ts b/src/server/bridges/UserBridge.ts index 633df3d5d..670c507e4 100644 --- a/src/server/bridges/UserBridge.ts +++ b/src/server/bridges/UserBridge.ts @@ -17,7 +17,7 @@ export abstract class UserBridge extends BaseBridge { } } - public async doGetAppUser(appId?: string): Promise { + public async doGetAppUser(appId: string): Promise { return this.getAppUser(appId); } @@ -47,7 +47,7 @@ export abstract class UserBridge extends BaseBridge { protected abstract getById(id: string, appId: string): Promise; protected abstract getByUsername(username: string, appId: string): Promise; - protected abstract getAppUser(appId?: string): Promise; + protected abstract getAppUser(appId: string): Promise; protected abstract getActiveUserCount(): Promise; protected abstract getUserUnreadMessageCount(uid: string): Promise; diff --git a/tests/server/accessors/UserRead.spec.ts b/tests/server/accessors/UserRead.spec.ts index 85f6b3f64..242ec8596 100644 --- a/tests/server/accessors/UserRead.spec.ts +++ b/tests/server/accessors/UserRead.spec.ts @@ -8,7 +8,6 @@ import { TestData } from '../../test-data/utilities'; export class UserReadAccessorTestFixture { private user: IUser; private mockUserBridge: UserBridge; - private mockAppId: 'test-appId'; @SetupFixture public setupFixture() { @@ -22,7 +21,7 @@ export class UserReadAccessorTestFixture { doGetByUsername(id, appId): Promise { return Promise.resolve(theUser); }, - doGetAppUser(appId?: string): Promise { + doGetAppUser(appId: string): Promise { return Promise.resolve(theUser); }, } as UserBridge; @@ -40,8 +39,7 @@ export class UserReadAccessorTestFixture { Expect(await ur.getByUsername('username')).toBeDefined(); Expect(await ur.getByUsername('username')).toEqual(this.user); - Expect(await ur.getAppUser(this.mockAppId)).toBeDefined(); - Expect(await ur.getAppUser(this.mockAppId)).toEqual(this.user); + Expect(await ur.getAppUser()).toBeDefined(); Expect(await ur.getAppUser()).toEqual(this.user); } } diff --git a/tests/test-data/bridges/userBridge.ts b/tests/test-data/bridges/userBridge.ts index 18993c1ca..99c9c4a8f 100644 --- a/tests/test-data/bridges/userBridge.ts +++ b/tests/test-data/bridges/userBridge.ts @@ -23,7 +23,7 @@ export class TestsUserBridge extends UserBridge { throw new Error('Method not implemented.'); } - public getAppUser(appId?: string): Promise { + public getAppUser(appId: string): Promise { throw new Error('Method not implemented.'); } From 1e77307c2d0d6b6acf186231a9240bc805e69abc Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 29 Dec 2022 14:48:29 -0300 Subject: [PATCH 10/13] Remove usernames from room --- src/definition/rooms/IRoom.ts | 4 ---- src/server/rooms/Room.ts | 20 ++------------------ 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/src/definition/rooms/IRoom.ts b/src/definition/rooms/IRoom.ts index da106db08..b0ff72954 100644 --- a/src/definition/rooms/IRoom.ts +++ b/src/definition/rooms/IRoom.ts @@ -7,10 +7,6 @@ export interface IRoom { slugifiedName: string; type: RoomType; creator: IUser; - /** - * @deprecated usernames will be removed on version 2.0.0 - */ - usernames: Array; userIds?: Array; isDefault?: boolean; isReadOnly?: boolean; diff --git a/src/server/rooms/Room.ts b/src/server/rooms/Room.ts index 34ae7c3b4..5ef3a2a5a 100644 --- a/src/server/rooms/Room.ts +++ b/src/server/rooms/Room.ts @@ -19,25 +19,9 @@ export class Room implements IRoom { public lastModifiedAt?: Date; public customFields?: { [key: string]: any }; public userIds?: Array; - private _USERNAMES: Array; + // private _USERNAMES: Array; - private [PrivateManager]: AppManager; - - /** - * @deprecated - */ - public get usernames(): Array { - // Get usernames - if (!this._USERNAMES) { - this._USERNAMES = this[PrivateManager].getBridges().getInternalBridge().doGetUsernamesOfRoomById(this.id); - } - - return this._USERNAMES; - } - - public set usernames(usernames) { - return; - } + // private [PrivateManager]: AppManager; public constructor(room: IRoom, manager: AppManager) { Object.assign(this, room); From 94fdaf037be3b4a0c07c73c0de68c17883c4a076 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Tue, 3 Jan 2023 10:48:05 -0300 Subject: [PATCH 11/13] Fix test --- tests/test-data/utilities.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test-data/utilities.ts b/tests/test-data/utilities.ts index 19d9f8c68..e70ac10a4 100644 --- a/tests/test-data/utilities.ts +++ b/tests/test-data/utilities.ts @@ -97,7 +97,6 @@ export class TestData { displayName: 'Testing Room', type: RoomType.CHANNEL, creator: TestData.getUser(), - usernames: [TestData.getUser().username], isDefault: true, isReadOnly: false, displaySystemMessages: true, From 3cdc0adac27467296d702bec2d5c61ebe99e4c29 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 5 Jan 2023 14:41:52 -0300 Subject: [PATCH 12/13] Add new getDirectByUserIds method --- src/definition/accessors/IRoomRead.ts | 7 +++++++ src/server/accessors/RoomRead.ts | 4 ++++ src/server/bridges/RoomBridge.ts | 7 +++++++ src/server/rooms/Room.ts | 3 --- tests/server/accessors/RoomRead.spec.ts | 5 +++++ tests/test-data/bridges/roomBridge.ts | 4 ++++ 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/definition/accessors/IRoomRead.ts b/src/definition/accessors/IRoomRead.ts index 2ccd18fb3..862e075ea 100644 --- a/src/definition/accessors/IRoomRead.ts +++ b/src/definition/accessors/IRoomRead.ts @@ -62,6 +62,13 @@ export interface IRoomRead { */ getDirectByUsernames(usernames: Array): Promise; + /** + * Gets a direct room with all user ids + * @param userIds all user ids belonging to the direct room + * @returns the room + */ + getDirectByUserIds(userIds: Array): Promise; + /** * Get a list of the moderators of a given room * diff --git a/src/server/accessors/RoomRead.ts b/src/server/accessors/RoomRead.ts index 137669c42..2b9f331ea 100644 --- a/src/server/accessors/RoomRead.ts +++ b/src/server/accessors/RoomRead.ts @@ -36,6 +36,10 @@ export class RoomRead implements IRoomRead { return this.roomBridge.doGetDirectByUsernames(usernames, this.appId); } + public getDirectByUserIds(userIds: Array): Promise { + return this.roomBridge.doGetDirectByUserIds(userIds, this.appId); + } + public getModerators(roomId: string): Promise> { return this.roomBridge.doGetModerators(roomId, this.appId); } diff --git a/src/server/bridges/RoomBridge.ts b/src/server/bridges/RoomBridge.ts index 1a97ff017..c01303ec7 100644 --- a/src/server/bridges/RoomBridge.ts +++ b/src/server/bridges/RoomBridge.ts @@ -37,6 +37,12 @@ export abstract class RoomBridge extends BaseBridge { } } + public async doGetDirectByUserIds(userIds: Array, appId: string): Promise { + if (this.hasReadPermission(appId)) { + return this.getDirectByUserIds(userIds, appId); + } + } + public async doGetDirectByUsernames(usernames: Array, appId: string): Promise { if (this.hasReadPermission(appId)) { return this.getDirectByUsernames(usernames, appId); @@ -97,6 +103,7 @@ export abstract class RoomBridge extends BaseBridge { protected abstract getCreatorById(roomId: string, appId: string): Promise; protected abstract getCreatorByName(roomName: string, appId: string): Promise; protected abstract getDirectByUsernames(usernames: Array, appId: string): Promise; + protected abstract getDirectByUserIds(userIds: Array, appId: string): Promise; protected abstract getMembers(roomId: string, appId: string): Promise>; protected abstract update(room: IRoom, members: Array, appId: string): Promise; protected abstract createDiscussion( diff --git a/src/server/rooms/Room.ts b/src/server/rooms/Room.ts index 5ef3a2a5a..43366b2b8 100644 --- a/src/server/rooms/Room.ts +++ b/src/server/rooms/Room.ts @@ -19,9 +19,6 @@ export class Room implements IRoom { public lastModifiedAt?: Date; public customFields?: { [key: string]: any }; public userIds?: Array; - // private _USERNAMES: Array; - - // private [PrivateManager]: AppManager; public constructor(room: IRoom, manager: AppManager) { Object.assign(this, room); diff --git a/tests/server/accessors/RoomRead.spec.ts b/tests/server/accessors/RoomRead.spec.ts index 9bd6ae4c1..96fe0f223 100644 --- a/tests/server/accessors/RoomRead.spec.ts +++ b/tests/server/accessors/RoomRead.spec.ts @@ -31,6 +31,9 @@ export class RoomReadAccessorTestFixture { doGetCreatorByName(name, appId): Promise { return Promise.resolve(theUser); }, + doGetDirectByUserIds(userIds, appId): Promise { + return Promise.resolve(theRoom); + }, doGetDirectByUsernames(usernames, appId): Promise { return Promise.resolve(theRoom); }, @@ -56,6 +59,8 @@ export class RoomReadAccessorTestFixture { Expect(await rr.getCreatorUserByName('testing')).toBe(this.user); Expect(await rr.getDirectByUsernames([this.user.username])).toBeDefined(); Expect(await rr.getDirectByUsernames([this.user.username])).toBe(this.room); + Expect(await rr.getDirectByUserIds([this.user.id])).toBeDefined(); + Expect(await rr.getDirectByUserIds([this.user.id])).toBe(this.room); } @AsyncTest() diff --git a/tests/test-data/bridges/roomBridge.ts b/tests/test-data/bridges/roomBridge.ts index 1159e2456..8e6d990a1 100644 --- a/tests/test-data/bridges/roomBridge.ts +++ b/tests/test-data/bridges/roomBridge.ts @@ -28,6 +28,10 @@ export class TestsRoomBridge extends RoomBridge { throw new Error('Method not implemented'); } + public getDirectByUserIds(userIds: Array, appId: string): Promise { + throw new Error('Method not implemented'); + } + public getMembers(roomName: string, appId: string): Promise> { throw new Error('Method not implemented.'); } From 7f4ac46fc4af9f2c8c1e241de8ea3facaab4f9cf Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 5 Jan 2023 14:58:31 -0300 Subject: [PATCH 13/13] Fix tests --- tests/server/accessors/RoomExtender.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/server/accessors/RoomExtender.spec.ts b/tests/server/accessors/RoomExtender.spec.ts index 0f12983b8..176f6d871 100644 --- a/tests/server/accessors/RoomExtender.spec.ts +++ b/tests/server/accessors/RoomExtender.spec.ts @@ -23,9 +23,7 @@ export class RoomExtenderAccessorTestFixture { Expect(() => re.addCustomField('thing', 'second')).toThrowError(Error, 'The room already contains a custom field by the key: thing'); Expect(() => re.addCustomField('thing.', 'second')).toThrowError(Error, 'The given key contains a period, which is not allowed. Key: thing.'); - Expect(room.usernames).not.toBeDefined(); Expect(re.addMember(TestData.getUser('theId', 'bradley'))).toBe(re); - Expect(room.usernames).not.toBeDefined(); Expect(re.getMembersBeingAdded()).toBeDefined(); Expect(re.getMembersBeingAdded()).not.toBeEmpty(); Expect(re.getMembersBeingAdded()[0]).not.toBeEmpty();