Skip to content

Commit

Permalink
Chore: use params instead of URL building on livechat endpoints (#25810)
Browse files Browse the repository at this point in the history
<!-- This is a pull request template, you do not need to uncomment or remove the comments, they won't show up in the PR text. -->

<!-- Your Pull Request name should start with one of the following tags
  [NEW] For new features
  [IMPROVE] For an improvement (performance or little improvements) in existing features
  [FIX] For bug fixes that affect the end-user
  [BREAK] For pull requests including breaking changes
  Chore: For small tasks
  Doc: For documentation
-->

<!-- Checklist!!! If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code. 
  - I have read the Contributing Guide - https://github.com/RocketChat/Rocket.Chat/blob/develop/.github/CONTRIBUTING.md#contributing-to-rocketchat doc
  - I have signed the CLA - https://cla-assistant.io/RocketChat/Rocket.Chat
  - Lint and unit tests pass locally with my changes
  - I have added tests that prove my fix is effective or that my feature works (if applicable)
  - I have added necessary documentation (if applicable)
  - Any dependent changes have been merged and published in downstream modules
-->

## Proposed changes (including videos or screenshots)
<!-- CHANGELOG -->
<!--
  Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.
  If it fixes a bug or resolves a feature request, be sure to link to that issue below.
  This description will appear in the release notes if we accept the contribution.
-->

<!-- END CHANGELOG -->

## Issue(s)
<!-- Link the issues being closed by or related to this PR. For example, you can use #594 if this PR closes issue number 594 -->

## Steps to test or reproduce
<!-- Mention how you would reproduce the bug if not mentioned on the issue page already. Also mention which screens are going to have the changes if applicable -->

## Further comments
<!-- If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... -->
  • Loading branch information
KevLehman authored Jun 9, 2022
1 parent c27412b commit 11a9d23
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/client/lib/stream/queueManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const updateInquiries = async (inquiries = []) =>
inquiries.forEach((inquiry) => LivechatInquiry.upsert({ _id: inquiry._id }, { ...inquiry, _updatedAt: new Date(inquiry._updatedAt) }));

const getAgentsDepartments = async (userId) => {
const { departments } = await APIClient.get(`/v1/livechat/agents/${userId}/departments?enabledDepartmentsOnly=true`);
const { departments } = await APIClient.get(`/v1/livechat/agents/${userId}/departments`, { enabledDepartmentsOnly: true });
return departments;
};

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/livechat/client/views/app/dialog/closeRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ Template.closeRoom.onCreated(async function () {
this.onEnterTag = () => this.invalidTags.set(!validateRoomTags(this.tagsRequired.get(), this.tags.get()));

const { rid } = Template.currentData();
const { room } = await APIClient.get(`/v1/rooms.info?roomId=${rid}`);
const { room } = await APIClient.get(`/v1/rooms.info`, { roomId: rid });
this.tags.set(room?.tags || []);

if (room?.departmentId) {
const { department } = await APIClient.get(`/v1/livechat/department/${room.departmentId}?includeAgents=false`);
const { department } = await APIClient.get(`/v1/livechat/department/${room.departmentId}`, { includeAgents: false });
this.tagsRequired.set(department?.requestTagBeforeClosingChat);
}

Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/app/livechat/client/views/app/livechatReadOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Template.livechatReadOnly.events({
event.stopPropagation();

try {
const { success } = (await APIClient.get(`/v1/livechat/room.join?roomId=${this.rid}`)) || {};
const { success } = (await APIClient.get(`/v1/livechat/room.join`, { roomId: this.rid })) || {};
if (!success) {
throw new Meteor.Error('error-join-room', 'Error joining room');
}
Expand Down Expand Up @@ -99,13 +99,13 @@ Template.livechatReadOnly.onCreated(async function () {

this.loadRoomAndInquiry = async (roomId) => {
this.preparing.set(true);
const { inquiry } = await APIClient.get(`/v1/livechat/inquiries.getOne?roomId=${roomId}`);
const { inquiry } = await APIClient.get(`/v1/livechat/inquiries.getOne`, { roomId });
this.inquiry.set(inquiry);
if (inquiry && inquiry._id) {
inquiryDataStream.on(inquiry._id, this.updateInquiry);
}

const { room } = await APIClient.get(`/v1/rooms.info?roomId=${roomId}`);
const { room } = await APIClient.get(`/v1/rooms.info`, { roomId });
this.room.set(room);
if (room && room._id) {
RoomManager.roomStream.on(roomId, (room) => this.room.set(room));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,24 @@ Template.contactChatHistory.onCreated(async function () {
const offset = this.offset.get();
const searchTerm = this.searchTerm.get();

let baseUrl = `/v1/livechat/visitors.searchChats/room/${
currentData.rid
}/visitor/${this.visitorId.get()}?count=${limit}&offset=${offset}&closedChatsOnly=true&servedChatsOnly=true`;
if (searchTerm) {
baseUrl += `&searchText=${searchTerm}`;
}
const baseUrl = `/v1/livechat/visitors.searchChats/room/${currentData.rid}/visitor/${this.visitorId.get()}`;
const params = {
count: limit,
offset,
closedChatsOnly: true,
servedChatsOnly: true,
...(searchTerm && { searchText: searchTerm }),
};

this.isLoading.set(true);
const { history, total } = await APIClient.get(baseUrl);
const { history, total } = await APIClient.get(baseUrl, params);
this.history.set(offset === 0 ? history : this.history.get().concat(history));
this.hasMore.set(total > this.history.get().length);
this.isLoading.set(false);
});

this.autorun(async () => {
const { room } = await APIClient.get(`/v1/rooms.info?roomId=${currentData.rid}`);
const { room } = await APIClient.get(`/v1/rooms.info`, { roomId: currentData.rid });
if (room?.v) {
this.visitorId.set(room.v._id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { APIClient } from '../../../utils/client';

Template.authorize.onCreated(async function () {
this.oauthApp = new ReactiveVar({});
const { oauthApp } = await APIClient.get(`/v1/oauth-apps.get?clientId=${this.data.client_id()}`);
const { oauthApp } = await APIClient.get(`/v1/oauth-apps.get`, { clientId: this.data.client_id() });
this.oauthApp.set(oauthApp);
});

Expand Down

0 comments on commit 11a9d23

Please sign in to comment.