Skip to content

Commit

Permalink
fix: inquiries being limited to 50 items (#31267)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva authored and sampaiodiego committed Jan 2, 2024
1 parent a075950 commit 84c4b07
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-moles-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed conversations in queue being limited to 50 items
16 changes: 11 additions & 5 deletions apps/meteor/app/livechat/client/lib/stream/queueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ILivechatDepartment, ILivechatInquiryRecord, IOmnichannelAgent } f

import { queryClient } from '../../../../../client/lib/queryClient';
import { callWithErrorHandling } from '../../../../../client/lib/utils/callWithErrorHandling';
import { settings } from '../../../../settings/client';
import { sdk } from '../../../../utils/client/lib/SDKClient';
import { LivechatInquiry } from '../../collections/LivechatInquiry';

Expand Down Expand Up @@ -39,7 +40,8 @@ const removeInquiry = async (inquiry: ILivechatInquiryRecord) => {
};

const getInquiriesFromAPI = async () => {
const { inquiries } = await sdk.rest.get('/v1/livechat/inquiries.queuedForUser', {});
const count = settings.get('Livechat_guest_pool_max_number_incoming_livechats_displayed') ?? 0;
const { inquiries } = await sdk.rest.get('/v1/livechat/inquiries.queuedForUser', { count });
return inquiries;
};

Expand Down Expand Up @@ -96,24 +98,28 @@ const subscribe = async (userId: IOmnichannelAgent['_id']) => {
// Register to all depts + public queue always to match the inquiry list returned by backend
const cleanDepartmentListeners = addListenerForeachDepartment(agentDepartments);
const globalCleanup = addGlobalListener();
const inquiriesFromAPI = (await getInquiriesFromAPI()) as unknown as ILivechatInquiryRecord[];

await updateInquiries(inquiriesFromAPI);
const computation = Tracker.autorun(async () => {
const inquiriesFromAPI = (await getInquiriesFromAPI()) as unknown as ILivechatInquiryRecord[];

await updateInquiries(inquiriesFromAPI);
});

return () => {
LivechatInquiry.remove({});
removeGlobalListener();
cleanDepartmentListeners?.();
globalCleanup?.();
departments.clear();
computation.stop();
};
};

export const initializeLivechatInquiryStream = (() => {
let cleanUp: (() => void) | undefined;

return async (...args: any[]) => {
return async (...args: Parameters<typeof subscribe>) => {
cleanUp?.();
cleanUp = await subscribe(...(args as [IOmnichannelAgent['_id']]));
cleanUp = await subscribe(...args);
};
})();
9 changes: 3 additions & 6 deletions apps/meteor/client/providers/OmnichannelProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const OmnichannelProvider: FC = ({ children }) => {
const omniChannelEnabled = useSetting('Livechat_enabled') as boolean;
const omnichannelRouting = useSetting('Livechat_Routing_Method');
const showOmnichannelQueueLink = useSetting('Livechat_show_queue_list_link') as boolean;
const omnichannelPoolMaxIncoming = useSetting('Livechat_guest_pool_max_number_incoming_livechats_displayed') as number;
const omnichannelPoolMaxIncoming = useSetting<number>('Livechat_guest_pool_max_number_incoming_livechats_displayed') ?? 0;
const omnichannelSortingMechanism = useSetting('Omnichannel_sorting_mechanism') as OmnichannelSortingMechanismSettingType;

const loggerRef = useRef(new ClientLogger('OmnichannelProvider'));
Expand Down Expand Up @@ -130,16 +130,13 @@ const OmnichannelProvider: FC = ({ children }) => {
}

return LivechatInquiry.find(
{
status: 'queued',
$or: [{ defaultAgent: { $exists: false } }, { 'defaultAgent.agentId': user?._id }],
},
{ status: 'queued' },
{
sort: getOmniChatSortQuery(omnichannelSortingMechanism),
limit: omnichannelPoolMaxIncoming,
},
).fetch();
}, [manuallySelected, omnichannelPoolMaxIncoming, omnichannelSortingMechanism, user?._id]),
}, [manuallySelected, omnichannelPoolMaxIncoming, omnichannelSortingMechanism]),
);

queue?.map(({ rid }) => {
Expand Down

0 comments on commit 84c4b07

Please sign in to comment.