> Not sure if I'm understanding you...when the user scrolls up, the old chats need to be re-shown. I don't see how tying it to the onMessage event will accomplish that.

when new messages are received, calculate which messages are likely outside of the viewable area and hide them. window scrolling is a high volume event and will consume vast resources—only use it when necessary ie. when the user scrolls _back_ to view old messages.