This is an old question, but this answer could help someone.
Think about books stacked on top of each other. It has some initial height before adding a/few book(s). You just need subtract “old-height” from “new-height” to remain at the last known book index/positoin.
If you have added auto-scroll feature when a new message comes on chat page, you would need to avoid that from triggering somehow or you can quickly scroll to your previous scrolled location as soon as new message(s) come(s) to page. Look at solution using code