Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.

Commit 5c05a48

Browse files
committed
Add new getDirectByUserIds method
1 parent 94fdaf0 commit 5c05a48

5 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/definition/accessors/IRoomRead.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ export interface IRoomRead {
6262
*/
6363
getDirectByUsernames(usernames: Array<string>): Promise<IRoom>;
6464

65+
/**
66+
* Gets a direct room with all user ids
67+
* @param userIds all user ids belonging to the direct room
68+
* @returns the room
69+
*/
70+
getDirectByUserIds(userIds: Array<string>): Promise<IRoom>;
71+
6572
/**
6673
* Get a list of the moderators of a given room
6774
*

src/server/accessors/RoomRead.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export class RoomRead implements IRoomRead {
3636
return this.roomBridge.doGetDirectByUsernames(usernames, this.appId);
3737
}
3838

39+
public getDirectByUserIds(userIds: Array<string>): Promise<IRoom> {
40+
return this.roomBridge.doGetDirectByUserIds(userIds, this.appId);
41+
}
42+
3943
public getModerators(roomId: string): Promise<Array<IUser>> {
4044
return this.roomBridge.doGetModerators(roomId, this.appId);
4145
}

src/server/bridges/RoomBridge.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export abstract class RoomBridge extends BaseBridge {
3737
}
3838
}
3939

40+
public async doGetDirectByUserIds(userIds: Array<string>, appId: string): Promise<IRoom | undefined> {
41+
if (this.hasReadPermission(appId)) {
42+
return this.getDirectByUserIds(userIds, appId);
43+
}
44+
}
45+
4046
public async doGetDirectByUsernames(usernames: Array<string>, appId: string): Promise<IRoom | undefined> {
4147
if (this.hasReadPermission(appId)) {
4248
return this.getDirectByUsernames(usernames, appId);
@@ -97,6 +103,7 @@ export abstract class RoomBridge extends BaseBridge {
97103
protected abstract getCreatorById(roomId: string, appId: string): Promise<IUser | undefined>;
98104
protected abstract getCreatorByName(roomName: string, appId: string): Promise<IUser | undefined>;
99105
protected abstract getDirectByUsernames(usernames: Array<string>, appId: string): Promise<IRoom | undefined>;
106+
protected abstract getDirectByUserIds(userIds: Array<string>, appId: string): Promise<IRoom | undefined>;
100107
protected abstract getMembers(roomId: string, appId: string): Promise<Array<IUser>>;
101108
protected abstract update(room: IRoom, members: Array<string>, appId: string): Promise<void>;
102109
protected abstract createDiscussion(

src/server/rooms/Room.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ export class Room implements IRoom {
1919
public lastModifiedAt?: Date;
2020
public customFields?: { [key: string]: any };
2121
public userIds?: Array<string>;
22-
// private _USERNAMES: Array<string>;
23-
24-
// private [PrivateManager]: AppManager;
2522

2623
public constructor(room: IRoom, manager: AppManager) {
2724
Object.assign(this, room);

tests/server/accessors/RoomRead.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export class RoomReadAccessorTestFixture {
3131
doGetCreatorByName(name, appId): Promise<IUser> {
3232
return Promise.resolve(theUser);
3333
},
34+
doGetDirectByUserIds(userIds, appId): Promise<IRoom> {
35+
return Promise.resolve(theRoom);
36+
},
3437
doGetDirectByUsernames(usernames, appId): Promise<IRoom> {
3538
return Promise.resolve(theRoom);
3639
},
@@ -56,6 +59,8 @@ export class RoomReadAccessorTestFixture {
5659
Expect(await rr.getCreatorUserByName('testing')).toBe(this.user);
5760
Expect(await rr.getDirectByUsernames([this.user.username])).toBeDefined();
5861
Expect(await rr.getDirectByUsernames([this.user.username])).toBe(this.room);
62+
Expect(await rr.getDirectByUserIds([this.user.id])).toBeDefined();
63+
Expect(await rr.getDirectByUserIds([this.user.id])).toBe(this.room);
5964
}
6065

6166
@AsyncTest()

0 commit comments

Comments
 (0)