0

I'm getting a list of the 200 most recent messages in my publish function, like so:

Messages.find({
    room: roomname
}, {
    sort: {time : -1}, 
    limit: 200 
}),

I know this makes the newest first, but I want the oldest first, so when I do the find on the client, I sort the other way:

messages: Messages.find({}, {sort: {time: 1}})

Everything shows up fine except for when I enter a new message. It gets inserted at the end of the list that has all the old messages. After the insert makes its round trip to the server, it jumps to the correct end of the list.

If I take out the limit and client-side sorting, and just give the client all the messages in the correct order, this issue does not occur.

How can I make the message show in the correct place while during the latency compensation?

Matt
  • 386
  • 3
  • 9
  • What do you mean "enter a new message" before it goes to the server? Can you give some more details on your insert? – womp Jul 16 '15 at 16:46
  • 1
    @matt How does the `time` field get added to the document? – David Weldon Jul 16 '15 at 16:46
  • wow ... I didn't think to check the insert. I completely forgot that I moved setting the time to the server to get rid of differences in time between clients. I put the time back there and the issue is gone. Thanks to both of you for your help! – Matt Jul 16 '15 at 16:57

0 Answers0