Skip to content

Commit

Permalink
Add new getDirectByUserIds method
Browse files Browse the repository at this point in the history
  • Loading branch information
d-gubert committed Jan 5, 2023
1 parent 94fdaf0 commit 3cdc0ad
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/definition/accessors/IRoomRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ export interface IRoomRead {
*/
getDirectByUsernames(usernames: Array<string>): Promise<IRoom>;

/**
* Gets a direct room with all user ids
* @param userIds all user ids belonging to the direct room
* @returns the room
*/
getDirectByUserIds(userIds: Array<string>): Promise<IRoom>;

/**
* Get a list of the moderators of a given room
*
Expand Down
4 changes: 4 additions & 0 deletions src/server/accessors/RoomRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export class RoomRead implements IRoomRead {
return this.roomBridge.doGetDirectByUsernames(usernames, this.appId);
}

public getDirectByUserIds(userIds: Array<string>): Promise<IRoom> {
return this.roomBridge.doGetDirectByUserIds(userIds, this.appId);
}

public getModerators(roomId: string): Promise<Array<IUser>> {
return this.roomBridge.doGetModerators(roomId, this.appId);
}
Expand Down
7 changes: 7 additions & 0 deletions src/server/bridges/RoomBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export abstract class RoomBridge extends BaseBridge {
}
}

public async doGetDirectByUserIds(userIds: Array<string>, appId: string): Promise<IRoom | undefined> {
if (this.hasReadPermission(appId)) {
return this.getDirectByUserIds(userIds, appId);
}
}

public async doGetDirectByUsernames(usernames: Array<string>, appId: string): Promise<IRoom | undefined> {
if (this.hasReadPermission(appId)) {
return this.getDirectByUsernames(usernames, appId);
Expand Down Expand Up @@ -97,6 +103,7 @@ export abstract class RoomBridge extends BaseBridge {
protected abstract getCreatorById(roomId: string, appId: string): Promise<IUser | undefined>;
protected abstract getCreatorByName(roomName: string, appId: string): Promise<IUser | undefined>;
protected abstract getDirectByUsernames(usernames: Array<string>, appId: string): Promise<IRoom | undefined>;
protected abstract getDirectByUserIds(userIds: Array<string>, appId: string): Promise<IRoom | undefined>;
protected abstract getMembers(roomId: string, appId: string): Promise<Array<IUser>>;
protected abstract update(room: IRoom, members: Array<string>, appId: string): Promise<void>;
protected abstract createDiscussion(
Expand Down
3 changes: 0 additions & 3 deletions src/server/rooms/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export class Room implements IRoom {
public lastModifiedAt?: Date;
public customFields?: { [key: string]: any };
public userIds?: Array<string>;
// private _USERNAMES: Array<string>;

// private [PrivateManager]: AppManager;

public constructor(room: IRoom, manager: AppManager) {
Object.assign(this, room);
Expand Down
5 changes: 5 additions & 0 deletions tests/server/accessors/RoomRead.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class RoomReadAccessorTestFixture {
doGetCreatorByName(name, appId): Promise<IUser> {
return Promise.resolve(theUser);
},
doGetDirectByUserIds(userIds, appId): Promise<IRoom> {
return Promise.resolve(theRoom);
},
doGetDirectByUsernames(usernames, appId): Promise<IRoom> {
return Promise.resolve(theRoom);
},
Expand All @@ -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()
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 @@ -28,6 +28,10 @@ export class TestsRoomBridge extends RoomBridge {
throw new Error('Method not implemented');
}

public getDirectByUserIds(userIds: Array<string>, appId: string): Promise<IRoom> {
throw new Error('Method not implemented');
}

public getMembers(roomName: string, appId: string): Promise<Array<IUser>> {
throw new Error('Method not implemented.');
}
Expand Down

0 comments on commit 3cdc0ad

Please sign in to comment.