@@ -36,7 +36,7 @@ Template.HelpRequestActions.dialogs = {
36
36
*/
37
37
display ( ) {
38
38
const self = this ;
39
- return new Promise ( function ( resolve , reject ) {
39
+ return new Promise ( function ( resolve , reject ) {
40
40
swal . withForm ( _ . extend ( {
41
41
title : t ( 'Closing_chat' ) ,
42
42
text : '' ,
@@ -64,7 +64,7 @@ Template.HelpRequestActions.dialogs = {
64
64
} ] ,
65
65
showCancelButton : true ,
66
66
closeOnConfirm : false
67
- } , self . properties ) , function ( isConfirm ) {
67
+ } , self . properties ) , function ( isConfirm ) {
68
68
if ( ! isConfirm ) { //on cancel
69
69
$ ( '.swal-form' ) . remove ( ) ; //possible bug? why I have to do this manually
70
70
reject ( ) ;
@@ -96,16 +96,16 @@ Template.HelpRequestActions.events({
96
96
roomId : instance . data . roomId
97
97
} ) , ( inputValue ) => {
98
98
/*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
+ }
102
102
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
+ }*/
107
107
108
- Meteor . call ( 'assistify:closeHelpRequest' , this . roomId , { comment : inputValue } , function ( error ) {
108
+ Meteor . call ( 'assistify:closeHelpRequest' , this . roomId , { comment : inputValue } , function ( error ) {
109
109
if ( error ) {
110
110
return handleError ( error ) ;
111
111
} else {
@@ -134,17 +134,8 @@ Template.HelpRequestActions.events({
134
134
showCancelButton : true ,
135
135
closeOnConfirm : false
136
136
} , ( inputValue ) => {
137
- if ( ! inputValue ) {
138
- swal . showInputError ( t ( 'Please_add_a_comment_to_close_the_room' ) ) ;
139
- return false ;
140
- }
141
137
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*/ ) {
148
139
if ( error ) {
149
140
return handleError ( error ) ;
150
141
}
@@ -160,26 +151,19 @@ Template.HelpRequestActions.events({
160
151
}
161
152
} ) ;
162
153
163
- Template . HelpRequestActions . onCreated ( function ( ) {
154
+ Template . HelpRequestActions . onCreated ( function ( ) {
164
155
const instance = this ;
165
156
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 ) ;
169
158
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
+
171
162
const helpRequest = RocketChat . models . HelpRequests . findOneByRoomId ( instance . data . roomId ) ;
172
163
instance . helpRequest . set ( helpRequest ) ;
173
164
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 ) ;
183
167
}
184
168
} ) ;
185
169
} ) ;
0 commit comments