Skip to content

Commit

Permalink
Merge branch 'develop' into feat/manage-subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocostadev authored Oct 17, 2023
2 parents a86f99b + 85ddfb2 commit 00d3c29
Show file tree
Hide file tree
Showing 38 changed files with 333 additions and 171 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;
2 changes: 1 addition & 1 deletion apps/meteor/app/apps/server/bridges/livechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,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
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
13 changes: 9 additions & 4 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 @@ -352,7 +352,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 +368,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 +378,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
125 changes: 1 addition & 124 deletions apps/meteor/app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import dns from 'dns';
import util from 'util';

import { Message, VideoConf, api } from '@rocket.chat/core-services';
import { Message } from '@rocket.chat/core-services';
import { Logger } from '@rocket.chat/logger';
import {
LivechatVisitors,
Expand All @@ -30,7 +30,6 @@ import { trim } from '../../../../lib/utils/stringUtils';
import { i18n } from '../../../../server/lib/i18n';
import { addUserRolesAsync } from '../../../../server/lib/roles/addUserRoles';
import { removeUserFromRolesAsync } from '../../../../server/lib/roles/removeUserFromRoles';
import { canAccessRoomAsync, roomAccessAttributes } from '../../../authorization/server';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { FileUpload } from '../../../file-upload/server';
import { deleteMessage } from '../../../lib/server/functions/deleteMessage';
Expand Down Expand Up @@ -718,40 +717,6 @@ export const Livechat = {
return ret;
},

async unarchiveDepartment(_id) {
check(_id, String);

const department = await LivechatDepartmentRaw.findOneById(_id, { projection: { _id: 1 } });

if (!department) {
throw new Meteor.Error('department-not-found', 'Department not found', {
method: 'livechat:removeDepartment',
});
}

// TODO: these kind of actions should be on events instead of here
await LivechatDepartmentAgents.enableAgentsByDepartmentId(_id);
return LivechatDepartmentRaw.unarchiveDepartment(_id);
},

async archiveDepartment(_id) {
check(_id, String);

const department = await LivechatDepartmentRaw.findOneById(_id, { projection: { _id: 1 } });

if (!department) {
throw new Meteor.Error('department-not-found', 'Department not found', {
method: 'livechat:removeDepartment',
});
}

await LivechatDepartmentAgents.disableAgentsByDepartmentId(_id);
await LivechatDepartmentRaw.archiveDepartment(_id);

this.logger.debug({ msg: 'Running livechat.afterDepartmentArchived callback for department:', departmentId: _id });
await callbacks.run('livechat.afterDepartmentArchived', department);
},

showConnecting() {
const { showConnecting } = RoutingManager.getConfig();
return showConnecting;
Expand All @@ -767,28 +732,6 @@ export const Livechat = {
});
},

async getRoomMessages({ rid }) {
check(rid, String);

const room = await Rooms.findOneById(rid, { projection: { t: 1 } });
if (room?.t !== 'l') {
throw new Meteor.Error('invalid-room');
}

const ignoredMessageTypes = [
'livechat_navigation_history',
'livechat_transcript_history',
'command',
'livechat-close',
'livechat-started',
'livechat_video_call',
];

return Messages.findVisibleByRoomIdNotContainingTypes(rid, ignoredMessageTypes, {
sort: { ts: 1 },
}).toArray();
},

async requestTranscript({ rid, email, subject, user }) {
check(rid, String);
check(email, String);
Expand Down Expand Up @@ -892,77 +835,11 @@ export const Livechat = {
});
},

async notifyAgentStatusChanged(userId, status) {
callbacks.runAsync('livechat.agentStatusChanged', { userId, status });
if (!settings.get('Livechat_show_agent_info')) {
return;
}

await LivechatRooms.findOpenByAgent(userId).forEach((room) => {
void api.broadcast('omnichannel.room', room._id, {
type: 'agentStatus',
status,
});
});
},

async allowAgentChangeServiceStatus(statusLivechat, agentId) {
if (statusLivechat !== 'available') {
return true;
}

return businessHourManager.allowAgentChangeServiceStatus(agentId);
},

notifyRoomVisitorChange(roomId, visitor) {
void api.broadcast('omnichannel.room', roomId, {
type: 'visitorData',
visitor,
});
},

async changeRoomVisitor(userId, roomId, visitor) {
const user = await Users.findOneById(userId);
if (!user) {
throw new Error('error-user-not-found');
}

if (!(await hasPermissionAsync(userId, 'change-livechat-room-visitor'))) {
throw new Error('error-not-authorized');
}

const room = await LivechatRooms.findOneById(roomId, { ...roomAccessAttributes, _id: 1, t: 1 });

if (!room) {
throw new Meteor.Error('invalid-room');
}

if (!(await canAccessRoomAsync(room, user))) {
throw new Error('error-not-allowed');
}

await LivechatRooms.changeVisitorByRoomId(room._id, visitor);

Livechat.notifyRoomVisitorChange(room._id, visitor);

return LivechatRooms.findOneById(roomId);
},
async updateLastChat(contactId, lastChat) {
const updateUser = {
$set: {
lastChat,
},
};
await LivechatVisitors.updateById(contactId, updateUser);
},
async updateCallStatus(callId, rid, status, user) {
await Rooms.setCallStatus(rid, status);
if (status === 'ended' || status === 'declined') {
if (await VideoConf.declineLivechatCall(callId)) {
return;
}

return updateMessage({ _id: callId, msg: status, actionLinks: [], webRtcCallEndTs: new Date() }, user);
}
},
};
Loading

0 comments on commit 00d3c29

Please sign in to comment.