Skip to content

Commit

Permalink
Merge branch 'develop' into fix/inquiry-room-removal
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Oct 18, 2023
2 parents e8dfb9c + 049b921 commit 30d8089
Show file tree
Hide file tree
Showing 69 changed files with 701 additions and 594 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-pianos-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/presence': minor
---

Add peak connections monitoring and methods to get and reset the counter
5 changes: 5 additions & 0 deletions .changeset/rich-dogs-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

Fix typing indicator of Apps user
7 changes: 7 additions & 0 deletions .changeset/slow-coats-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@rocket.chat/meteor": minor
---

Add the daily and monthly peaks of concurrent connections to statistics
- Added `dailyPeakConnections` statistic for monitoring the daily peak of concurrent connections in a workspace;
- Added `maxMonthlyPeakConnections` statistic for monitoring the last 30 days peak of concurrent connections in a workspace;
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
7 changes: 4 additions & 3 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 Expand Up @@ -288,7 +289,7 @@ export class AppLivechatBridge extends LivechatBridge {
throw new Error('Could not get the message converter to process livechat room messages');
}

const livechatMessages = await Livechat.getRoomMessages({ rid: roomId });
const livechatMessages = await LivechatTyped.getRoomMessages({ rid: roomId });

return Promise.all(livechatMessages.map((message) => messageConverter.convertMessage(message) as Promise<IAppsEngineMesage>));
}
Expand Down
6 changes: 5 additions & 1 deletion apps/meteor/app/apps/server/bridges/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ export class AppMessageBridge extends MessageBridge {
protected async typing({ scope, id, username, isTyping }: ITypingDescriptor): Promise<void> {
switch (scope) {
case 'room':
notifications.notifyRoom(id, 'typing', username!, isTyping);
if (!username) {
throw new Error('Invalid username');
}

notifications.notifyRoom(id, 'user-activity', username, isTyping ? ['user-typing'] : []);
return;
default:
throw new Error('Unrecognized typing scope provided');
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/cas/server/cas_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Accounts.registerLoginHandler('cas', async (options) => {
if (roomName) {
let room = await Rooms.findOneByNameAndType(roomName, 'c');
if (!room) {
room = await createRoom('c', roomName, user.username);
room = await createRoom('c', roomName, user);
}
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async function handleJoinedChannel(args) {
let room = await Rooms.findOneByName(args.roomName);

if (!room) {
const createdRoom = await createRoom('c', args.roomName, user.username, []);
const createdRoom = await createRoom('c', args.roomName, user, []);
room = await Rooms.findOne({ _id: createdRoom.rid });

this.log(`${user.username} created room ${args.roomName}`);
Expand Down
10 changes: 4 additions & 6 deletions apps/meteor/app/livechat/imports/server/rest/departments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '../../../server/api/lib/departments';
import { DepartmentHelper } from '../../../server/lib/Departments';
import { Livechat } from '../../../server/lib/Livechat';
import { Livechat as LivechatTs } from '../../../server/lib/LivechatTyped';

API.v1.addRoute(
'livechat/department',
Expand Down Expand Up @@ -192,7 +193,7 @@ API.v1.addRoute(
},
{
async post() {
await Livechat.archiveDepartment(this.urlParams._id);
await LivechatTs.archiveDepartment(this.urlParams._id);

return API.v1.success();
},
Expand All @@ -207,11 +208,8 @@ API.v1.addRoute(
},
{
async post() {
if (await Livechat.unarchiveDepartment(this.urlParams._id)) {
return API.v1.success();
}

return API.v1.failure();
await LivechatTs.unarchiveDepartment(this.urlParams._id);
return API.v1.success();
},
},
);
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
27 changes: 18 additions & 9 deletions apps/meteor/app/livechat/server/api/v1/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { callbacks } from '../../../../../lib/callbacks';
import { i18n } from '../../../../../server/lib/i18n';
import { API } from '../../../../api/server';
import { isWidget } from '../../../../api/server/helpers/isWidget';
import { canAccessRoomAsync } from '../../../../authorization/server';
import { canAccessRoomAsync, roomAccessAttributes } from '../../../../authorization/server';
import { hasPermissionAsync } from '../../../../authorization/server/functions/hasPermission';
import { addUserToRoom } from '../../../../lib/server/functions/addUserToRoom';
import { settings as rcSettings } from '../../../../settings/server';
Expand Down 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 All @@ -352,7 +356,12 @@ API.v1.addRoute(

API.v1.addRoute(
'livechat/room.visitor',
{ authRequired: true, permissionsRequired: ['view-l-room'], validateParams: isPUTLivechatRoomVisitorParams, deprecationVersion: '7.0.0' },
{
authRequired: true,
permissionsRequired: ['change-livechat-room-visitor'],
validateParams: isPUTLivechatRoomVisitorParams,
deprecationVersion: '7.0.0',
},
{
async put() {
// This endpoint is deprecated and will be removed in future versions.
Expand All @@ -363,7 +372,7 @@ API.v1.addRoute(
throw new Error('invalid-visitor');
}

const room = await LivechatRooms.findOneById(rid, { _id: 1, v: 1 }); // TODO: check _id
const room = await LivechatRooms.findOneById(rid, { projection: { ...roomAccessAttributes, _id: 1, t: 1, v: 1 } }); // TODO: check _id
if (!room) {
throw new Error('invalid-room');
}
Expand All @@ -373,7 +382,7 @@ API.v1.addRoute(
throw new Error('invalid-room-visitor');
}

const roomAfterChange = await Livechat.changeRoomVisitor(this.userId, rid, visitor);
const roomAfterChange = await LivechatTyped.changeRoomVisitor(this.userId, room, visitor);

if (!roomAfterChange) {
return API.v1.failure();
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/api/v1/videoCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { i18n } from '../../../../../server/lib/i18n';
import { API } from '../../../../api/server';
import { canSendMessageAsync } from '../../../../authorization/server/functions/canSendMessage';
import { settings as rcSettings } from '../../../../settings/server';
import { Livechat } from '../../lib/Livechat';
import { Livechat } from '../../lib/LivechatTyped';
import { settings } from '../lib/livechat';

API.v1.addRoute(
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/api/v1/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ API.v1.addRoute('livechat/visitor.callStatus', {
if (!guest) {
throw new Meteor.Error('invalid-token');
}
await Livechat.updateCallStatus(callId, rid, callStatus, guest);
await LivechatTyped.updateCallStatus(callId, rid, callStatus, guest);
return API.v1.success({ token, callStatus });
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isOmnichannelRoom } from '@rocket.chat/core-typings';

import { callbacks } from '../../../../lib/callbacks';
import { Livechat } from '../lib/Livechat';
import { Livechat } from '../lib/LivechatTyped';

callbacks.add(
'livechat.newRoom',
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 30d8089

Please sign in to comment.