Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] LiveChat switch department not working #11011

Merged
merged 19 commits into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6dc4bc5
When a livechat visitor attempted to change the current department, t…
renatobecker Jun 5, 2018
0ee4d79
Merge branch 'develop' into fix-changing-livechat-visitor-department
renatobecker Jun 13, 2018
4c980c7
Merge branch 'develop' into fix-changing-livechat-visitor-department
renatobecker Jun 13, 2018
b4deb6e
Fixed the behaviour of the LiveChat department change.
renatobecker Jun 14, 2018
cdc7a4d
Merge branch 'develop' into fix-changing-livechat-visitor-department
ggazzo Jun 14, 2018
38872a0
Merge branch 'develop' into fix-changing-livechat-visitor-department
renatobecker Jun 14, 2018
cf34fb9
Merge branch 'fix-changing-livechat-visitor-department' of github.com…
renatobecker Jun 14, 2018
08e2df1
Invalid comments removed.
renatobecker Jun 14, 2018
f03652e
Merge branch 'develop' into fix-changing-livechat-visitor-department
renatobecker Jul 11, 2018
aee97ea
Merge branch 'develop' into fix-changing-livechat-visitor-department
renatobecker Aug 2, 2018
d6c795a
Fixed `RocketChat.Livechat.stream.emit` that was not being emitted.
renatobecker Aug 3, 2018
247db3e
Merge branch 'develop' into fix-changing-livechat-visitor-department
renatobecker Aug 3, 2018
19205b6
Merged `develop` into current branch.
renatobecker Aug 3, 2018
8592c7e
Merge branch 'develop' into fix-changing-livechat-visitor-department
renatobecker Aug 19, 2018
92f75c1
Fix eslint new rules.
renatobecker Aug 19, 2018
3353332
Fix eslint new rules.
renatobecker Aug 19, 2018
583317d
Fix eslint new really rules.
renatobecker Aug 19, 2018
9a98faa
Fix eslint new rules.
renatobecker Aug 19, 2018
3b5c72f
Merge branch 'develop' into fix-changing-livechat-visitor-department
sampaiodiego Aug 21, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,15 @@ Template.livechatWindow.onCreated(function() {
Livechat.nameFieldRegistrationForm = result.nameFieldRegistrationForm;
Livechat.emailFieldRegistrationForm = result.emailFieldRegistrationForm;

loadDepartments(result.departments);

if (result.visitor) {
visitor.setData(result.visitor);

if (result.visitor.department) {
Livechat.department = result.visitor.department;
}

if (result.visitor.name) {
Livechat.guestName = result.visitor.name;
}
Expand Down Expand Up @@ -171,8 +177,6 @@ Template.livechatWindow.onCreated(function() {
Triggers.setTriggers(result.triggers);
Triggers.init();

loadDepartments(result.departments);

Livechat.allowSwitchingDepartments = result.allowSwitchingDepartments;

Livechat.ready();
Expand Down
28 changes: 14 additions & 14 deletions packages/rocketchat-livechat/.app/client/views/switchDepartment.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Template.switchDepartment.events({

instance.error.set();
swal({
text: t('Are_you_sure_do_you_want_end_this_chat_and_switch_department'),
text: t('Are_you_sure_do_you_want_switch_the_department'),
title: '',
type: 'warning',
showCancelButton: true,
Expand All @@ -49,27 +49,27 @@ Template.switchDepartment.events({
return;
}

Meteor.call('livechat:closeByVisitor', { roomId: visitor.getRoom(), token: visitor.getToken() }, (error) => {
if (error) {
return console.log('Error ->', error);
}
const guestData = {
roomId: visitor.getRoom(),
visitorToken: visitor.getToken(),
departmentId,
};

const guestData = {
token: visitor.getToken(),
department: departmentId,
};
Meteor.call('livechat:setDepartmentForVisitor', guestData, (error) => {
if (error) {
return console.log('Error ->', error);
}
Meteor.call('livechat:setDepartmentForVisitor', guestData, (error, result) => {
if (error) {
instance.error.set(error.error);
} else if (result) {
instance.error.set();
Livechat.department = departmentId;
Livechat.showSwitchDepartmentForm = false;
swal({
title: t('Department_switched'),
type: 'success',
timer: 2000,
});
});
} else {
instance.error.set(t('No_available_agents_to_transfer'));
}
});
});
},
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-livechat/.app/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Appearance": "Appearance",
"Are_you_sure_do_you_want_end_this_chat": "Are you sure you want to end this chat?",
"Are_you_sure_do_you_want_end_this_chat_and_switch_department": "Are you sure you want to end this chat and switch department?",
"Are_you_sure_do_you_want_switch_the_department": "Are you sure you want to switch the department?",
"Cancel": "Cancel",
"Change": "Change",
"Chat_ended": "Chat ended!",
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-livechat/.app/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Appearance": "Aparência",
"Are_you_sure_do_you_want_end_this_chat": "Você tem certeza que deseja encerrar?",
"Are_you_sure_do_you_want_end_this_chat_and_switch_department": "Tem certeza que deseja fechar esse chat e trocar de departamento?",
"Are_you_sure_do_you_want_switch_the_department": "Tem certeza que deseja trocar de departamento?",
"Cancel": "Cancelar",
"Change": "Alterar",
"Chat_ended": "Chat encerrado!",
Expand Down
15 changes: 12 additions & 3 deletions packages/rocketchat-livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ RocketChat.Livechat = {

const user = LivechatVisitors.getVisitorByToken(token, { fields: { _id: 1 } });
if (user) {
return Meteor.users.update(user._id, updateUser);
return LivechatVisitors.updateById(user._id, updateUser);
}
return false;
},
Expand Down Expand Up @@ -403,6 +403,13 @@ RocketChat.Livechat = {
RocketChat.models.Messages.createUserLeaveWithRoomIdAndUser(room._id, { _id: servedBy._id, username: servedBy.username });
RocketChat.models.Messages.createUserJoinWithRoomIdAndUser(room._id, { _id: agent.agentId, username: agent.username });

const guestData = {
token: guest.token,
department: transferData.departmentId,
};

this.setDepartmentForGuest(guestData);

RocketChat.Livechat.stream.emit(room._id, {
type: 'agentData',
data: RocketChat.models.Users.getAgentInfo(agent.agentId),
Expand Down Expand Up @@ -472,7 +479,7 @@ RocketChat.Livechat = {
if (openInq) {
RocketChat.models.Messages.createUserLeaveWithRoomIdAndUser(rid, { _id: room.servedBy._id, username: room.servedBy.username });

RocketChat.Livechat.stream.emit(room._id, {
RocketChat.Livechat.stream.emit(rid, {
type: 'agentData',
data: null,
});
Expand Down Expand Up @@ -676,11 +683,13 @@ RocketChat.Livechat.stream = new Meteor.Streamer('livechat-room');

RocketChat.Livechat.stream.allowRead((roomId, extraData) => {
const room = RocketChat.models.Rooms.findOneById(roomId);

if (!room) {
console.warn(`Invalid eventName: "${ roomId }"`);
return false;
}
if (room.t === 'l' && extraData && extraData.token && room.v.token === extraData.token) {

if (room.t === 'l' && extraData && extraData.visitorToken && room.v.token === extraData.visitorToken) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Meteor.methods({
const room = RocketChat.models.Rooms.findOneById(roomId);
const visitor = LivechatVisitors.getVisitorByToken(token);

// allow to only user to send transcripts from their own chats
if (!room || room.t !== 'l' || !room.v || room.v.token !== visitor.token) {
throw new Meteor.Error('error-invalid-room', 'Invalid room');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import LivechatVisitors from '../models/LivechatVisitors';

Meteor.methods({
'livechat:setDepartmentForVisitor'({ token, department } = {}) {
RocketChat.Livechat.setDepartmentForGuest.call(this, {
token,
department,
});
'livechat:setDepartmentForVisitor'({ roomId, visitorToken, departmentId } = {}) {
check(roomId, String);
check(visitorToken, String);
check(departmentId, String);

const room = RocketChat.models.Rooms.findOneById(roomId);
const visitor = LivechatVisitors.getVisitorByToken(visitorToken);

if (!room || room.t !== 'l' || !room.v || room.v.token !== visitor.token) {
throw new Meteor.Error('error-invalid-room', 'Invalid room');
}

// update visited page history to not expire
RocketChat.models.Messages.keepHistoryForToken(token);
RocketChat.models.Messages.keepHistoryForToken(visitorToken);

const transferData = {
roomId,
departmentId,
};

return true;
return RocketChat.Livechat.transfer(room, visitor, transferData);
},
});