Skip to content

Commit cc0bd72

Browse files
committed
Harmonize behavior of live chats and requests with respect to actions handling
Fixes #44
1 parent 9367ec3 commit cc0bd72

File tree

3 files changed

+30
-46
lines changed

3 files changed

+30
-46
lines changed

packages/assistify-help-request/client/views/tabbar/HelpRequestActions.js

+18-34
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Template.HelpRequestActions.dialogs = {
3636
*/
3737
display() {
3838
const self = this;
39-
return new Promise(function (resolve, reject) {
39+
return new Promise(function(resolve, reject) {
4040
swal.withForm(_.extend({
4141
title: t('Closing_chat'),
4242
text: '',
@@ -64,7 +64,7 @@ Template.HelpRequestActions.dialogs = {
6464
}],
6565
showCancelButton: true,
6666
closeOnConfirm: false
67-
}, self.properties), function (isConfirm) {
67+
}, self.properties), function(isConfirm) {
6868
if (!isConfirm) { //on cancel
6969
$('.swal-form').remove(); //possible bug? why I have to do this manually
7070
reject();
@@ -96,16 +96,16 @@ Template.HelpRequestActions.events({
9696
roomId: instance.data.roomId
9797
}), (inputValue) => {
9898
/*if (!inputValue) {
99-
swal.showInputError(t('Please_add_a_comment_to_close_the_room'));
100-
return false;
101-
}
99+
swal.showInputError(t('Please_add_a_comment_to_close_the_room'));
100+
return false;
101+
}
102102
103-
if (s.trim(inputValue) === '') {
104-
swal.showInputError(t('Please_add_a_comment_to_close_the_room'));
105-
return false;
106-
}*/
103+
if (s.trim(inputValue) === '') {
104+
swal.showInputError(t('Please_add_a_comment_to_close_the_room'));
105+
return false;
106+
}*/
107107

108-
Meteor.call('assistify:closeHelpRequest', this.roomId, {comment: inputValue}, function (error) {
108+
Meteor.call('assistify:closeHelpRequest', this.roomId, {comment: inputValue}, function(error) {
109109
if (error) {
110110
return handleError(error);
111111
} else {
@@ -134,17 +134,8 @@ Template.HelpRequestActions.events({
134134
showCancelButton: true,
135135
closeOnConfirm: false
136136
}, (inputValue) => {
137-
if (!inputValue) {
138-
swal.showInputError(t('Please_add_a_comment_to_close_the_room'));
139-
return false;
140-
}
141137

142-
if (s.trim(inputValue) === '') {
143-
swal.showInputError(t('Please_add_a_comment_to_close_the_room'));
144-
return false;
145-
}
146-
147-
Meteor.call('livechat:closeRoom', this.rid, inputValue, function (error/*, result*/) {
138+
Meteor.call('livechat:closeRoom', this.roomId, inputValue, function(error/*, result*/) {
148139
if (error) {
149140
return handleError(error);
150141
}
@@ -160,26 +151,19 @@ Template.HelpRequestActions.events({
160151
}
161152
});
162153

163-
Template.HelpRequestActions.onCreated(function () {
154+
Template.HelpRequestActions.onCreated(function() {
164155
const instance = this;
165156
this.helpRequest = new ReactiveVar(null);
166-
167-
Meteor.subscribe('assistify:helpRequests', instance.data.roomId); //not reactively needed, as roomId doesn't change
168-
157+
this.room = new ReactiveVar(null);
169158
this.autorun(() => {
170-
if (Template.currentData().roomId) {
159+
if (instance.data && instance.data.roomId) {
160+
Meteor.subscribe('assistify:helpRequests', instance.data.roomId); //not reactively needed, as roomId doesn't change
161+
171162
const helpRequest = RocketChat.models.HelpRequests.findOneByRoomId(instance.data.roomId);
172163
instance.helpRequest.set(helpRequest);
173164

174-
// if (!instance.helpRequest.get()) { //todo remove after PoC: Non-reactive method call
175-
// Meteor.call('assistify:helpRequestByRoomId', Template.currentData().roomId, (err, result) => {
176-
// if (!err) {
177-
// instance.helpRequest.set(result);
178-
// } else {
179-
// console.log(err);
180-
// }
181-
// });
182-
// }
165+
const room = ChatSubscription.findOne({rid: instance.data.roomId});
166+
instance.room.set(room);
183167
}
184168
});
185169
});

packages/dbs-ai/client/views/app/tabbar/smarti.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h2><span class="title-icon"><img
1111
{{/if}}
1212
{{/let}}
1313
{{#if isLivechat}}
14-
{{> HelpRequestActions }}
14+
{{> HelpRequestActions liveChatActions}}
1515
{{/if}}
1616
<div class="external-message">Smarti</div>
1717
</div>

packages/dbs-ai/client/views/app/tabbar/smarti.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
Template.dbsAI_smarti.onCreated(function() {
22
this.helpRequest = new ReactiveVar(null);
3-
43
const instance = this;
54

5+
Meteor.subscribe('assistify:helpRequests', instance.data.rid); //not reactively needed, as roomId doesn't change
6+
67
this.autorun(() => {
78
if (instance.data.rid) {
8-
9-
if (!instance.helpRequest.get()) { //todo remove after PoC: Non-reactive method call
10-
Meteor.call('assistify:helpRequestByRoomId', instance.data.rid, (err, result) => {
11-
if (!err) {
12-
instance.helpRequest.set(result);
13-
} else {
14-
console.log(err);
15-
}
16-
});
17-
}
9+
const helpRequest = RocketChat.models.HelpRequests.findOneByRoomId(instance.data.rid);
10+
instance.helpRequest.set(helpRequest);
1811
}
1912
});
2013

@@ -64,6 +57,13 @@ Template.dbsAI_smarti.helpers({
6457
const instance = Template.instance();
6558
return ChatSubscription.findOne({rid: instance.data.rid}).t === 'l';
6659
},
60+
/**
61+
This helper is needed in order to create an object which matches the actions bar importing parameters
62+
*/
63+
liveChatActions() {
64+
const instance = Template.instance();
65+
return { roomId: instance.data.rid };
66+
},
6767
helpRequestByRoom() {
6868
const instance = Template.instance();
6969
return instance.helpRequest.get();

0 commit comments

Comments
 (0)