@@ -28,7 +28,6 @@ qx.Class.define("osparc.support.Conversations", {
2828 this . __openConversationId = openConversationId ;
2929
3030 this . __fetchConversations ( ) ;
31- this . __listenToConversationWS ( ) ;
3231 } ,
3332
3433 statics : {
@@ -73,66 +72,6 @@ qx.Class.define("osparc.support.Conversations", {
7372 return control || this . base ( arguments , id ) ;
7473 } ,
7574
76- __listenToConversationWS : function ( ) {
77- this . __wsHandlers = [ ] ;
78-
79- const socket = osparc . wrapper . WebSocket . getInstance ( ) ;
80-
81- [
82- this . self ( ) . CHANNELS . CONVERSATION_CREATED ,
83- this . self ( ) . CHANNELS . CONVERSATION_UPDATED ,
84- this . self ( ) . CHANNELS . CONVERSATION_DELETED ,
85- ] . forEach ( eventName => {
86- const eventHandler = conversation => {
87- if ( conversation ) {
88- switch ( eventName ) {
89- case this . self ( ) . CHANNELS . CONVERSATION_CREATED :
90- if ( ! conversation [ "projectId" ] ) {
91- this . __addConversation ( conversation ) ;
92- }
93- break ;
94- case this . self ( ) . CHANNELS . CONVERSATION_UPDATED :
95- this . __updateConversationName ( conversation ) ;
96- break ;
97- case this . self ( ) . CHANNELS . CONVERSATION_DELETED :
98- this . __removeConversationItem ( conversation [ "conversationId" ] ) ;
99- break ;
100- }
101- }
102- } ;
103- socket . on ( eventName , eventHandler , this ) ;
104- this . __wsHandlers . push ( { eventName, handler : eventHandler } ) ;
105- } ) ;
106-
107- [
108- this . self ( ) . CHANNELS . CONVERSATION_MESSAGE_CREATED ,
109- this . self ( ) . CHANNELS . CONVERSATION_MESSAGE_UPDATED ,
110- this . self ( ) . CHANNELS . CONVERSATION_MESSAGE_DELETED ,
111- ] . forEach ( eventName => {
112- const eventHandler = message => {
113- if ( message ) {
114- const conversationId = message [ "conversationId" ] ;
115- const conversationPage = this . __getConversationItem ( conversationId ) ;
116- if ( conversationPage ) {
117- switch ( eventName ) {
118- case this . self ( ) . CHANNELS . CONVERSATION_MESSAGE_CREATED :
119- conversationPage . addMessage ( message ) ;
120- break ;
121- case this . self ( ) . CHANNELS . CONVERSATION_MESSAGE_UPDATED :
122- conversationPage . updateMessage ( message ) ;
123- break ;
124- case this . self ( ) . CHANNELS . CONVERSATION_MESSAGE_DELETED :
125- conversationPage . deleteMessage ( message ) ;
126- break ;
127- }
128- }
129- }
130- } ;
131- socket . on ( eventName , eventHandler , this ) ;
132- this . __wsHandlers . push ( { eventName, handler : eventHandler } ) ;
133- } ) ;
134- } ,
135-
13675 __getConversationItem : function ( conversationId ) {
13776 return this . __conversationListItems . find ( conversation => conversation . getConversationId ( ) === conversationId ) ;
13877 } ,
@@ -143,8 +82,8 @@ qx.Class.define("osparc.support.Conversations", {
14382
14483 osparc . store . ConversationsSupport . getInstance ( ) . getConversations ( )
14584 . then ( conversations => {
146- if ( conversations . length ) {
147- conversations . forEach ( conversation => this . __addConversation ( conversation ) ) ;
85+ if ( Object . values ( conversations ) . length ) {
86+ Object . values ( conversations ) . forEach ( conversation => this . __addConversation ( conversation ) ) ;
14887 if ( this . __openConversationId ) {
14988 const conversationsLayout = this . getChildControl ( "conversations-layout" ) ;
15089 const conversation = conversationsLayout . getSelectables ( ) . find ( c => c . getConversationId ( ) === this . __openConversationId ) ;
@@ -161,17 +100,17 @@ qx.Class.define("osparc.support.Conversations", {
161100 } ) ;
162101 } ,
163102
164- __addConversation : function ( conversationData ) {
103+ __addConversation : function ( conversation ) {
165104 // ignore it if it was already there
166- const conversationId = conversationData [ "conversationId" ] ;
105+ const conversationId = conversation . getConversationId ( ) ;
167106 const conversationItemFound = this . __getConversationItem ( conversationId ) ;
168107 if ( conversationItemFound ) {
169108 return null ;
170109 }
171110
172111 const conversationListItem = new osparc . support . ConversationListItem ( ) ;
173- conversationListItem . setConversationId ( conversationData [ "conversationId" ] ) ;
174- conversationListItem . addListener ( "tap" , ( ) => this . fireDataEvent ( "openConversation" , conversationData [ " conversationId" ] ) , this ) ;
112+ conversationListItem . setConversation ( conversation ) ;
113+ conversationListItem . addListener ( "tap" , ( ) => this . fireDataEvent ( "openConversation" , conversationId , this ) ) ;
175114
176115 const conversationsLayout = this . getChildControl ( "conversations-layout" ) ;
177116 conversationsLayout . add ( conversationListItem ) ;
@@ -180,45 +119,5 @@ qx.Class.define("osparc.support.Conversations", {
180119
181120 return conversationListItem ;
182121 } ,
183-
184- __removeConversationItem : function ( conversationId , changeSelection = false ) {
185- const conversationItem = this . __getConversationItem ( conversationId ) ;
186- if ( conversationItem ) {
187- const conversationsLayout = this . getChildControl ( "conversations-layout" ) ;
188- if ( conversationsLayout . indexOf ( conversationItem ) > - 1 ) {
189- conversationsLayout . remove ( conversationItem ) ;
190- }
191- this . __conversationListItems = this . __conversationListItems . filter ( c => c !== conversationItem ) ;
192- const conversationPages = conversationsLayout . getSelectables ( ) ;
193- if ( conversationPages . length ) {
194- if ( changeSelection ) {
195- // change selection to the first conversation
196- conversationsLayout . setSelection ( [ conversationPages [ 0 ] ] ) ;
197- }
198- }
199- }
200- } ,
201-
202- // it can only be renamed, not updated
203- __updateConversationName : function ( conversationData ) {
204- const conversationId = conversationData [ "conversationId" ] ;
205- const conversationPage = this . __getConversationItem ( conversationId ) ;
206- if ( conversationPage ) {
207- conversationPage . renameConversation ( conversationData [ "name" ] ) ;
208- }
209- } ,
210-
211- // overridden
212- destroy : function ( ) {
213- const socket = osparc . wrapper . WebSocket . getInstance ( ) ;
214- if ( this . __wsHandlers ) {
215- this . __wsHandlers . forEach ( ( { eventName } ) => {
216- socket . removeSlot ( eventName ) ;
217- } ) ;
218- this . __wsHandlers = null ;
219- }
220-
221- this . base ( arguments ) ;
222- } ,
223122 } ,
224123} ) ;
0 commit comments