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

chore: Callback smol fixes (#29942)

parent 69447e18
No related branches found
No related tags found
No related merge requests found
import type { ILivechatDepartment } from '@rocket.chat/core-typings';
import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import { LivechatDepartment, Users, Rooms } from '@rocket.chat/models';
......@@ -17,9 +18,12 @@ callbacks.add(
let departmentName;
const { name, email, department, message: text, host } = data;
if (department && department !== '') {
const dept = await LivechatDepartment.findOneById(department, {
projection: { name: 1, offlineMessageChannelName: 1 },
});
const dept = await LivechatDepartment.findOneById<Pick<ILivechatDepartment, '_id' | 'name' | 'offlineMessageChannelName'>>(
department,
{
projection: { name: 1, offlineMessageChannelName: 1 },
},
);
departmentName = dept?.name;
if (dept?.offlineMessageChannelName) {
channelName = dept.offlineMessageChannelName;
......@@ -30,7 +34,7 @@ callbacks.add(
return data;
}
const room: any = await Rooms.findOneByName(channelName, { projection: { t: 1, archived: 1 } });
const room = await Rooms.findOneByName(channelName, { projection: { t: 1, archived: 1 } });
if (!room || room.archived || (isOmnichannelRoom(room) && room.closedAt)) {
return data;
}
......
......@@ -8,12 +8,12 @@ import { callbackLogger } from '../lib/logger';
callbacks.add(
'afterSaveMessage',
async (message, room) => {
callbackLogger.debug(`Calculating Omnichannel metrics for room ${room._id}`);
// check if room is livechat
if (!isOmnichannelRoom(room)) {
return message;
}
callbackLogger.debug(`Calculating Omnichannel metrics for room ${room._id}`);
// skips this callback if the message was edited
if (!message || isEditedMessage(message)) {
return message;
......
......@@ -12,10 +12,11 @@ callbacks.add(
if (message.t) {
return message;
}
if (message.token) {
await LivechatRooms.setVisitorLastMessageTimestampByRoomId(room._id, message.ts);
if (!message.token) {
return message;
}
return message;
await LivechatRooms.setVisitorLastMessageTimestampByRoomId(room._id, message.ts);
},
callbacks.priority.HIGH,
'save-last-visitor-message-timestamp',
......
import type { IOmnichannelRoom } from '@rocket.chat/core-typings';
import { LivechatRooms, LivechatDepartment } from '@rocket.chat/models';
import { callbacks } from '../../../../../lib/callbacks';
......@@ -8,7 +9,9 @@ callbacks.add(
async (options) => {
const { rid, newDepartmentId } = options;
const room = await LivechatRooms.findOneById(rid);
const room = await LivechatRooms.findOneById<Pick<IOmnichannelRoom, '_id' | 'departmentAncestors'>>(rid, {
projection: { departmentAncestors: 1 },
});
if (!room) {
cbLogger.debug('Skipping callback. No room found');
return options;
......
......@@ -15,9 +15,6 @@ const afterRemoveDepartment = async (options: { department: ILivechatDepartmentR
cbLogger.debug(`Removing department from forward list: ${department._id}`);
await LivechatDepartment.removeDepartmentFromForwardListById(department._id);
cbLogger.debug(`Removed department from forward list: ${department._id}`);
cbLogger.debug(`Post-department-removal actions completed in EE: ${department._id}`);
return options;
};
......
......@@ -28,9 +28,12 @@ const onTransferFailure = async (
return false;
}
const department = (await LivechatDepartment.findOneById(departmentId, {
projection: { _id: 1, name: 1, fallbackForwardDepartment: 1 },
})) as Partial<ILivechatDepartment>;
const department = await LivechatDepartment.findOneById<Pick<ILivechatDepartment, 'name' | '_id' | 'fallbackForwardDepartment'>>(
departmentId,
{
projection: { _id: 1, name: 1, fallbackForwardDepartment: 1 },
},
);
if (!department?.fallbackForwardDepartment?.length) {
return false;
......
......@@ -7,6 +7,10 @@ import { setPredictedVisitorAbandonmentTime } from '../lib/Helper';
callbacks.add(
'afterSaveMessage',
async (message, room) => {
if (!isOmnichannelRoom(room)) {
return message;
}
if (
!settings.get('Livechat_abandoned_rooms_action') ||
settings.get('Livechat_abandoned_rooms_action') === 'none' ||
......@@ -19,12 +23,8 @@ callbacks.add(
return message;
}
if (!isOmnichannelRoom(room)) {
return message;
}
// message valid only if it is a livechat room
if (!(typeof room.t !== 'undefined' && room.t === 'l' && room.v && room.v.token)) {
if (!room.v?.token) {
return message;
}
// if the message has a type means it is a special message (like the closing comment), so skip it
......
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