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 visitor not being prompted for transcript when himself is closing the chat #10767

Merged
merged 9 commits into from
Jun 20, 2018
2 changes: 1 addition & 1 deletion packages/rocketchat-livechat/.app/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ mizzao:timesync
reactive-var@1.0.11
accounts-password@1.5.0
tap:i18n
smoral:sweetalert
ecmascript@0.10.6
es5-shim@4.7.0
standard-minifier-css@1.4.0
Expand All @@ -40,3 +39,4 @@ shell-server@0.3.1
dynamic-import@0.3.0

konecty:user-presence
cleandersonlobo:sweetalert2
2 changes: 1 addition & 1 deletion packages/rocketchat-livechat/.app/.meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ caching-html-compiler@1.1.2
callback-hook@1.1.0
cfs:http-methods@0.0.32
check@1.3.1
cleandersonlobo:sweetalert2@1.5.0
coffeescript@1.0.17
ddp@1.4.0
ddp-client@2.3.2
Expand Down Expand Up @@ -78,7 +79,6 @@ session@1.1.7
sha@1.0.9
shell-server@0.3.1
shim-common@0.1.0
smoral:sweetalert@1.1.1
socket-stream-client@0.1.0
spacebars@1.0.15
spacebars-compiler@1.1.3
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-livechat/.app/client/lib/chatMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ this.ChatMessages = class ChatMessages {
}

visitor.setId(result.userId);
visitor.setData(result.visitor);

sendMessage();
});
} else {
Expand Down
23 changes: 11 additions & 12 deletions packages/rocketchat-livechat/.app/client/lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,30 @@ this.Commands = {
if (Livechat.transcript) {
const visitorData = visitor.getData();
const email = visitorData && visitorData.visitorEmails && visitorData.visitorEmails.length > 0 ? visitorData.visitorEmails[0].address : '';
const transcriptMessage = (!_.isEmpty(Livechat.transcriptMessage)) ? Livechat.transcriptMessage : (TAPi18n.__('Would_you_like_a_copy_if_this_chat_emailed'));
const transcriptMessage = (Livechat.transcriptMessage) ? Livechat.transcriptMessage : (TAPi18n.__('Would_you_like_a_copy_if_this_chat_emailed'));

swal({
title: t('Chat_ended'),
text: transcriptMessage,
type: 'input',
input: 'email',
inputValue: email,
inputPlaceholder: t('Type_your_email'),
showCancelButton: true,
cancelButtonText: t('no'),
confirmButtonText: t('yes'),
closeOnCancel: true,
closeOnConfirm: false
}, (response) => {
if ((typeof response === 'boolean') && !response) {
confirmButtonText: t('yes')
}).then((result) => {
if ((typeof result.value === 'boolean') && !response) {
Copy link
Member

Choose a reason for hiding this comment

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

since there are a lot of changes here, what do you think on improving it's logic to look more "flat" (as the previous code improvements) ?

return true;
} else {
if (!response) {
swal.showInputError(t('please enter your email'));
if (!result.value) {
swal.showValidationError(t('please enter your email'));
return false;
}
if (response.trim() === '') {
swal.showInputError(t('please enter your email'));
if (result.value.trim() === '') {
swal.showValidationError(t('please enter your email'));
return false;
} else {
Meteor.call('livechat:sendTranscript', visitor.getToken(), visitor.getRoom(), response, (err) => {
Meteor.call('livechat:sendTranscript', visitor.getToken(), visitor.getRoom(), result.value, (err) => {
if (err) {
console.error(err);
}
Expand Down
18 changes: 7 additions & 11 deletions packages/rocketchat-livechat/.app/client/views/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ Template.options.events({
confirmButtonColor: '#DD6B55',
confirmButtonText: t('Yes'),
cancelButtonText: t('No'),
closeOnConfirm: true,
html: false
}, () => {
Meteor.call('livechat:closeByVisitor', { roomId: visitor.getRoom(), token: visitor.getToken() }, (error) => {
if (error) {
return console.log('Error ->', error);
}
swal({
title: t('Chat_ended'),
type: 'success',
timer: 2000
}).then((result) => {
if (result.value) {
Meteor.call('livechat:closeByVisitor', { roomId: visitor.getRoom(), token: visitor.getToken() }, (error) => {
if (error) {
return console.log('Error ->', error);
}
});
});
}
});
},
'click .switch-department'() {
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-livechat/.app/client/views/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Template.register.events({
}
parentCall('callback', ['pre-chat-form-submit', _.omit(guest, 'token')]);
visitor.setId(result.userId);
visitor.setData(result.visitor);
start();
});
}
Expand Down
13 changes: 12 additions & 1 deletion packages/rocketchat-livechat/server/methods/registerGuest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import LivechatVisitors from '../models/LivechatVisitors';

Meteor.methods({
'livechat:registerGuest'({ token, name, email, department } = {}) {
const userId = RocketChat.Livechat.registerGuest.call(this, {
Expand All @@ -10,8 +12,17 @@ Meteor.methods({
// update visited page history to not expire
RocketChat.models.LivechatPageVisited.keepHistoryForToken(token);

const visitor = LivechatVisitors.getVisitorByToken(token, {
fields: {
name: 1,
username: 1,
visitorEmails: 1
}
});

return {
userId
userId,
visitor
};
}
});