Solution for Building a group chat with notifications logic
is Given Below:
I built a group chat app using react-native (expo) for fron-end and nodejs servers for the back-end. 1st server is responsible for handling mysql queries and 2nd is responsible for handling the socket.io connection and storing messages in mongodb.
Im am trying to find an optimal way of handling notifications for each message. The way i have it set up at the moment is the following:
- there are 2 types of chat groups (public and private)
- each group is a row in mysql ‘group’ table with columns: group_id, admin_id, users (json-type array), tokens (json-type array), waiting_users (json-type array) , waiting_tokens (json-type array).
- if a user joins a public group, his user_id and notification_token are stored in ‘users’ and ‘tokens’ json-type array columns of mysql db.
- I then extract the tokens and loop over them to send notifications to users in the group chat upon new message.
- If a user wants to join a private group, his token goes to the waiting_tokens array, and when an admin confirms the user, it gets moved to the tokens array.
My question is: Am i doing this right? or is there a completely different logic for handling notification subscriptions for use cases like mine? It just seems that what im doing it too bulky.
I can elaborate if something is unclear.
Thank you for your help in advance.