Skip to content

Commit

Permalink
migrate getUserUnreadMessageCountByRoom to room read
Browse files Browse the repository at this point in the history
  • Loading branch information
Dnouv committed Sep 24, 2024
1 parent 625105c commit 9aa4ece
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
7 changes: 7 additions & 0 deletions src/definition/accessors/IRoomRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetMessagesOptions>): Promise<IMessageRaw[]>;

/**
* 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<number | undefined>;
}
7 changes: 0 additions & 7 deletions src/definition/accessors/IUserRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,4 @@ export interface IUserRead {
* @param uid user's id
*/
getUserUnreadMessageCount(uid: string): Promise<number | undefined>;

/**
* 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<number | undefined>;
}
4 changes: 4 additions & 0 deletions src/server/accessors/RoomRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number> {
return this.roomBridge.doGetUserUnreadMessageCountByRoom(uid, rid, this.appId);
}

// If there are any invalid fields or values, throw
private validateSort(sort: Record<string, unknown>) {
Object.entries(sort).forEach(([key, value]) => {
Expand Down
4 changes: 0 additions & 4 deletions src/server/accessors/UserRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@ export class UserRead implements IUserRead {
public getUserUnreadMessageCount(uid: string): Promise<number> {
return this.userBridge.doGetUserUnreadMessageCount(uid, this.appId);
}

public getUserUnreadMessageCountByRoom(uid: string, rid: string): Promise<number> {
return this.userBridge.doGetUserUnreadMessageCountByRoom(uid, rid, this.appId);
}
}
8 changes: 8 additions & 0 deletions src/server/bridges/RoomBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ export abstract class RoomBridge extends BaseBridge {
}
}

public async doGetUserUnreadMessageCountByRoom(uid: string, roomId: string, appId: string): Promise<number> {
if (this.hasReadPermission(appId)) {
return this.getUserUnreadMessageCountByRoom(uid, roomId, appId);
}
}

protected abstract create(room: IRoom, members: Array<string>, appId: string): Promise<string>;

protected abstract getById(roomId: string, appId: string): Promise<IRoom>;
Expand Down Expand Up @@ -155,6 +161,8 @@ export abstract class RoomBridge extends BaseBridge {

protected abstract getUnreadByRoomAndUser(roomId: string, uid: string, options: GetMessagesOptions, appId: string): Promise<IMessageRaw[]>;

protected abstract getUserUnreadMessageCountByRoom(uid: string, roomId: string, appId: string): Promise<number>;

private hasWritePermission(appId: string): boolean {
if (AppPermissionManager.hasPermission(appId, AppPermissions.room.write)) {
return true;
Expand Down
8 changes: 0 additions & 8 deletions src/server/bridges/UserBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ export abstract class UserBridge extends BaseBridge {
}
}

public async doGetUserUnreadMessageCountByRoom(uid: string, roomId: string, appId: string): Promise<number> {
if (this.hasReadPermission(appId)) {
return this.getUserUnreadMessageCountByRoom(uid, roomId, appId);
}
}

public async doDeleteUsersCreatedByApp(appId: string, type: UserType.BOT | UserType.APP): Promise<boolean> {
if (this.hasWritePermission(appId)) {
return this.deleteUsersCreatedByApp(appId, type);
Expand All @@ -73,8 +67,6 @@ export abstract class UserBridge extends BaseBridge {

protected abstract getUserUnreadMessageCount(uid: string, appId: string): Promise<number>;

protected abstract getUserUnreadMessageCountByRoom(uid: string, roomId: string, appId: string): Promise<number>;

/**
* Creates a user.
* @param data the essential data for creating a user
Expand Down
4 changes: 4 additions & 0 deletions tests/test-data/bridges/roomBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ export class TestsRoomBridge extends RoomBridge {
public getUnreadByRoomAndUser(roomId: string, uid: string, options: GetMessagesOptions, appId: string): Promise<IMessageRaw[]> {
throw new Error('Method not implemented.');
}

protected getUserUnreadMessageCountByRoom(uid: string, roomId: string, appId: string): Promise<number> {
throw new Error('Method not implemented.');
}
}
4 changes: 0 additions & 4 deletions tests/test-data/bridges/userBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ export class TestsUserBridge extends UserBridge {
throw new Error('Method not implemented.');
}

protected getUserUnreadMessageCountByRoom(uid: string, roomId: string, appId: string): Promise<number> {
throw new Error('Method not implemented.');
}

protected deactivate(userId: IUser['id'], confirmRelinquish: boolean, appId: string): Promise<boolean> {
throw new Error('Method not implemented.');
}
Expand Down

0 comments on commit 9aa4ece

Please sign in to comment.