@@ -32,7 +32,7 @@ qx.Class.define("osparc.conversation.AddMessage", {
3232 check : "String" ,
3333 init : null ,
3434 nullable : true ,
35- event : "changeConversationId"
35+ event : "changeConversationId" ,
3636 } ,
3737
3838 studyData : {
@@ -150,7 +150,7 @@ qx.Class.define("osparc.conversation.AddMessage", {
150150
151151 __applyStudyData : function ( studyData ) {
152152 if ( studyData ) {
153- const canIWrite = osparc . data . model . Study . canIWrite ( this . __studyData [ "accessRights" ] )
153+ const canIWrite = osparc . data . model . Study . canIWrite ( studyData [ "accessRights" ] )
154154 this . getChildControl ( "add-comment-button" ) . setEnabled ( canIWrite ) ;
155155 this . getChildControl ( "notify-user-button" ) . show ( ) ;
156156 this . getChildControl ( "notify-user-button" ) . setEnabled ( canIWrite ) ;
@@ -175,35 +175,53 @@ qx.Class.define("osparc.conversation.AddMessage", {
175175 } ,
176176
177177 __addComment : function ( ) {
178- if ( this . __conversationId ) {
178+ const conversationId = this . getConversationId ( ) ;
179+ if ( conversationId ) {
179180 this . __postMessage ( ) ;
180181 } else {
181- // create new conversation first
182- osparc . store . ConversationsProject . getInstance ( ) . addConversation ( this . __studyData [ "uuid" ] )
183- . then ( data => {
184- this . __conversationId = data [ "conversationId" ] ;
185- this . __postMessage ( ) ;
186- } )
182+ const studyData = this . getStudyData ( ) ;
183+ if ( studyData ) {
184+ // create new conversation first
185+ osparc . store . ConversationsProject . getInstance ( ) . addConversation ( studyData )
186+ . then ( data => {
187+ this . setConversationId ( data [ "conversationId" ] ) ;
188+ this . __postMessage ( ) ;
189+ } ) ;
190+ } else {
191+ // support conversation
192+ }
187193 }
188194 } ,
189195
190196 __editComment : function ( ) {
191197 const commentField = this . getChildControl ( "comment-field" ) ;
192198 const content = commentField . getChildControl ( "text-area" ) . getValue ( ) ;
193199 if ( content ) {
194- osparc . store . ConversationsProject . getInstance ( ) . editMessage ( this . __studyData [ "uuid" ] , this . __conversationId , this . __message [ "messageId" ] , content )
195- . then ( data => {
196- this . fireDataEvent ( "messageUpdated" , data ) ;
197- commentField . getChildControl ( "text-area" ) . setValue ( "" ) ;
198- } ) ;
200+ const studyData = this . getStudyData ( ) ;
201+ const conversationId = this . getConversationId ( ) ;
202+ const message = this . getMessage ( ) ;
203+ if ( studyData ) {
204+ osparc . store . ConversationsProject . getInstance ( ) . editMessage ( studyData [ "uuid" ] , conversationId , message [ "messageId" ] , content )
205+ . then ( data => {
206+ this . fireDataEvent ( "messageUpdated" , data ) ;
207+ commentField . getChildControl ( "text-area" ) . setValue ( "" ) ;
208+ } ) ;
209+ } else {
210+ // support comment editing
211+ }
199212 }
200213 } ,
201214
202215 /* NOTIFY USERS */
203216 __notifyUserTapped : function ( ) {
217+ const studyData = this . getStudyData ( ) ;
218+ if ( ! studyData ) {
219+ return ;
220+ }
221+
204222 const showOrganizations = false ;
205223 const showAccessRights = false ;
206- const userManager = new osparc . share . NewCollaboratorsManager ( this . __studyData , showOrganizations , showAccessRights ) . set ( {
224+ const userManager = new osparc . share . NewCollaboratorsManager ( studyData , showOrganizations , showAccessRights ) . set ( {
207225 acceptOnlyOne : true ,
208226 } ) ;
209227 userManager . setCaption ( this . tr ( "Notify user" ) ) ;
@@ -220,10 +238,15 @@ qx.Class.define("osparc.conversation.AddMessage", {
220238 } ,
221239
222240 __notifyUser : function ( userGid ) {
241+ const studyData = this . getStudyData ( ) ;
242+ if ( ! studyData ) {
243+ return ;
244+ }
245+
223246 // Note!
224247 // This check only works if the project is directly shared with the user.
225248 // If it's shared through a group, it might be a bit confusing
226- if ( userGid in this . __studyData [ "accessRights" ] ) {
249+ if ( userGid in studyData [ "accessRights" ] ) {
227250 this . __addNotify ( userGid ) ;
228251 } else {
229252 const msg = this . tr ( "This user has no access to the project. Do you want to share it?" ) ;
@@ -239,13 +262,13 @@ qx.Class.define("osparc.conversation.AddMessage", {
239262 const newCollaborators = {
240263 [ userGid ] : osparc . data . Roles . STUDY [ "write" ] . accessRights
241264 } ;
242- osparc . store . Study . getInstance ( ) . addCollaborators ( this . __studyData , newCollaborators )
265+ osparc . store . Study . getInstance ( ) . addCollaborators ( studyData , newCollaborators )
243266 . then ( ( ) => {
244267 this . __addNotify ( userGid ) ;
245268 const potentialCollaborators = osparc . store . Groups . getInstance ( ) . getPotentialCollaborators ( )
246269 if ( userGid in potentialCollaborators && "getUserId" in potentialCollaborators [ userGid ] ) {
247270 const uid = potentialCollaborators [ userGid ] . getUserId ( ) ;
248- osparc . notification . Notifications . pushStudyShared ( uid , this . __studyData [ "uuid" ] ) ;
271+ osparc . notification . Notifications . pushStudyShared ( uid , studyData [ "uuid" ] ) ;
249272 }
250273 } )
251274 . catch ( err => osparc . FlashMessenger . logError ( err ) ) ;
@@ -255,51 +278,65 @@ qx.Class.define("osparc.conversation.AddMessage", {
255278 } ,
256279
257280 __addNotify : function ( userGid ) {
258- if ( this . __conversationId ) {
281+ const studyData = this . getStudyData ( ) ;
282+ if ( ! studyData ) {
283+ return ;
284+ }
285+
286+ const conversationId = this . getConversationId ( ) ;
287+ if ( conversationId ) {
259288 this . __postNotify ( userGid ) ;
260289 } else {
261290 // create new conversation first
262- osparc . store . ConversationsProject . getInstance ( ) . addConversation ( this . __studyData [ "uuid" ] )
291+ osparc . store . ConversationsProject . getInstance ( ) . addConversation ( studyData [ "uuid" ] )
263292 . then ( data => {
264- this . __conversationId = data [ "conversationId" ] ;
293+ this . setConversationId ( data [ "conversationId" ] ) ;
265294 this . __postNotify ( userGid ) ;
266295 } ) ;
267296 }
268297 } ,
269- /* NOTIFY USERS */
270298
271- __postMessage : function ( ) {
272- const commentField = this . getChildControl ( "comment-field" ) ;
273- const content = commentField . getChildControl ( "text-area" ) . getValue ( ) ;
274- if ( content ) {
275- if ( this . __studyData ) {
276- osparc . store . ConversationsProject . getInstance ( ) . addMessage ( this . __studyData [ "uuid" ] , this . __conversationId , content )
277- . then ( data => {
278- this . fireDataEvent ( "messageAdded" , data ) ;
279- commentField . getChildControl ( "text-area" ) . setValue ( "" ) ;
280- } ) ;
281- } else {
282- // Support
283- }
299+ __postNotify : function ( userGid ) {
300+ const studyData = this . getStudyData ( ) ;
301+ if ( ! studyData ) {
302+ return ;
284303 }
285- } ,
286304
287- __postNotify : function ( userGid ) {
288305 if ( userGid ) {
289- osparc . store . ConversationsProject . getInstance ( ) . notifyUser ( this . __studyData [ "uuid" ] , this . __conversationId , userGid )
306+ const conversationId = this . getConversationId ( ) ;
307+ osparc . store . ConversationsProject . getInstance ( ) . notifyUser ( studyData [ "uuid" ] , conversationId , userGid )
290308 . then ( data => {
291309 this . fireDataEvent ( "messageAdded" , data ) ;
292310 const potentialCollaborators = osparc . store . Groups . getInstance ( ) . getPotentialCollaborators ( ) ;
293311 if ( userGid in potentialCollaborators ) {
294312 if ( "getUserId" in potentialCollaborators [ userGid ] ) {
295313 const uid = potentialCollaborators [ userGid ] . getUserId ( ) ;
296- osparc . notification . Notifications . pushConversationNotification ( uid , this . __studyData [ "uuid" ] ) ;
314+ osparc . notification . Notifications . pushConversationNotification ( uid , studyData [ "uuid" ] ) ;
297315 }
298316 const msg = "getLabel" in potentialCollaborators [ userGid ] ? potentialCollaborators [ userGid ] . getLabel ( ) + this . tr ( " was notified" ) : this . tr ( "Notification sent" ) ;
299317 osparc . FlashMessenger . logAs ( msg , "INFO" ) ;
300318 }
301319 } ) ;
302320 }
303321 } ,
322+ /* NOTIFY USERS */
323+
324+ __postMessage : function ( ) {
325+ const commentField = this . getChildControl ( "comment-field" ) ;
326+ const content = commentField . getChildControl ( "text-area" ) . getValue ( ) ;
327+ if ( content ) {
328+ const studyData = this . getStudyData ( ) ;
329+ const conversationId = this . getConversationId ( ) ;
330+ if ( studyData ) {
331+ osparc . store . ConversationsProject . getInstance ( ) . addMessage ( studyData [ "uuid" ] , conversationId , content )
332+ . then ( data => {
333+ this . fireDataEvent ( "messageAdded" , data ) ;
334+ commentField . getChildControl ( "text-area" ) . setValue ( "" ) ;
335+ } ) ;
336+ } else {
337+ // Support
338+ }
339+ }
340+ } ,
304341 }
305342} ) ;
0 commit comments