Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into fix/…
Browse files Browse the repository at this point in the history
…chat.postMessage

* 'develop' of github.com:RocketChat/Rocket.Chat:
  fix: inconsistent behavior when removing subscriptions and inquiries (#30572)
  fix: Handle AWS S3 Re-Authentication via s3.getSignedUrlPromise (#30642)
  test: wait for the name update finish (#30663)
  regression: Restore default limits to community apps (#30611)
  refactor: Move functions out of `Livechat.js` (#30650)
  chore: remove license v3 public key envvar (#30646)
  fix: Read receipts are not created on the first time a user reads a room (#30610)
  fix: licenses.info endpoint only available for admins (#30644)
  • Loading branch information
gabriellsh committed Oct 18, 2023
2 parents 15c06df + e24d071 commit 4a9f0d7
Show file tree
Hide file tree
Showing 32 changed files with 396 additions and 403 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-cars-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed intermittent errors caused by the removal of subscriptions and inquiries when lacking permissions.
5 changes: 5 additions & 0 deletions .changeset/weak-cameras-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed issue with message read receipts not being created when accessing a room the first time
5 changes: 3 additions & 2 deletions apps/meteor/app/apps/server/bridges/livechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export class AppLivechatBridge extends LivechatBridge {
message: await this.orch.getConverters()?.get('messages').convertAppMessage(message),
};

await Livechat.updateMessage(data);
// @ts-expect-error IVisitor vs ILivechatVisitor :(
await LivechatTyped.updateMessage(data);
}

protected async createRoom(visitor: IVisitor, agent: IUser, appId: string, extraParams?: IExtraRoomParams): Promise<ILivechatRoom> {
Expand Down Expand Up @@ -208,7 +209,7 @@ export class AppLivechatBridge extends LivechatBridge {
userId = transferredTo._id;
}

return Livechat.transfer(
return LivechatTyped.transfer(
await this.orch.getConverters()?.get('rooms').convertAppRoom(currentRoom),
this.orch.getConverters()?.get('visitors').convertAppVisitor(visitor),
{ userId, departmentId, transferredBy, transferredTo },
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/file-upload/ufs/AmazonS3/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class AmazonS3Store extends UploadFS.Store {
ResponseContentDisposition: `${forceDownload ? 'attachment' : 'inline'}; filename="${encodeURI(file.name || '')}"`,
};

return s3.getSignedUrl('getObject', params);
return s3.getSignedUrlPromise('getObject', params);
};

/**
Expand Down
26 changes: 21 additions & 5 deletions apps/meteor/app/livechat/client/lib/stream/queueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,34 @@ import { LivechatInquiry } from '../../collections/LivechatInquiry';
const departments = new Set();

const events = {
added: (inquiry: ILivechatInquiryRecord) => {
departments.has(inquiry.department) && LivechatInquiry.insert({ ...inquiry, alert: true, _updatedAt: new Date(inquiry._updatedAt) });
added: async (inquiry: ILivechatInquiryRecord) => {
if (!departments.has(inquiry.department)) {
return;
}

LivechatInquiry.insert({ ...inquiry, alert: true, _updatedAt: new Date(inquiry._updatedAt) });
await invalidateRoomQueries(inquiry.rid);
},
changed: async (inquiry: ILivechatInquiryRecord) => {
if (inquiry.status !== 'queued' || (inquiry.department && !departments.has(inquiry.department))) {
return LivechatInquiry.remove(inquiry._id);
return removeInquiry(inquiry);
}

LivechatInquiry.upsert({ _id: inquiry._id }, { ...inquiry, alert: true, _updatedAt: new Date(inquiry._updatedAt) });
await queryClient.invalidateQueries(['/v1/rooms.info', inquiry.rid]);
await invalidateRoomQueries(inquiry.rid);
},
removed: (inquiry: ILivechatInquiryRecord) => LivechatInquiry.remove(inquiry._id),
removed: (inquiry: ILivechatInquiryRecord) => removeInquiry(inquiry),
};

const invalidateRoomQueries = async (rid: string) => {
await queryClient.invalidateQueries(['rooms', { reference: rid, type: 'l' }]);
await queryClient.removeQueries(['rooms', rid]);
await queryClient.removeQueries(['/v1/rooms.info', rid]);
};

const removeInquiry = async (inquiry: ILivechatInquiryRecord) => {
await LivechatInquiry.remove(inquiry._id);
return queryClient.invalidateQueries(['rooms', { reference: inquiry.rid, type: 'l' }]);
};

const getInquiriesFromAPI = async () => {
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/app/livechat/server/api/lib/livechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Meteor } from 'meteor/meteor';
import { callbacks } from '../../../../../lib/callbacks';
import { i18n } from '../../../../../server/lib/i18n';
import { normalizeAgent } from '../../lib/Helper';
import { Livechat } from '../../lib/Livechat';
import { Livechat as LivechatTyped } from '../../lib/LivechatTyped';

export function online(department: string, skipSettingCheck = false, skipFallbackCheck = false): Promise<boolean> {
Expand Down Expand Up @@ -139,7 +138,7 @@ export function normalizeHttpHeaderData(headers: Record<string, string | string[

export async function settings({ businessUnit = '' }: { businessUnit?: string } = {}): Promise<Record<string, string | number | any>> {
// Putting this ugly conversion while we type the livechat service
const initSettings = (await Livechat.getInitSettings()) as unknown as Record<string, string | number | any>;
const initSettings = await LivechatTyped.getInitSettings();
const triggers = await findTriggers();
const departments = await findDepartments(businessUnit);
const sound = `${Meteor.absoluteUrl()}sounds/chime.mp3`;
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/livechat/server/api/v1/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ API.v1.addRoute(
throw new Error('invalid-message');
}

const result = await Livechat.updateMessage({
const result = await LivechatTyped.updateMessage({
guest,
message: { _id: msg._id, msg: this.bodyParams.msg },
message: { _id: msg._id, msg: this.bodyParams.msg, rid: msg.rid },
});
if (!result) {
return API.v1.failure();
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/api/v1/offlineMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isPOSTLivechatOfflineMessageParams } from '@rocket.chat/rest-typings';

import { i18n } from '../../../../../server/lib/i18n';
import { API } from '../../../../api/server';
import { Livechat } from '../../lib/Livechat';
import { Livechat } from '../../lib/LivechatTyped';

API.v1.addRoute(
'livechat/offline.message',
Expand Down
14 changes: 9 additions & 5 deletions apps/meteor/app/livechat/server/api/v1/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ API.v1.addRoute(
const { _id, username, name } = guest;
const transferredBy = normalizeTransferredByData({ _id, username, name, userType: 'visitor' }, room);

if (!(await Livechat.transfer(room, guest, { roomId: rid, departmentId: department, transferredBy }))) {
if (!(await LivechatTyped.transfer(room, guest, { departmentId: department, transferredBy }))) {
return API.v1.failure();
}

Expand Down Expand Up @@ -312,10 +312,10 @@ API.v1.addRoute(
{ authRequired: true, permissionsRequired: ['view-l-room', 'transfer-livechat-guest'], validateParams: isLiveChatRoomForwardProps },
{
async post() {
const transferData: typeof this.bodyParams & {
transferredBy?: unknown;
const transferData = this.bodyParams as typeof this.bodyParams & {
transferredBy: TransferByData;
transferredTo?: { _id: string; username?: string; name?: string };
} = this.bodyParams;
};

const room = await LivechatRooms.findOneById(this.bodyParams.roomId);
if (!room || room.t !== 'l') {
Expand All @@ -327,6 +327,10 @@ API.v1.addRoute(
}

const guest = await LivechatVisitors.findOneEnabledById(room.v?._id);
if (!guest) {
throw new Error('error-invalid-visitor');
}

const transferedBy = this.user satisfies TransferByData;
transferData.transferredBy = normalizeTransferredByData(transferedBy, room);
if (transferData.userId) {
Expand All @@ -340,7 +344,7 @@ API.v1.addRoute(
}
}

const chatForwardedResult = await Livechat.transfer(room, guest, transferData);
const chatForwardedResult = await LivechatTyped.transfer(room, guest, transferData);
if (!chatForwardedResult) {
throw new Error('error-forwarding-chat');
}
Expand Down
3 changes: 3 additions & 0 deletions apps/meteor/app/livechat/server/lib/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ export const forwardRoomToAgent = async (room: IOmnichannelRoom, transferData: T
logger.debug(`Forwarding room ${room._id} to agent ${transferData.userId}`);

const { userId: agentId, clientAction } = transferData;
if (!agentId) {
throw new Error('error-invalid-agent');
}
const user = await Users.findOneOnlineAgentById(agentId);
if (!user) {
logger.debug(`Agent ${agentId} is offline. Cannot forward`);
Expand Down
Loading

0 comments on commit 4a9f0d7

Please sign in to comment.