@@ -53,8 +53,9 @@ qx.Class.define("osparc.conversation.AddMessage", {
5353 } ,
5454
5555 events : {
56- "messageAdded " : "qx.event.type.Data" ,
56+ "addMessage " : "qx.event.type.Data" ,
5757 "updateMessage" : "qx.event.type.Data" ,
58+ "notifyUser" : "qx.event.type.Data" ,
5859 } ,
5960
6061 members : {
@@ -171,53 +172,12 @@ qx.Class.define("osparc.conversation.AddMessage", {
171172 } ,
172173
173174 addComment : function ( ) {
174- const conversationId = this . getConversationId ( ) ;
175- if ( conversationId ) {
176- return this . __postMessage ( ) ;
177- } else {
178- // create new conversation first
179- const studyData = this . getStudyData ( ) ;
180- let promise = null ;
181- if ( studyData ) {
182- // project conversation
183- promise = osparc . store . ConversationsProject . getInstance ( ) . postConversation ( studyData [ "uuid" ] )
184- } else {
185- // support conversation
186- const extraContext = { } ;
187- const currentStudy = osparc . store . Store . getInstance ( ) . getCurrentStudy ( )
188- if ( currentStudy ) {
189- extraContext [ "projectId" ] = currentStudy . getUuid ( ) ;
190- }
191- promise = osparc . store . ConversationsSupport . getInstance ( ) . postConversation ( extraContext ) ;
192- }
193- return promise
194- . then ( data => {
195- this . setConversationId ( data [ "conversationId" ] ) ;
196- return this . __postMessage ( ) ;
197- } ) ;
198- }
199- } ,
200-
201- __postMessage : function ( ) {
202175 const commentField = this . getChildControl ( "comment-field" ) ;
203176 const content = commentField . getChildControl ( "text-area" ) . getValue ( ) ;
204- let promise = null ;
205177 if ( content ) {
206- const studyData = this . getStudyData ( ) ;
207- const conversationId = this . getConversationId ( ) ;
208- if ( studyData ) {
209- promise = osparc . store . ConversationsProject . getInstance ( ) . postMessage ( studyData [ "uuid" ] , conversationId , content ) ;
210- } else {
211- promise = osparc . store . ConversationsSupport . getInstance ( ) . postMessage ( conversationId , content ) ;
212- }
213- return promise
214- . then ( data => {
215- this . fireDataEvent ( "messageAdded" , data ) ;
216- commentField . getChildControl ( "text-area" ) . setValue ( "" ) ;
217- return data ;
218- } ) ;
178+ this . fireDataEvent ( "addMessage" , content ) ;
179+ commentField . getChildControl ( "text-area" ) . setValue ( "" ) ;
219180 }
220- return Promise . reject ( ) ;
221181 } ,
222182
223183 __editComment : function ( ) {
@@ -263,7 +223,7 @@ qx.Class.define("osparc.conversation.AddMessage", {
263223 // This check only works if the project is directly shared with the user.
264224 // If it's shared through a group, it might be a bit confusing
265225 if ( userGid in studyData [ "accessRights" ] ) {
266- this . __addNotify ( userGid ) ;
226+ this . __doNotifyUser ( userGid ) ;
267227 } else {
268228 const msg = this . tr ( "This user has no access to the project. Do you want to share it?" ) ;
269229 const win = new osparc . ui . window . Confirmation ( msg ) . set ( {
@@ -280,7 +240,7 @@ qx.Class.define("osparc.conversation.AddMessage", {
280240 } ;
281241 osparc . store . Study . getInstance ( ) . addCollaborators ( studyData , newCollaborators )
282242 . then ( ( ) => {
283- this . __addNotify ( userGid ) ;
243+ this . __doNotifyUser ( userGid ) ;
284244 const potentialCollaborators = osparc . store . Groups . getInstance ( ) . getPotentialCollaborators ( )
285245 if ( userGid in potentialCollaborators && "getUserId" in potentialCollaborators [ userGid ] ) {
286246 const uid = potentialCollaborators [ userGid ] . getUserId ( ) ;
@@ -293,47 +253,13 @@ qx.Class.define("osparc.conversation.AddMessage", {
293253 }
294254 } ,
295255
296- __addNotify : function ( userGid ) {
297- const studyData = this . getStudyData ( ) ;
298- if ( ! studyData ) {
299- return ;
300- }
301-
302- const conversationId = this . getConversationId ( ) ;
303- if ( conversationId ) {
304- this . __postNotify ( userGid ) ;
305- } else {
306- // create new conversation first
307- osparc . store . ConversationsProject . getInstance ( ) . postConversation ( studyData [ "uuid" ] )
308- . then ( data => {
309- this . setConversationId ( data [ "conversationId" ] ) ;
310- this . __postNotify ( userGid ) ;
311- } ) ;
312- }
313- } ,
314-
315- __postNotify : function ( userGid ) {
256+ __doNotifyUser : function ( userGid ) {
316257 const studyData = this . getStudyData ( ) ;
317258 if ( ! studyData ) {
318259 return ;
319260 }
320261
321- if ( userGid ) {
322- const conversationId = this . getConversationId ( ) ;
323- osparc . store . ConversationsProject . getInstance ( ) . notifyUser ( studyData [ "uuid" ] , conversationId , userGid )
324- . then ( data => {
325- this . fireDataEvent ( "messageAdded" , data ) ;
326- const potentialCollaborators = osparc . store . Groups . getInstance ( ) . getPotentialCollaborators ( ) ;
327- if ( userGid in potentialCollaborators ) {
328- if ( "getUserId" in potentialCollaborators [ userGid ] ) {
329- const uid = potentialCollaborators [ userGid ] . getUserId ( ) ;
330- osparc . notification . Notifications . pushConversationNotification ( uid , studyData [ "uuid" ] ) ;
331- }
332- const msg = "getLabel" in potentialCollaborators [ userGid ] ? potentialCollaborators [ userGid ] . getLabel ( ) + this . tr ( " was notified" ) : this . tr ( "Notification sent" ) ;
333- osparc . FlashMessenger . logAs ( msg , "INFO" ) ;
334- }
335- } ) ;
336- }
262+ this . fireDataEvent ( "notifyUser" , userGid ) ;
337263 } ,
338264 /* NOTIFY USERS */
339265 }
0 commit comments