Skip to content

Commit

Permalink
improved types
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-lehnen-rc committed Nov 29, 2024
1 parent 526abcb commit 3f580f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 8 additions & 4 deletions apps/meteor/app/api/server/lib/maybeMigrateLivechatRoom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isOmnichannelRoom, type IRoom } from '@rocket.chat/core-typings';
import { Rooms } from '@rocket.chat/models';
import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import type { IOmnichannelRoom, IRoom } from '@rocket.chat/core-typings';
import { LivechatRooms } from '@rocket.chat/models';
import type { FindOptions } from 'mongodb';

import { projectionAllowsAttribute } from './projectionAllowsAttribute';
Expand All @@ -9,7 +10,10 @@ import { migrateVisitorIfMissingContact } from '../../../livechat/server/lib/con
* If the room is a livechat room and it doesn't yet have a contact, trigger the migration for its visitor and source
* The migration will create/use a contact and assign it to every room that matches this visitorId and source.
**/
export async function maybeMigrateLivechatRoom(room: IRoom | null, options: FindOptions<IRoom> = {}): Promise<IRoom | null> {
export async function maybeMigrateLivechatRoom(
room: IOmnichannelRoom | null,
options: FindOptions<IRoom> = {},
): Promise<IOmnichannelRoom | null> {
if (!room || !isOmnichannelRoom(room)) {
return room;
}
Expand All @@ -32,5 +36,5 @@ export async function maybeMigrateLivechatRoom(room: IRoom | null, options: Find
}

// Load the room again with the same options so it can be reloaded with the contactId in place
return Rooms.findOneById(room._id, options);
return LivechatRooms.findOneById(room._id, options);
}
6 changes: 1 addition & 5 deletions apps/meteor/app/livechat/server/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ import './roomAccessValidator.internalService';
const logger = new Logger('LivechatStartup');

Meteor.startup(async () => {
roomCoordinator.setRoomFind('l', async (_id) => {
const room = await LivechatRooms.findOneById(_id);

return (await maybeMigrateLivechatRoom(room)) ?? undefined;
});
roomCoordinator.setRoomFind('l', async (id) => maybeMigrateLivechatRoom(await LivechatRooms.findOneById(id)));

beforeLeaveRoomCallback.add(
(user, room) => {
Expand Down

0 comments on commit 3f580f8

Please sign in to comment.