I have a Flutter app where users can rent items from each other with Firestore RTDB. rental documents have a chat collection that stores the chats between two users:
rentals (collection)
rental_1 (document)
chat (collection)
message_timestamp_1 (document)
message_timestamp_2 (document)
users (array, document field)
user_id_1 (String)
user_id_2 (String)
rental_2 (document)
chat (collection)
message_timestamp_1 (document)
etc.
I have a page in my app that is a listview of all the rentals that the user is involved in (simple arrayContains on the users field). Basically, I want to show all the chats the user is involved in. However, I would like to order this list by most recent chat (like any normal messaging app). Is there a way to achieve this without having to store and update a lastUpdated field in the rental document (thus creating two writes each time a message is sent)?