@@ -22,12 +22,13 @@ qx.Class.define("osparc.study.Conversations", {
2222 /**
2323 * @param studyData {Object} Study Data
2424 */
25- construct : function ( studyData ) {
25+ construct : function ( studyData , openConversationId = null ) {
2626 this . base ( arguments ) ;
2727
2828 this . _setLayout ( new qx . ui . layout . VBox ( ) ) ;
2929
3030 this . __conversations = [ ] ;
31+ this . __openConversationId = openConversationId ;
3132
3233 this . set ( {
3334 studyData,
@@ -51,7 +52,7 @@ qx.Class.define("osparc.study.Conversations", {
5152 PROJECT_ANNOTATION : "PROJECT_ANNOTATION" ,
5253 } ,
5354
54- popUpInWindow : function ( studyData ) {
55+ popUpInWindow : function ( studyData , openConversationId = null ) {
5556 const conversations = new osparc . study . Conversations ( studyData ) ;
5657 const title = qx . locale . Manager . tr ( "Conversations" ) ;
5758 const viewWidth = 600 ;
@@ -161,6 +162,7 @@ qx.Class.define("osparc.study.Conversations", {
161162 } ,
162163
163164 members : {
165+ __openConversationId : null ,
164166 __conversations : null ,
165167 __newConversationButton : null ,
166168 __wsHandlers : null ,
@@ -259,7 +261,17 @@ qx.Class.define("osparc.study.Conversations", {
259261 osparc . data . Resources . fetch ( "conversations" , "getConversationsPage" , params )
260262 . then ( conversations => {
261263 if ( conversations . length ) {
264+ // Sort conversations by created date, newest first
265+ conversations . sort ( ( a , b ) => new Date ( b . created ) - new Date ( a . created ) ) ;
262266 conversations . forEach ( conversation => this . __addConversationPage ( conversation ) ) ;
267+ if ( this . __openConversationId ) {
268+ const conversationsLayout = this . getChildControl ( "conversations-layout" ) ;
269+ const conversation = conversationsLayout . getSelectables ( ) . find ( c => c . getConversationId ( ) === this . __openConversationId ) ;
270+ if ( conversation ) {
271+ conversationsLayout . setSelection ( [ conversation ] ) ;
272+ }
273+ this . __openConversationId = null ; // reset it so it does not open again
274+ }
263275 } else {
264276 this . __addTempConversationPage ( ) ;
265277 }
0 commit comments