Skip to content
Snippets Groups Projects
Unverified Commit d7905a3d authored by Kevin Aleman's avatar Kevin Aleman Committed by GitHub
Browse files

refactor: Remove `livechat.js` file (#31179)

parent 6f88d8d2
No related branches found
No related tags found
No related merge requests found
Showing
with 19 additions and 30 deletions
import { OmnichannelIntegration } from '@rocket.chat/core-services'; import { OmnichannelIntegration } from '@rocket.chat/core-services';
import { OmnichannelSourceType } from '@rocket.chat/core-typings'; import { OmnichannelSourceType } from '@rocket.chat/core-typings';
import { Logger } from '@rocket.chat/logger';
import { LivechatVisitors, LivechatRooms, LivechatDepartment } from '@rocket.chat/models'; import { LivechatVisitors, LivechatRooms, LivechatDepartment } from '@rocket.chat/models';
import { Random } from '@rocket.chat/random'; import { Random } from '@rocket.chat/random';
import { serverFetch as fetch } from '@rocket.chat/server-fetch'; import { serverFetch as fetch } from '@rocket.chat/server-fetch';
...@@ -8,9 +9,10 @@ import { Meteor } from 'meteor/meteor'; ...@@ -8,9 +9,10 @@ import { Meteor } from 'meteor/meteor';
import { API } from '../../../../api/server'; import { API } from '../../../../api/server';
import { FileUpload } from '../../../../file-upload/server'; import { FileUpload } from '../../../../file-upload/server';
import { settings } from '../../../../settings/server'; import { settings } from '../../../../settings/server';
import { Livechat } from '../../../server/lib/Livechat';
import { Livechat as LivechatTyped } from '../../../server/lib/LivechatTyped'; import { Livechat as LivechatTyped } from '../../../server/lib/LivechatTyped';
const logger = new Logger('SMS');
const getUploadFile = async (details, fileUrl) => { const getUploadFile = async (details, fileUrl) => {
const response = await fetch(fileUrl); const response = await fetch(fileUrl);
...@@ -156,7 +158,7 @@ API.v1.addRoute('livechat/sms-incoming/:service', { ...@@ -156,7 +158,7 @@ API.v1.addRoute('livechat/sms-incoming/:service', {
attachment.title_link_download = true; attachment.title_link_download = true;
} }
} catch (err) { } catch (err) {
Livechat.logger.error({ msg: 'Attachment upload failed', err }); logger.error({ msg: 'Attachment upload failed', err });
attachment = { attachment = {
fields: [ fields: [
{ {
......
import { Logger } from '@rocket.chat/logger';
import { serverFetch as fetch } from '@rocket.chat/server-fetch'; import { serverFetch as fetch } from '@rocket.chat/server-fetch';
import { API } from '../../../../api/server'; import { API } from '../../../../api/server';
import { settings } from '../../../../settings/server'; import { settings } from '../../../../settings/server';
import { Livechat } from '../../lib/Livechat';
const logger = new Logger('WebhookTest');
API.v1.addRoute( API.v1.addRoute(
'livechat/webhook.test', 'livechat/webhook.test',
...@@ -70,18 +72,18 @@ API.v1.addRoute( ...@@ -70,18 +72,18 @@ API.v1.addRoute(
} }
try { try {
Livechat.logger.debug(`Testing webhook ${webhookUrl}`); logger.debug(`Testing webhook ${webhookUrl}`);
const request = await fetch(webhookUrl, options); const request = await fetch(webhookUrl, options);
const response = await request.text(); const response = await request.text();
Livechat.logger.debug({ response }); logger.debug({ response });
if (request.status === 200) { if (request.status === 200) {
return API.v1.success(); return API.v1.success();
} }
throw new Error('Invalid status code'); throw new Error('Invalid status code');
} catch (error) { } catch (error) {
Livechat.logger.error(`Error testing webhook: ${error}`); logger.error(`Error testing webhook: ${error}`);
throw new Error('error-invalid-webhook-response'); throw new Error('error-invalid-webhook-response');
} }
}, },
......
...@@ -76,5 +76,3 @@ import './api'; ...@@ -76,5 +76,3 @@ import './api';
import './api/rest'; import './api/rest';
import './externalFrame'; import './externalFrame';
import './methods/saveBusinessHour'; import './methods/saveBusinessHour';
export { Livechat } from './lib/Livechat';
...@@ -38,7 +38,6 @@ import { hasRoleAsync } from '../../../authorization/server/functions/hasRole'; ...@@ -38,7 +38,6 @@ import { hasRoleAsync } from '../../../authorization/server/functions/hasRole';
import { sendNotification } from '../../../lib/server'; import { sendNotification } from '../../../lib/server';
import { sendMessage } from '../../../lib/server/functions/sendMessage'; import { sendMessage } from '../../../lib/server/functions/sendMessage';
import { settings } from '../../../settings/server'; import { settings } from '../../../settings/server';
import { Livechat } from './Livechat';
import { Livechat as LivechatTyped } from './LivechatTyped'; import { Livechat as LivechatTyped } from './LivechatTyped';
import { queueInquiry, saveQueueInquiry } from './QueueManager'; import { queueInquiry, saveQueueInquiry } from './QueueManager';
import { RoutingManager } from './RoutingManager'; import { RoutingManager } from './RoutingManager';
...@@ -296,7 +295,7 @@ export const parseAgentCustomFields = (customFields?: Record<string, any>) => { ...@@ -296,7 +295,7 @@ export const parseAgentCustomFields = (customFields?: Record<string, any>) => {
const parseCustomFields = JSON.parse(accountCustomFields); const parseCustomFields = JSON.parse(accountCustomFields);
return Object.keys(parseCustomFields).filter((customFieldKey) => parseCustomFields[customFieldKey].sendToIntegrations === true); return Object.keys(parseCustomFields).filter((customFieldKey) => parseCustomFields[customFieldKey].sendToIntegrations === true);
} catch (error) { } catch (error) {
Livechat.logger.error(error); logger.error(error);
return []; return [];
} }
}; };
......
// Note: Please don't add any new methods to this file, since its still in js and we are migrating to ts
// Please add new methods to LivechatTyped.ts
import { Logger } from '@rocket.chat/logger';
const logger = new Logger('Livechat');
export const Livechat = {
logger,
};
...@@ -6,7 +6,6 @@ import { Meteor } from 'meteor/meteor'; ...@@ -6,7 +6,6 @@ import { Meteor } from 'meteor/meteor';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger'; import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';
import { Livechat } from '../lib/Livechat';
declare module '@rocket.chat/ui-contexts' { declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention
...@@ -27,7 +26,6 @@ Meteor.methods<ServerMethods>({ ...@@ -27,7 +26,6 @@ Meteor.methods<ServerMethods>({
} }
if (!options.chartOptions?.name) { if (!options.chartOptions?.name) {
Livechat.logger.warn('Incorrect analytics options');
return; return;
} }
......
...@@ -5,7 +5,6 @@ import type { ServerMethods } from '@rocket.chat/ui-contexts'; ...@@ -5,7 +5,6 @@ import type { ServerMethods } from '@rocket.chat/ui-contexts';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { Livechat } from '../lib/Livechat';
declare module '@rocket.chat/ui-contexts' { declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention
...@@ -24,14 +23,12 @@ Meteor.methods<ServerMethods>({ ...@@ -24,14 +23,12 @@ Meteor.methods<ServerMethods>({
} }
if (!options.chartOptions?.name) { if (!options.chartOptions?.name) {
Livechat.logger.error('Incorrect chart options');
return; return;
} }
const user = await Users.findOneById(userId, { projection: { _id: 1, utcOffset: 1 } }); const user = await Users.findOneById(userId, { projection: { _id: 1, utcOffset: 1 } });
if (!user) { if (!user) {
Livechat.logger.error('User not found');
return; return;
} }
......
...@@ -7,7 +7,6 @@ import { Meteor } from 'meteor/meteor'; ...@@ -7,7 +7,6 @@ import { Meteor } from 'meteor/meteor';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger'; import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';
import { settings } from '../../../settings/server'; import { settings } from '../../../settings/server';
import { Livechat } from '../lib/Livechat';
declare module '@rocket.chat/ui-contexts' { declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention
...@@ -27,7 +26,6 @@ Meteor.methods<ServerMethods>({ ...@@ -27,7 +26,6 @@ Meteor.methods<ServerMethods>({
} }
if (!options.analyticsOptions?.name) { if (!options.analyticsOptions?.name) {
Livechat.logger.error('Incorrect analytics options');
return; return;
} }
......
import type { IOmnichannelRoom } from '@rocket.chat/core-typings'; import type { IOmnichannelRoom } from '@rocket.chat/core-typings';
import { Logger } from '@rocket.chat/logger';
import { LivechatRooms } from '@rocket.chat/models'; import { LivechatRooms } from '@rocket.chat/models';
import type { ServerMethods } from '@rocket.chat/ui-contexts'; import type { ServerMethods } from '@rocket.chat/ui-contexts';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
...@@ -16,6 +17,7 @@ declare module '@rocket.chat/ui-contexts' { ...@@ -16,6 +17,7 @@ declare module '@rocket.chat/ui-contexts' {
Meteor.methods<ServerMethods>({ Meteor.methods<ServerMethods>({
async 'livechat:removeAllClosedRooms'(departmentIds) { async 'livechat:removeAllClosedRooms'(departmentIds) {
const logger = new Logger('livechat:removeAllClosedRooms');
const user = Meteor.userId(); const user = Meteor.userId();
if (!user || !(await hasPermissionAsync(user, 'remove-closed-livechat-rooms'))) { if (!user || !(await hasPermissionAsync(user, 'remove-closed-livechat-rooms'))) {
...@@ -25,7 +27,7 @@ Meteor.methods<ServerMethods>({ ...@@ -25,7 +27,7 @@ Meteor.methods<ServerMethods>({
} }
// These are not debug logs since we want to know when the action is performed // These are not debug logs since we want to know when the action is performed
Livechat.logger.info(`User ${Meteor.userId()} is removing all closed rooms`); logger.info(`User ${Meteor.userId()} is removing all closed rooms`);
const extraQuery = await callbacks.run('livechat.applyRoomRestrictions', {}); const extraQuery = await callbacks.run('livechat.applyRoomRestrictions', {});
const promises: Promise<void>[] = []; const promises: Promise<void>[] = [];
...@@ -34,7 +36,7 @@ Meteor.methods<ServerMethods>({ ...@@ -34,7 +36,7 @@ Meteor.methods<ServerMethods>({
}); });
await Promise.all(promises); await Promise.all(promises);
Livechat.logger.info(`User ${Meteor.userId()} removed ${promises.length} closed rooms`); logger.info(`User ${Meteor.userId()} removed ${promises.length} closed rooms`);
return promises.length; return promises.length;
}, },
}); });
import type { IUser } from '@rocket.chat/core-typings'; import type { IUser } from '@rocket.chat/core-typings';
import { ILivechatAgentStatus, isOmnichannelRoom } from '@rocket.chat/core-typings'; import { ILivechatAgentStatus, isOmnichannelRoom } from '@rocket.chat/core-typings';
import { Logger } from '@rocket.chat/logger';
import { LivechatRooms } from '@rocket.chat/models'; import { LivechatRooms } from '@rocket.chat/models';
import { Accounts } from 'meteor/accounts-base'; import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
...@@ -12,12 +13,13 @@ import { hasPermissionAsync } from '../../authorization/server/functions/hasPerm ...@@ -12,12 +13,13 @@ import { hasPermissionAsync } from '../../authorization/server/functions/hasPerm
import { settings } from '../../settings/server'; import { settings } from '../../settings/server';
import { businessHourManager } from './business-hour'; import { businessHourManager } from './business-hour';
import { createDefaultBusinessHourIfNotExists } from './business-hour/Helper'; import { createDefaultBusinessHourIfNotExists } from './business-hour/Helper';
import { Livechat } from './lib/Livechat';
import { Livechat as LivechatTyped } from './lib/LivechatTyped'; import { Livechat as LivechatTyped } from './lib/LivechatTyped';
import { RoutingManager } from './lib/RoutingManager'; import { RoutingManager } from './lib/RoutingManager';
import { LivechatAgentActivityMonitor } from './statistics/LivechatAgentActivityMonitor'; import { LivechatAgentActivityMonitor } from './statistics/LivechatAgentActivityMonitor';
import './roomAccessValidator.internalService'; import './roomAccessValidator.internalService';
const logger = new Logger('LivechatStartup');
Meteor.startup(async () => { Meteor.startup(async () => {
roomCoordinator.setRoomFind('l', (_id) => LivechatRooms.findOneById(_id)); roomCoordinator.setRoomFind('l', (_id) => LivechatRooms.findOneById(_id));
...@@ -63,7 +65,7 @@ Meteor.startup(async () => { ...@@ -63,7 +65,7 @@ Meteor.startup(async () => {
await createDefaultBusinessHourIfNotExists(); await createDefaultBusinessHourIfNotExists();
settings.watch<boolean>('Livechat_enable_business_hours', async (value) => { settings.watch<boolean>('Livechat_enable_business_hours', async (value) => {
Livechat.logger.info(`Changing business hour type to ${value}`); logger.info(`Changing business hour type to ${value}`);
if (value) { if (value) {
await businessHourManager.startManager(); await businessHourManager.startManager();
return; return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment