Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/livechat/client/views/app/livechatReadOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { inquiryDataStream } from '../../lib/stream/inquiry';
Template.livechatReadOnly.helpers({
inquiryOpen() {
const inquiry = Template.instance().inquiry.get();
const room = Template.instance().room.get();
return (inquiry && inquiry.status === 'queued') || !room.servedBy;
return inquiry && inquiry.status === 'queued';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gotta say: this works. this won't solve other room-related issues when some room props are updated (like room's name/visibility) but will solve our use case so we should be fine for now.

I'll create a task to address the bigger one.

},

roomOpen() {
Expand Down
4 changes: 2 additions & 2 deletions app/livechat/lib/LivechatRoomType.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class LivechatRoomType extends RoomTypeConfig {
}
}

readOnly(rid) {
readOnly(rid, user) {
const room = ChatRoom.findOne({ _id: rid }, { fields: { open: 1, servedBy: 1 } });
if (!room || !room.open) {
return true;
Expand All @@ -111,7 +111,7 @@ export default class LivechatRoomType extends RoomTypeConfig {
return true;
}

return !room.servedBy;
return (!room.servedBy || room.servedBy._id !== user._id) && !hasPermission('view-livechat-rooms');
}

getAvatarPath(roomData) {
Expand Down
2 changes: 1 addition & 1 deletion app/livechat/server/methods/takeInquiry.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Meteor.methods({
fields: { _id: 1, username: 1, roles: 1, status: 1, statusLivechat: 1 },
});
if (!userCanTakeInquiry(user)) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
throw new Meteor.Error('error-not-allowed-due-to-offline', `Not allowed since user's status is offline`, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it true that the only reason for not being able to take the inquiry is because the user is offline? 👀

method: 'livechat:takeInquiry',
});
}
Expand Down
19 changes: 18 additions & 1 deletion app/livechat/server/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Accounts } from 'meteor/accounts-base';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';

import { roomTypes } from '../../utils';
import { LivechatRooms } from '../../models';
import { LivechatRooms, LivechatInquiry } from '../../models/server';
import { callbacks } from '../../../lib/callbacks';
import { settings } from '../../settings/server';
import { LivechatAgentActivityMonitor } from './statistics/LivechatAgentActivityMonitor';
Expand Down Expand Up @@ -49,6 +49,23 @@ Meteor.startup(async () => {
'cant-join-room',
);

callbacks.add(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do this callback needs to be inside a Meteor.startup? Can be on its own ts file and imported on this one? 👀
Additionally, can you add this callback signature to the callback types? (on lib/callbacks.ts)

'beforeJoinRoom',
function (user, room) {
if (room.t === 'l' && !room.servedBy) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You can use the isOmnichannelRoom function to check if the room is an omnichannel room.
  2. Change the sense of the if so that if the room is not livechat or the room is already assigned you return the user, so the code can be unnested

const inquiry = LivechatInquiry.findOneByRoomId(room._id);
if (!inquiry) {
throw new Meteor.Error('error-invalid-inquiry', `Error: No inquiry found connected to room with id: ${room._id}`);
}
Meteor.runAsUser(user._id, () => Meteor.call('livechat:takeInquiry', inquiry._id));
}

return user;
},
callbacks.priority.HIGH,
'auto-assign-managers-to-livechat-rooms-if-no-one-is-assigned-to-chat',
);

const monitor = new LivechatAgentActivityMonitor();

let TroubleshootDisableLivechatActivityMonitor;
Expand Down
7 changes: 4 additions & 3 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,7 @@
"error-no-agents-online-in-department": "No agents online in the department",
"error-no-message-for-unread": "There are no messages to mark unread",
"error-not-allowed": "Not allowed",
"error-not-allowed-due-to-offline": "Not allowed since user's status is offline",
"error-not-authorized": "Not authorized",
"error-office-hours-are-closed": "The office hours are closed.",
"error-password-in-history": "Entered password has been previously used",
Expand Down Expand Up @@ -2942,9 +2943,9 @@
"Message_HideType_ujt": "Hide \"User Joined Team\" messages",
"Message_HideType_ul": "Hide \"User Leave\" messages",
"Message_HideType_ult": "Hide \"User Left Team\" messages",
"Message_HideType_user_added_room_to_team": "Hide \"User Added Room to Team\" messages",
"Message_HideType_user_added_room_to_team": "Hide \"User Added Room to Team\" messages",
"Message_HideType_user_converted_to_channel": "Hide \"User converted team to a Channel\" messages",
"Message_HideType_user_converted_to_team": "Hide \"User converted channel to a Team\" messages",
"Message_HideType_user_converted_to_team": "Hide \"User converted channel to a Team\" messages",
"Message_HideType_user_deleted_room_from_team": "Hide \"User deleted room from Team\" messages",
"Message_HideType_user_removed_room_from_team": "Hide \"User removed room from Team\" messages",
"Message_HideType_ut": "Hide \"User Joined Conversation\" messages",
Expand Down Expand Up @@ -4875,4 +4876,4 @@
"onboarding.form.standaloneServerForm.servicesUnavailable": "Some of the services will be unavailable or will require manual setup",
"onboarding.form.standaloneServerForm.publishOwnApp": "In order to send push notitications you need to compile and publish your own app to Google Play and App Store",
"onboarding.form.standaloneServerForm.manuallyIntegrate": "Need to manually integrate with external services"
}
}