File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
services/static-webserver/client/source/class/osparc/conversation Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -242,8 +242,15 @@ qx.Class.define("osparc.conversation.Conversation", {
242242 return ;
243243 }
244244
245- // Add the message in the messages array
246- this . __messages . push ( message ) ;
245+ // determine insertion index for most‐recent‐first order
246+ const newTime = new Date ( message [ "created" ] ) ;
247+ let insertAt = this . __messages . findIndex ( m => new Date ( m [ "created" ] ) < newTime ) ;
248+ if ( insertAt === - 1 ) {
249+ insertAt = this . __messages . length ;
250+ }
251+
252+ // Insert the message in the messages array
253+ this . __messages . splice ( insertAt , 0 , message ) ;
247254
248255 // Add the UI element to the messages list
249256 let control = null ;
@@ -256,7 +263,8 @@ qx.Class.define("osparc.conversation.Conversation", {
256263 break ;
257264 }
258265 if ( control ) {
259- this . __messagesList . addAt ( control , 0 ) ;
266+ // insert into the UI at the same position
267+ this . __messagesList . addAt ( control , insertAt ) ;
260268 }
261269
262270 this . __updateMessagesNumber ( ) ;
You can’t perform that action at this time.
0 commit comments