@@ -27,6 +27,8 @@ qx.Class.define("osparc.study.Conversations", {
2727
2828 this . _setLayout ( new qx . ui . layout . VBox ( ) ) ;
2929
30+ this . __conversations = [ ] ;
31+
3032 this . fetchConversations ( studyData ) ;
3133 } ,
3234
@@ -138,6 +140,8 @@ qx.Class.define("osparc.study.Conversations", {
138140 } ,
139141
140142 members : {
143+ __conversations : null ,
144+
141145 _createChildControlImpl : function ( id ) {
142146 let control ;
143147 switch ( id ) {
@@ -156,6 +160,37 @@ qx.Class.define("osparc.study.Conversations", {
156160 return control || this . base ( arguments , id ) ;
157161 } ,
158162
163+ __listenToConversationWS : function ( ) {
164+ const socket = osparc . wrapper . WebSocket . getInstance ( ) ;
165+
166+ socket . on ( "conversation:message:created" , data => {
167+ if ( data ) {
168+ const projectId = data [ "projectId" ] ;
169+ const conversationId = data [ "conversationId" ] ;
170+ const messageId = data [ "messageId" ] ;
171+ console . log ( "Conversation message created" , projectId , conversationId , messageId ) ;
172+ }
173+ } , this ) ;
174+
175+ socket . on ( "conversation:message:update" , data => {
176+ if ( data ) {
177+ const projectId = data [ "projectId" ] ;
178+ const conversationId = data [ "conversationId" ] ;
179+ const messageId = data [ "messageId" ] ;
180+ console . log ( "Conversation message created" , projectId , conversationId , messageId ) ;
181+ }
182+ } , this ) ;
183+
184+ socket . on ( "conversation:message:deleted" , data => {
185+ if ( data ) {
186+ const projectId = data [ "projectId" ] ;
187+ const conversationId = data [ "conversationId" ] ;
188+ const messageId = data [ "messageId" ] ;
189+ console . log ( "Conversation message created" , projectId , conversationId , messageId ) ;
190+ }
191+ } , this ) ;
192+ } ,
193+
159194 fetchConversations : function ( studyData ) {
160195 const loadMoreButton = this . getChildControl ( "loading-button" ) ;
161196 loadMoreButton . setFetching ( true ) ;
@@ -192,20 +227,22 @@ qx.Class.define("osparc.study.Conversations", {
192227 this . fetchConversations ( studyData ) ;
193228 } ;
194229
230+ this . __conversations = [ ] ;
195231 if ( conversations . length === 0 ) {
196232 const noConversationTab = new osparc . conversation . Conversation ( studyData ) ;
197233 conversationPages . push ( noConversationTab ) ;
198234 noConversationTab . setLabel ( this . tr ( "new" ) ) ;
199235 noConversationTab . addListener ( "conversationDeleted" , ( ) => reloadConversations ( ) ) ;
200236 conversationsLayout . add ( noConversationTab ) ;
201237 } else {
202- conversations . forEach ( conversation => {
203- const conversationId = conversation [ "conversationId" ] ;
204- const conversationTab = new osparc . conversation . Conversation ( studyData , conversationId ) ;
205- conversationPages . push ( conversationTab ) ;
206- conversationTab . setLabel ( conversation [ "name" ] ) ;
207- conversationTab . addListener ( "conversationDeleted" , ( ) => reloadConversations ( ) ) ;
208- conversationsLayout . add ( conversationTab ) ;
238+ conversations . forEach ( conversationData => {
239+ const conversationId = conversationData [ "conversationId" ] ;
240+ const conversation = new osparc . conversation . Conversation ( studyData , conversationId ) ;
241+ this . __conversations . push ( conversation ) ;
242+ conversationPages . push ( conversation ) ;
243+ conversation . setLabel ( conversationData [ "name" ] ) ;
244+ conversation . addListener ( "conversationDeleted" , ( ) => reloadConversations ( ) ) ;
245+ conversationsLayout . add ( conversation ) ;
209246 } ) ;
210247 }
211248
0 commit comments