I'm writing a chat app that uses the multiplatform...
# squarelibraries
t
I'm writing a chat app that uses the multiplatform version of paging3. Two things I'm trying to figure out. 1.) Assuming the list of chat messages is loaded and I receive a push event that indicates a new message has been added to the thread, what is the proper way to refresh what the user sees? Fetching the new data and storing it in the local DB doesn't trigger a refresh. I'm using a remote mediator. I'm not sure when I am supposed to call invalidate() on the paging source instance. 2.) Is there a way to nicely add the new message to the list? Maybe with an animation, instead of reloading the whole page of results?
s
your mediator will have to invalidate the paging source if it detects that the persisted data-set has changed. if you're using sqldelight's paging3 extension this should happen automatically: https://github.com/cashapp/sqldelight/blob/6fe5db182f11515c1d716a8ee16376fd8ebfd36[…]monMain/kotlin/app/cash/sqldelight/paging3/QueryPagingSource.kt
Is there a way to nicely add the new message to the list? Maybe with an animation, instead of reloading the whole page of results?
this is up to your UI layer. if it receives new items, it should nicely animate them in. if you're using RecyclerView, an adapter with DiffUtil will do this for you. if you're using compose ui, you're out of luck because item entry/exit animations aren't supported yet.
t
Thanks for the info. I am using compose, so I guess I’ll wait for the animation. 😃
👍 1