Skip to content

Commit

Permalink
Merge branch 'develop' into gsoc-livechat-2FA-feature-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
murtaza98 authored Aug 25, 2023
2 parents 1f6b4ba + 3b37fe5 commit 91b924e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 20 deletions.
12 changes: 8 additions & 4 deletions apps/meteor/app/livechat/server/hooks/offlineMessageToChannel.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ILivechatDepartment } from '@rocket.chat/core-typings';
import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import { LivechatDepartment, Users, Rooms } from '@rocket.chat/models';

Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/hooks/saveAnalyticsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { IOmnichannelRoom } from '@rocket.chat/core-typings';
import { LivechatRooms, LivechatDepartment } from '@rocket.chat/models';

import { callbacks } from '../../../../../lib/callbacks';
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' ||
Expand All @@ -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
Expand Down

0 comments on commit 91b924e

Please sign in to comment.