Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
remove 'room'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dnouv committed Sep 26, 2024
1 parent 9aa4ece commit d5aa91c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/definition/accessors/IRoomRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ export interface IRoomRead {
* - sort: An object defining the sorting order of the messages. Each key is a field to sort by, and the value is either 'asc' for ascending order or 'desc' for descending order.
* @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[]>;
getUnreadByUser(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>;
getUserUnreadMessageCount(uid: string, roomId: string): Promise<number | undefined>;
}
8 changes: 4 additions & 4 deletions src/server/accessors/RoomRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class RoomRead implements IRoomRead {
return this.roomBridge.doGetLeaders(roomId, this.appId);
}

public async getUnreadByRoomAndUser(roomId: string, uid: string, options: Partial<GetMessagesOptions> = {}): Promise<IMessageRaw[]> {
public async getUnreadByUser(roomId: string, uid: string, options: Partial<GetMessagesOptions> = {}): Promise<IMessageRaw[]> {
const { limit = 100, sort = { createdAt: 'asc' }, skip = 0 } = options;

if (typeof roomId !== 'string' || roomId.trim().length === 0) {
Expand All @@ -73,11 +73,11 @@ export class RoomRead implements IRoomRead {

const completeOptions: GetMessagesOptions = { limit, sort, skip };

return this.roomBridge.doGetUnreadByRoomAndUser(roomId, uid, completeOptions, this.appId);
return this.roomBridge.doGetUnreadByUser(roomId, uid, completeOptions, this.appId);
}

public getUserUnreadMessageCountByRoom(uid: string, rid: string): Promise<number> {
return this.roomBridge.doGetUserUnreadMessageCountByRoom(uid, rid, this.appId);
public getUserUnreadMessageCount(uid: string, rid: string): Promise<number> {
return this.roomBridge.doGetUserUnreadMessageCount(uid, rid, this.appId);
}

// If there are any invalid fields or values, throw
Expand Down
12 changes: 6 additions & 6 deletions src/server/bridges/RoomBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ export abstract class RoomBridge extends BaseBridge {
}
}

public async doGetUnreadByRoomAndUser(roomId: string, uid: string, options: GetMessagesOptions, appId: string): Promise<IMessageRaw[]> {
public async doGetUnreadByUser(roomId: string, uid: string, options: GetMessagesOptions, appId: string): Promise<IMessageRaw[]> {
if (this.hasReadPermission(appId)) {
return this.getUnreadByRoomAndUser(roomId, uid, options, appId);
return this.getUnreadByUser(roomId, uid, options, appId);
}
}

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

Expand Down Expand Up @@ -159,9 +159,9 @@ export abstract class RoomBridge extends BaseBridge {

protected abstract removeUsers(roomId: string, usernames: Array<string>, appId: string): Promise<void>;

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

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

private hasWritePermission(appId: string): boolean {
if (AppPermissionManager.hasPermission(appId, AppPermissions.room.write)) {
Expand Down
10 changes: 5 additions & 5 deletions tests/server/accessors/RoomRead.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class RoomReadAccessorTestFixture {
doGetMessages(roomId, options, appId): Promise<IMessageRaw[]> {
return Promise.resolve(theMessages);
},
doGetUnreadByRoomAndUser(roomId, uid, options, appId): Promise<IMessageRaw[]> {
doGetUnreadByUser(roomId, uid, options, appId): Promise<IMessageRaw[]> {
if (roomId === unreadRoomId && uid === unreadUserId) {
return Promise.resolve(theUnreadMsg);
}
Expand All @@ -84,11 +84,11 @@ export class RoomReadAccessorTestFixture {
Expect(await rr.getDirectByUsernames([this.user.username])).toBe(this.room);
Expect(await rr.getMessages('testing')).toBeDefined();
Expect(await rr.getMessages('testing')).toBe(this.messages);
Expect(await rr.getUnreadByRoomAndUser(this.unreadRoomId, this.unreadUserId)).toBeDefined();
Expect(await rr.getUnreadByRoomAndUser(this.unreadRoomId, this.unreadUserId)).toEqual(this.messages);
Expect(await rr.getUnreadByUser(this.unreadRoomId, this.unreadUserId)).toBeDefined();
Expect(await rr.getUnreadByUser(this.unreadRoomId, this.unreadUserId)).toEqual(this.messages);

Expect(await rr.getUnreadByRoomAndUser('fake', 'fake')).toBeDefined();
Expect(await rr.getUnreadByRoomAndUser('fake', 'fake')).toEqual([]);
Expect(await rr.getUnreadByUser('fake', 'fake')).toBeDefined();
Expect(await rr.getUnreadByUser('fake', 'fake')).toEqual([]);
}

@AsyncTest()
Expand Down
4 changes: 2 additions & 2 deletions tests/test-data/bridges/roomBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ export class TestsRoomBridge extends RoomBridge {
throw new Error('Method not implemented');
}

public getUnreadByRoomAndUser(roomId: string, uid: string, options: GetMessagesOptions, appId: string): Promise<IMessageRaw[]> {
public getUnreadByUser(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> {
protected getUserUnreadMessageCount(uid: string, roomId: string, appId: string): Promise<number> {
throw new Error('Method not implemented.');
}
}

0 comments on commit d5aa91c

Please sign in to comment.