Need guidance on how to make my chat functionality, please help!

Hi guys, I'm trying to create a chat app and i've ran into some trouble.

When inside a chat, getting new messages into the UI is fine and works great. It's really simple, just listen to the conversationMessages table and filter by the conversationId that we are currently on - Great stuff ✅

The problem I have is the Inbox component. It needs to show:
  • All current conversations you're involved in
  • The latest message sent to each chat
  • Whether it has been read or not by the user (I compare conversationMembers.lastRead with the latest conversationMessages.createdAt
  • Needs to update in realtime
    • if im on my inbox screen and get a new message, I expect that chat to move up to 1st place and show the new message.
I have created a view called conversationsView that gets all the above data ready for me and it works great.

However, I failed to realise you cannot use realtime on views 😔 so my plan has failed on the last hurdle. When a new message is sent, the inbox is not updated in realtime.

Does anyone see a way of achieving this? Im quite new to SQL.

I've attached an image of my db design and chat component.

I've spent 3 days trying to figure out a way of doing this 😆 If anyone has a good method of achieving this please put me out of my misery haha.
Untitled_2.png
Was this page helpful?