Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Agents (with user status offline & omni-status as available) not able to take or forward chat #26575

Merged
merged 12 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/meteor/app/livechat/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ Meteor.startup(function () {
type: 'boolean',
group: 'Omnichannel',
i18nLabel: 'Accept_new_livechats_when_agent_is_idle',
public: true,
enableQuery: omnichannelEnabledQuery,
});

Expand Down
15 changes: 0 additions & 15 deletions apps/meteor/app/livechat/server/lib/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,21 +562,6 @@ export const checkServiceStatus = ({ guest, agent }) => {
return users && users.count() > 0;
};

export const userCanTakeInquiry = (user) => {
check(
user,
Match.ObjectIncluding({
status: String,
statusLivechat: String,
roles: [String],
}),
);

const { roles, status, statusLivechat } = user;
// TODO: hasRole when the user has already been fetched from DB
return (status !== 'offline' && statusLivechat === 'available') || roles.includes('bot');
};

export const updateDepartmentAgents = (departmentId, agents, departmentEnabled) => {
check(departmentId, String);
check(
Expand Down
5 changes: 2 additions & 3 deletions apps/meteor/app/livechat/server/methods/takeInquiry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Meteor } from 'meteor/meteor';
import { hasPermission } from '../../../authorization';
import { Users, LivechatInquiry } from '../../../models/server';
import { RoutingManager } from '../lib/RoutingManager';
import { userCanTakeInquiry } from '../lib/Helper';

Meteor.methods({
'livechat:takeInquiry'(inquiryId, options) {
Expand All @@ -21,10 +20,10 @@ Meteor.methods({
});
}

const user = Users.findOneById(Meteor.userId(), {
const user = Users.findOneOnlineAgentById(Meteor.userId(), {
fields: { _id: 1, username: 1, roles: 1, status: 1, statusLivechat: 1 },
});
if (!userCanTakeInquiry(user)) {
if (!user) {
throw new Meteor.Error('error-agent-status-service-offline', 'Agent status is offline or Omnichannel service is not active', {
method: 'livechat:takeInquiry',
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IOmnichannelRoom } from '@rocket.chat/core-typings';
import { Field, Button, TextAreaInput, Modal, Box, PaginatedSelectFiltered } from '@rocket.chat/fuselage';
import { useDebouncedValue } from '@rocket.chat/fuselage-hooks';
import { useEndpoint, useTranslation } from '@rocket.chat/ui-contexts';
import { useEndpoint, useSetting, useTranslation } from '@rocket.chat/ui-contexts';
import React, { ReactElement, useCallback, useEffect, useMemo, useState } from 'react';
import { useForm } from 'react-hook-form';

Expand All @@ -23,6 +23,7 @@ const ForwardChatModal = ({
}): ReactElement => {
const t = useTranslation();
const getUserData = useEndpoint('GET', '/v1/users.info');
const idleAgentsAllowedForForwarding = useSetting('Livechat_enabled_when_agent_idle') as boolean;

const { getValues, handleSubmit, register, setFocus, setValue, watch } = useForm();

Expand All @@ -43,7 +44,26 @@ const ForwardChatModal = ({
const hasDepartments = useMemo(() => departments && departments.length > 0, [departments]);

const _id = { $ne: room.servedBy?._id };
const conditions = { _id, status: { $ne: 'offline' }, statusLivechat: 'available' };
const conditions = {
_id,
...(!idleAgentsAllowedForForwarding && {
$or: [
{
status: {
$exists: true,
$ne: 'offline',
},
roles: {
$ne: 'bot',
},
},
{
roles: 'bot',
},
],
}),
statusLivechat: 'available',
};

const endReached = useCallback(
(start) => {
Expand Down