From 9aa4ecea434857b84deb25deba9c6adef7bb1aa2 Mon Sep 17 00:00:00 2001 From: Dnouv Date: Tue, 24 Sep 2024 16:40:27 +0530 Subject: [PATCH] migrate getUserUnreadMessageCountByRoom to room read --- src/definition/accessors/IRoomRead.ts | 7 +++++++ src/definition/accessors/IUserRead.ts | 7 ------- src/server/accessors/RoomRead.ts | 4 ++++ src/server/accessors/UserRead.ts | 4 ---- src/server/bridges/RoomBridge.ts | 8 ++++++++ src/server/bridges/UserBridge.ts | 8 -------- tests/test-data/bridges/roomBridge.ts | 4 ++++ tests/test-data/bridges/userBridge.ts | 4 ---- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/definition/accessors/IRoomRead.ts b/src/definition/accessors/IRoomRead.ts index 49a97ca6c..51d34e82b 100644 --- a/src/definition/accessors/IRoomRead.ts +++ b/src/definition/accessors/IRoomRead.ts @@ -103,4 +103,11 @@ export interface IRoomRead { * @returns A Promise that resolves to an array of IMessage objects representing the unread messages for the specified user in the specified room. */ getUnreadByRoomAndUser(roomId: string, uid: string, options?: Partial): Promise; + + /** + * Gets the user's unread messages count in a room. + * @param uid user's id + * @param roomId room's id + */ + getUserUnreadMessageCountByRoom(uid: string, roomId: string): Promise; } diff --git a/src/definition/accessors/IUserRead.ts b/src/definition/accessors/IUserRead.ts index c99c65923..33c4c6e45 100644 --- a/src/definition/accessors/IUserRead.ts +++ b/src/definition/accessors/IUserRead.ts @@ -19,11 +19,4 @@ export interface IUserRead { * @param uid user's id */ getUserUnreadMessageCount(uid: string): Promise; - - /** - * Gets the user's unread messages count in a room. - * @param uid user's id - * @param roomId room's id - */ - getUserUnreadMessageCountByRoom(uid: string, roomId: string): Promise; } diff --git a/src/server/accessors/RoomRead.ts b/src/server/accessors/RoomRead.ts index da93c63f6..e2742a3ba 100644 --- a/src/server/accessors/RoomRead.ts +++ b/src/server/accessors/RoomRead.ts @@ -76,6 +76,10 @@ export class RoomRead implements IRoomRead { return this.roomBridge.doGetUnreadByRoomAndUser(roomId, uid, completeOptions, this.appId); } + public getUserUnreadMessageCountByRoom(uid: string, rid: string): Promise { + return this.roomBridge.doGetUserUnreadMessageCountByRoom(uid, rid, this.appId); + } + // If there are any invalid fields or values, throw private validateSort(sort: Record) { Object.entries(sort).forEach(([key, value]) => { diff --git a/src/server/accessors/UserRead.ts b/src/server/accessors/UserRead.ts index 5112046ea..4eeb38cc7 100644 --- a/src/server/accessors/UserRead.ts +++ b/src/server/accessors/UserRead.ts @@ -20,8 +20,4 @@ export class UserRead implements IUserRead { public getUserUnreadMessageCount(uid: string): Promise { return this.userBridge.doGetUserUnreadMessageCount(uid, this.appId); } - - public getUserUnreadMessageCountByRoom(uid: string, rid: string): Promise { - return this.userBridge.doGetUserUnreadMessageCountByRoom(uid, rid, this.appId); - } } diff --git a/src/server/bridges/RoomBridge.ts b/src/server/bridges/RoomBridge.ts index 9bcb7450d..b9f54dee3 100644 --- a/src/server/bridges/RoomBridge.ts +++ b/src/server/bridges/RoomBridge.ts @@ -117,6 +117,12 @@ export abstract class RoomBridge extends BaseBridge { } } + public async doGetUserUnreadMessageCountByRoom(uid: string, roomId: string, appId: string): Promise { + if (this.hasReadPermission(appId)) { + return this.getUserUnreadMessageCountByRoom(uid, roomId, appId); + } + } + protected abstract create(room: IRoom, members: Array, appId: string): Promise; protected abstract getById(roomId: string, appId: string): Promise; @@ -155,6 +161,8 @@ export abstract class RoomBridge extends BaseBridge { protected abstract getUnreadByRoomAndUser(roomId: string, uid: string, options: GetMessagesOptions, appId: string): Promise; + protected abstract getUserUnreadMessageCountByRoom(uid: string, roomId: string, appId: string): Promise; + private hasWritePermission(appId: string): boolean { if (AppPermissionManager.hasPermission(appId, AppPermissions.room.write)) { return true; diff --git a/src/server/bridges/UserBridge.ts b/src/server/bridges/UserBridge.ts index 59f4e12d4..d67f2a091 100644 --- a/src/server/bridges/UserBridge.ts +++ b/src/server/bridges/UserBridge.ts @@ -45,12 +45,6 @@ export abstract class UserBridge extends BaseBridge { } } - public async doGetUserUnreadMessageCountByRoom(uid: string, roomId: string, appId: string): Promise { - if (this.hasReadPermission(appId)) { - return this.getUserUnreadMessageCountByRoom(uid, roomId, appId); - } - } - public async doDeleteUsersCreatedByApp(appId: string, type: UserType.BOT | UserType.APP): Promise { if (this.hasWritePermission(appId)) { return this.deleteUsersCreatedByApp(appId, type); @@ -73,8 +67,6 @@ export abstract class UserBridge extends BaseBridge { protected abstract getUserUnreadMessageCount(uid: string, appId: string): Promise; - protected abstract getUserUnreadMessageCountByRoom(uid: string, roomId: string, appId: string): Promise; - /** * Creates a user. * @param data the essential data for creating a user diff --git a/tests/test-data/bridges/roomBridge.ts b/tests/test-data/bridges/roomBridge.ts index 3fe722295..7f5a79fb1 100644 --- a/tests/test-data/bridges/roomBridge.ts +++ b/tests/test-data/bridges/roomBridge.ts @@ -68,4 +68,8 @@ export class TestsRoomBridge extends RoomBridge { public getUnreadByRoomAndUser(roomId: string, uid: string, options: GetMessagesOptions, appId: string): Promise { throw new Error('Method not implemented.'); } + + protected getUserUnreadMessageCountByRoom(uid: string, roomId: string, appId: string): Promise { + throw new Error('Method not implemented.'); + } } diff --git a/tests/test-data/bridges/userBridge.ts b/tests/test-data/bridges/userBridge.ts index a8cbca41d..83464315b 100644 --- a/tests/test-data/bridges/userBridge.ts +++ b/tests/test-data/bridges/userBridge.ts @@ -38,10 +38,6 @@ export class TestsUserBridge extends UserBridge { throw new Error('Method not implemented.'); } - protected getUserUnreadMessageCountByRoom(uid: string, roomId: string, appId: string): Promise { - throw new Error('Method not implemented.'); - } - protected deactivate(userId: IUser['id'], confirmRelinquish: boolean, appId: string): Promise { throw new Error('Method not implemented.'); }