I want to create scalable chat structure in realtime database to support both private and group chat
This is my current structure
.chats
.chat1
.type: private
.lastMessage
.users
.uid1: true
.uid2: true
.chat2
.type: group
.groupName
.groupImage
.lastMessage
.users
.uid1: true
.uid2: true
.uid2: true
... other users
.userChats
.uid1
.chat1:
.lastMessage
.lastMessageTime
...
.chat2:
.lastMessage
.lastMessageTime
.image
.groupName
...
When a user login to the app, I want to listen to his/her chat list and show them in a list. That is why I have userChats.
The problem here is that in a group chat we can have (for example) 50 users, and when any user send new message in the group, we need to update lastMessage field (in userChats) for every 50 users, so they can update their list immediately.
But this does not seem to be the right way to do it.
Is there any better structure to achieve this goal?

