Skip to content

Commit

Permalink
Harmonize behavior of live chats and requests with respect to actions…
Browse files Browse the repository at this point in the history
… handling

Fixes #44
  • Loading branch information
mrsimpson committed Jul 19, 2017
1 parent 9367ec3 commit cc0bd72
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Template.HelpRequestActions.dialogs = {
*/
display() {
const self = this;
return new Promise(function (resolve, reject) {
return new Promise(function(resolve, reject) {
swal.withForm(_.extend({
title: t('Closing_chat'),
text: '',
Expand Down Expand Up @@ -64,7 +64,7 @@ Template.HelpRequestActions.dialogs = {
}],
showCancelButton: true,
closeOnConfirm: false
}, self.properties), function (isConfirm) {
}, self.properties), function(isConfirm) {
if (!isConfirm) { //on cancel
$('.swal-form').remove(); //possible bug? why I have to do this manually
reject();
Expand Down Expand Up @@ -96,16 +96,16 @@ Template.HelpRequestActions.events({
roomId: instance.data.roomId
}), (inputValue) => {
/*if (!inputValue) {
swal.showInputError(t('Please_add_a_comment_to_close_the_room'));
return false;
}
swal.showInputError(t('Please_add_a_comment_to_close_the_room'));
return false;
}
if (s.trim(inputValue) === '') {
swal.showInputError(t('Please_add_a_comment_to_close_the_room'));
return false;
}*/
if (s.trim(inputValue) === '') {
swal.showInputError(t('Please_add_a_comment_to_close_the_room'));
return false;
}*/

Meteor.call('assistify:closeHelpRequest', this.roomId, {comment: inputValue}, function (error) {
Meteor.call('assistify:closeHelpRequest', this.roomId, {comment: inputValue}, function(error) {
if (error) {
return handleError(error);
} else {
Expand Down Expand Up @@ -134,17 +134,8 @@ Template.HelpRequestActions.events({
showCancelButton: true,
closeOnConfirm: false
}, (inputValue) => {
if (!inputValue) {
swal.showInputError(t('Please_add_a_comment_to_close_the_room'));
return false;
}

if (s.trim(inputValue) === '') {
swal.showInputError(t('Please_add_a_comment_to_close_the_room'));
return false;
}

Meteor.call('livechat:closeRoom', this.rid, inputValue, function (error/*, result*/) {
Meteor.call('livechat:closeRoom', this.roomId, inputValue, function(error/*, result*/) {
if (error) {
return handleError(error);
}
Expand All @@ -160,26 +151,19 @@ Template.HelpRequestActions.events({
}
});

Template.HelpRequestActions.onCreated(function () {
Template.HelpRequestActions.onCreated(function() {
const instance = this;
this.helpRequest = new ReactiveVar(null);

Meteor.subscribe('assistify:helpRequests', instance.data.roomId); //not reactively needed, as roomId doesn't change

this.room = new ReactiveVar(null);
this.autorun(() => {
if (Template.currentData().roomId) {
if (instance.data && instance.data.roomId) {
Meteor.subscribe('assistify:helpRequests', instance.data.roomId); //not reactively needed, as roomId doesn't change

const helpRequest = RocketChat.models.HelpRequests.findOneByRoomId(instance.data.roomId);
instance.helpRequest.set(helpRequest);

// if (!instance.helpRequest.get()) { //todo remove after PoC: Non-reactive method call
// Meteor.call('assistify:helpRequestByRoomId', Template.currentData().roomId, (err, result) => {
// if (!err) {
// instance.helpRequest.set(result);
// } else {
// console.log(err);
// }
// });
// }
const room = ChatSubscription.findOne({rid: instance.data.roomId});
instance.room.set(room);
}
});
});
2 changes: 1 addition & 1 deletion packages/dbs-ai/client/views/app/tabbar/smarti.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2><span class="title-icon"><img
{{/if}}
{{/let}}
{{#if isLivechat}}
{{> HelpRequestActions }}
{{> HelpRequestActions liveChatActions}}
{{/if}}
<div class="external-message">Smarti</div>
</div>
Expand Down
22 changes: 11 additions & 11 deletions packages/dbs-ai/client/views/app/tabbar/smarti.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
Template.dbsAI_smarti.onCreated(function() {
this.helpRequest = new ReactiveVar(null);

const instance = this;

Meteor.subscribe('assistify:helpRequests', instance.data.rid); //not reactively needed, as roomId doesn't change

this.autorun(() => {
if (instance.data.rid) {

if (!instance.helpRequest.get()) { //todo remove after PoC: Non-reactive method call
Meteor.call('assistify:helpRequestByRoomId', instance.data.rid, (err, result) => {
if (!err) {
instance.helpRequest.set(result);
} else {
console.log(err);
}
});
}
const helpRequest = RocketChat.models.HelpRequests.findOneByRoomId(instance.data.rid);
instance.helpRequest.set(helpRequest);
}
});

Expand Down Expand Up @@ -64,6 +57,13 @@ Template.dbsAI_smarti.helpers({
const instance = Template.instance();
return ChatSubscription.findOne({rid: instance.data.rid}).t === 'l';
},
/**
This helper is needed in order to create an object which matches the actions bar importing parameters
*/
liveChatActions() {
const instance = Template.instance();
return { roomId: instance.data.rid };
},
helpRequestByRoom() {
const instance = Template.instance();
return instance.helpRequest.get();
Expand Down

0 comments on commit cc0bd72

Please sign in to comment.