@@ -83,29 +83,21 @@ qx.Class.define("osparc.support.Conversation", {
8383 }
8484 osparc . store . ConversationsSupport . getInstance ( ) . postConversation ( extraContext )
8585 . then ( data => {
86- let prePostMessagePromise = new Promise ( ( resolve ) => resolve ( ) ) ;
87- let isBookACall = false ;
88- // make these checks first, setConversation will reload messages
89- if (
90- this . _messages . length === 1 &&
91- this . _messages [ 0 ] [ "systemMessageType" ] &&
92- this . _messages [ 0 ] [ "systemMessageType" ] === osparc . support . Conversation . SYSTEM_MESSAGE_TYPE . BOOK_A_CALL
93- ) {
94- isBookACall = true ;
95- }
86+ // clone first, it will be reset when setting the conversation
87+ const bookACallInfo = this . __bookACallInfo ? Object . assign ( { } , this . __bookACallInfo ) : null ;
9688 const newConversation = new osparc . data . model . Conversation ( data ) ;
9789 this . setConversation ( newConversation ) ;
98- if ( isBookACall ) {
90+ let prePostMessagePromise = new Promise ( ( resolve ) => resolve ( ) ) ;
91+ if ( bookACallInfo ) {
9992 // add a first message
10093 let msg = "Book a Call" ;
101- if ( this . __bookACallInfo ) {
102- msg += `\n- Topic: ${ this . __bookACallInfo [ "topic" ] } ` ;
103- if ( "extraInfo" in this . __bookACallInfo ) {
104- msg += `\n- Extra Info: ${ this . __bookACallInfo [ "extraInfo" ] } ` ;
94+ if ( bookACallInfo ) {
95+ msg += `\n- Topic: ${ bookACallInfo [ "topic" ] } ` ;
96+ if ( "extraInfo" in bookACallInfo ) {
97+ msg += `\n- Extra Info: ${ bookACallInfo [ "extraInfo" ] } ` ;
10598 }
10699 }
107100 prePostMessagePromise = this . __postMessage ( msg ) ;
108- this . __bookACallInfo = null ;
109101 // rename the conversation
110102 newConversation . renameConversation ( "Book a Call" ) ;
111103 }
@@ -125,6 +117,7 @@ qx.Class.define("osparc.support.Conversation", {
125117 _applyConversation : function ( conversation ) {
126118 this . base ( arguments , conversation ) ;
127119
120+ this . __bookACallInfo = null ;
128121 this . __populateShareProjectCheckbox ( ) ;
129122 } ,
130123
@@ -196,15 +189,6 @@ qx.Class.define("osparc.support.Conversation", {
196189 addSystemMessage : function ( type ) {
197190 type = type || osparc . support . Conversation . SYSTEM_MESSAGE_TYPE . ASK_A_QUESTION ;
198191
199- const now = new Date ( ) ;
200- const systemMessage = {
201- "conversationId" : null ,
202- "created" : now . toISOString ( ) ,
203- "messageId" : `system-${ now . getTime ( ) } ` ,
204- "modified" : now . toISOString ( ) ,
205- "type" : "MESSAGE" ,
206- "userGroupId" : "system" ,
207- } ;
208192 let msg = null ;
209193 const greet = "Hi " + osparc . auth . Data . getInstance ( ) . getUserName ( ) + ",\n" ;
210194 switch ( type ) {
@@ -222,8 +206,16 @@ qx.Class.define("osparc.support.Conversation", {
222206 break ;
223207 }
224208 if ( msg ) {
225- systemMessage [ "content" ] = msg ;
226- systemMessage [ "systemMessageType" ] = type ;
209+ const now = new Date ( ) ;
210+ const systemMessage = {
211+ "conversationId" : null ,
212+ "content" : msg ,
213+ "created" : now . toISOString ( ) ,
214+ "messageId" : `system-${ now . getTime ( ) } ` ,
215+ "modified" : now . toISOString ( ) ,
216+ "type" : "MESSAGE" ,
217+ "userGroupId" : "system" ,
218+ } ;
227219 this . addMessage ( systemMessage ) ;
228220 }
229221 } ,
0 commit comments