Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 1 addition & 9 deletions app/livechat/client/collections/LivechatInquiry.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import { Mongo } from 'meteor/mongo';

import { settings } from '../../../settings/client';

let collection;
export const getLivechatInquiryCollection = () => {
if (!collection) {
collection = new Mongo.Collection(settings.get('Livechat_enable_inquiry_fetch_by_stream') ? null : 'rocketchat_livechat_inquiry');
}
return collection;
};
export const LivechatInquiry = new Mongo.Collection(null);
17 changes: 9 additions & 8 deletions app/livechat/client/lib/stream/queueManager.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { APIClient } from '../../../../utils/client';
import { getLivechatInquiryCollection } from '../../collections/LivechatInquiry';
import { LivechatInquiry } from '../../collections/LivechatInquiry';
import { inquiryDataStream } from './inquiry';
import { hasRole } from '../../../../authorization/client';

let agentDepartments = [];
const collection = getLivechatInquiryCollection();

const events = {
added: (inquiry) => {
delete inquiry.type;
collection.insert(inquiry);
LivechatInquiry.insert(inquiry);
},
changed: (inquiry) => {
if (inquiry.status !== 'queued' || (inquiry.department && !agentDepartments.includes(inquiry.department))) {
return collection.remove(inquiry._id);
return LivechatInquiry.remove(inquiry._id);
}
delete inquiry.type;
collection.upsert({ _id: inquiry._id }, inquiry);
LivechatInquiry.upsert({ _id: inquiry._id }, inquiry);
},
removed: (inquiry) => collection.remove(inquiry._id),
removed: (inquiry) => LivechatInquiry.remove(inquiry._id),
};

const updateCollection = (inquiry) => { events[inquiry.type](inquiry); };
Expand All @@ -31,7 +30,7 @@ const getInquiriesFromAPI = async (url) => {
};

const updateInquiries = async (inquiries) => {
(inquiries || []).forEach((inquiry) => collection.upsert({ _id: inquiry._id }, inquiry));
(inquiries || []).forEach((inquiry) => LivechatInquiry.upsert({ _id: inquiry._id }, inquiry));
};

const getAgentsDepartments = async (userId) => {
Expand All @@ -54,12 +53,14 @@ const removeGlobalListener = () => {
};

export const initializeLivechatInquiryStream = async (userId) => {
collection.remove({});
LivechatInquiry.remove({});

if (agentDepartments.length) {
removeDepartmentsListeners(agentDepartments);
}
removeGlobalListener();
await updateInquiries(await getInquiriesFromAPI('livechat/inquiries.queued?sort={"ts": 1}'));

agentDepartments = (await getAgentsDepartments(userId)).map((department) => department.departmentId);
await addListenerForeachDepartment(userId, agentDepartments);
if (agentDepartments.length === 0 || hasRole(userId, 'livechat-manager')) {
Expand Down
11 changes: 4 additions & 7 deletions app/livechat/client/views/sideNav/livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { KonchatNotification } from '../../../../ui';
import { settings } from '../../../../settings';
import { hasPermission } from '../../../../authorization';
import { t, handleError, getUserPreference } from '../../../../utils';
import { getLivechatInquiryCollection } from '../../collections/LivechatInquiry';
import { LivechatInquiry } from '../../collections/LivechatInquiry';
import { Notifications } from '../../../../notifications/client';
import { initializeLivechatInquiryStream } from '../../lib/stream/queueManager';

Expand Down Expand Up @@ -50,7 +50,7 @@ Template.livechat.helpers({
},

inquiries() {
const inqs = getLivechatInquiryCollection().find({
const inqs = LivechatInquiry.find({
status: 'queued',
}, {
sort: {
Expand Down Expand Up @@ -131,11 +131,8 @@ Template.livechat.onCreated(function() {
this.statusLivechat.set();
}
});
if (!settings.get('Livechat_enable_inquiry_fetch_by_stream')) {
this.subscribe('livechat:inquiry');
} else {
initializeLivechatInquiryStream(Meteor.userId());
}

initializeLivechatInquiryStream(Meteor.userId());
this.updateAgentDepartments = () => initializeLivechatInquiryStream(Meteor.userId());
this.autorun(() => this.inquiriesLimit.set(settings.get('Livechat_guest_pool_max_number_incoming_livechats_displayed')));

Expand Down
8 changes: 4 additions & 4 deletions app/livechat/lib/LivechatRoomType.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { openRoom } from '../../ui-utils';
import { RoomSettingsEnum, UiTextContext, RoomTypeRouteConfig, RoomTypeConfig } from '../../utils';
import { getAvatarURL } from '../../utils/lib/getAvatarURL';

let getLivechatInquiryCollection;
let LivechatInquiry;
if (Meteor.isClient) {
({ getLivechatInquiryCollection } = require('../client/collections/LivechatInquiry'));
({ LivechatInquiry } = require('../client/collections/LivechatInquiry'));
}

class LivechatRoomRoute extends RoomTypeRouteConfig {
Expand Down Expand Up @@ -72,7 +72,7 @@ export default class LivechatRoomType extends RoomTypeConfig {
if (room) {
return room.v && room.v.status;
}
const inquiry = getLivechatInquiryCollection().findOne({ rid });
const inquiry = LivechatInquiry.findOne({ rid });
return inquiry && inquiry.v && inquiry.v.status;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ export default class LivechatRoomType extends RoomTypeConfig {
return true;
}

const inquiry = getLivechatInquiryCollection().findOne({ rid }, { fields: { status: 1 } });
const inquiry = LivechatInquiry.findOne({ rid }, { fields: { status: 1 } });
if (inquiry && inquiry.status === 'queued') {
return true;
}
Expand Down
9 changes: 0 additions & 9 deletions app/livechat/server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,4 @@ Meteor.startup(function() {
i18nLabel: 'How_long_to_wait_to_consider_visitor_abandonment',
i18nDescription: 'Time_in_seconds',
});

settings.add('Livechat_enable_inquiry_fetch_by_stream', true, {
type: 'boolean',
group: 'Omnichannel',
section: 'Routing',
public: true,
i18nLabel: 'Enable_inquiry_fetch_by_stream',
enableQuery: { _id: 'Livechat_Routing_Method', value: 'Manual_Selection' },
});
});
1 change: 1 addition & 0 deletions server/startup/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,5 @@ import './v174';
import './v175';
import './v176';
import './v177';
import './v178';
import './xrun';
14 changes: 14 additions & 0 deletions server/startup/migrations/v178.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {
Migrations,
} from '../../../app/migrations';
import {
Settings,
} from '../../../app/models';


Migrations.add({
version: 178,
up() {
Settings.remove({ _id: 'Livechat_enable_inquiry_fetch_by_stream' });
},
});