Skip to content

Commit

Permalink
chore: Break big LivechatTyped file into smaller modules (#33656)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman authored and ricardogarim committed Oct 28, 2024
1 parent 27368c8 commit 5fa35d7
Show file tree
Hide file tree
Showing 18 changed files with 299 additions and 290 deletions.
6 changes: 4 additions & 2 deletions apps/meteor/app/apps/server/bridges/livechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { LivechatVisitors, LivechatRooms, LivechatDepartment, Users } from '@roc

import { callbacks } from '../../../../lib/callbacks';
import { deasyncPromise } from '../../../../server/deasync/deasync';
import { type ILivechatMessage, Livechat as LivechatTyped } from '../../../livechat/server/lib/LivechatTyped';
import { Livechat as LivechatTyped } from '../../../livechat/server/lib/LivechatTyped';
import { getRoomMessages } from '../../../livechat/server/lib/getRoomMessages';
import type { ILivechatMessage } from '../../../livechat/server/lib/localTypes';
import { settings } from '../../../settings/server';

declare module '@rocket.chat/apps/dist/converters/IAppMessagesConverter' {
Expand Down Expand Up @@ -352,7 +354,7 @@ export class AppLivechatBridge extends LivechatBridge {
throw new Error('Could not get the message converter to process livechat room messages');
}

const livechatMessages = await LivechatTyped.getRoomMessages({ rid: roomId });
const livechatMessages = await getRoomMessages({ rid: roomId });
return Promise.all(await livechatMessages.map((message) => messageConverter.convertMessage(message, livechatMessages)).toArray());
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/lib/server/functions/closeLivechatRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import { LivechatRooms, Subscriptions } from '@rocket.chat/models';

import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import type { CloseRoomParams } from '../../../livechat/server/lib/LivechatTyped';
import { Livechat } from '../../../livechat/server/lib/LivechatTyped';
import type { CloseRoomParams } from '../../../livechat/server/lib/localTypes';
import { notifyOnSubscriptionChanged } from '../lib/notifyListener';

export const closeLivechatRoom = async (
Expand Down
12 changes: 6 additions & 6 deletions apps/meteor/app/livechat/imports/server/rest/departments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
findArchivedDepartments,
} from '../../../server/api/lib/departments';
import { DepartmentHelper } from '../../../server/lib/Departments';
import { Livechat as LivechatTs } from '../../../server/lib/LivechatTyped';
import { saveDepartment, archiveDepartment, unarchiveDepartment, saveDepartmentAgents } from '../../../server/lib/departmentsLib';
import { isDepartmentCreationAvailable } from '../../../server/lib/isDepartmentCreationAvailable';

API.v1.addRoute(
Expand Down Expand Up @@ -62,7 +62,7 @@ API.v1.addRoute(

const agents = this.bodyParams.agents ? { upsert: this.bodyParams.agents } : {};
const { departmentUnit } = this.bodyParams;
const department = await LivechatTs.saveDepartment(
const department = await saveDepartment(
this.userId,
null,
this.bodyParams.department as ILivechatDepartment,
Expand Down Expand Up @@ -131,7 +131,7 @@ API.v1.addRoute(
}

const agentParam = permissionToAddAgents && agents ? { upsert: agents } : {};
await LivechatTs.saveDepartment(this.userId, _id, department, agentParam, departmentUnit || {});
await saveDepartment(this.userId, _id, department, agentParam, departmentUnit || {});

return API.v1.success({
department: await LivechatDepartment.findOneById(_id),
Expand Down Expand Up @@ -191,7 +191,7 @@ API.v1.addRoute(
},
{
async post() {
await LivechatTs.archiveDepartment(this.urlParams._id);
await archiveDepartment(this.urlParams._id);

return API.v1.success();
},
Expand All @@ -206,7 +206,7 @@ API.v1.addRoute(
},
{
async post() {
await LivechatTs.unarchiveDepartment(this.urlParams._id);
await unarchiveDepartment(this.urlParams._id);
return API.v1.success();
},
},
Expand Down Expand Up @@ -271,7 +271,7 @@ API.v1.addRoute(
remove: Array,
}),
);
await LivechatTs.saveDepartmentAgents(this.urlParams._id, this.bodyParams);
await saveDepartmentAgents(this.urlParams._id, this.bodyParams);

return API.v1.success();
},
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/imports/server/rest/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { FileUpload } from '../../../../file-upload/server';
import { checkUrlForSsrf } from '../../../../lib/server/functions/checkUrlForSsrf';
import { settings } from '../../../../settings/server';
import { setCustomField } from '../../../server/api/lib/customFields';
import type { ILivechatMessage } from '../../../server/lib/LivechatTyped';
import { Livechat as LivechatTyped } from '../../../server/lib/LivechatTyped';
import type { ILivechatMessage } from '../../../server/lib/localTypes';

const logger = new Logger('SMS');

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/api/v1/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { addUserToRoom } from '../../../../lib/server/functions/addUserToRoom';
import { closeLivechatRoom } from '../../../../lib/server/functions/closeLivechatRoom';
import { settings as rcSettings } from '../../../../settings/server';
import { normalizeTransferredByData } from '../../lib/Helper';
import type { CloseRoomParams } from '../../lib/LivechatTyped';
import { Livechat as LivechatTyped } from '../../lib/LivechatTyped';
import type { CloseRoomParams } from '../../lib/localTypes';
import { findGuest, findRoom, settings, findAgent, onCheckRoomParams } from '../lib/livechat';

const isAgentWithInfo = (agentObj: ILivechatAgent | { hiddenInfo: boolean }): agentObj is ILivechatAgent => !('hiddenInfo' in agentObj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import { LivechatRooms } from '@rocket.chat/models';

import { callbacks } from '../../../../lib/callbacks';
import type { CloseRoomParams } from '../lib/LivechatTyped';
import type { CloseRoomParams } from '../lib/localTypes';
import { sendTranscript } from '../lib/sendTranscript';

type LivechatCloseCallbackParams = {
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/livechat/server/lib/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { settings } from '../../../settings/server';
import { Livechat as LivechatTyped } from './LivechatTyped';
import { queueInquiry, saveQueueInquiry } from './QueueManager';
import { RoutingManager } from './RoutingManager';
import { getOnlineAgents } from './getOnlineAgents';

const logger = new Logger('LivechatHelper');
export const allowAgentSkipQueue = (agent: SelectedAgent) => {
Expand Down Expand Up @@ -403,7 +404,7 @@ export const dispatchInquiryQueued = async (inquiry: ILivechatInquiryRecord, age
await saveQueueInquiry(inquiry);

// Alert only the online agents of the queued request
const onlineAgents = await LivechatTyped.getOnlineAgents(department, agent);
const onlineAgents = await getOnlineAgents(department, agent);
if (!onlineAgents) {
logger.debug('Cannot notify agents of queued inquiry. No online agents found');
return;
Expand Down
Loading

0 comments on commit 5fa35d7

Please sign in to comment.