Skip to content

Commit de78d94

Browse files
committed
insert message in the right place
1 parent 776288e commit de78d94

File tree

1 file changed

+11
-3
lines changed
  • services/static-webserver/client/source/class/osparc/conversation

1 file changed

+11
-3
lines changed

services/static-webserver/client/source/class/osparc/conversation/Conversation.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)