Hello,
I’m building an online marketplace for multiple users.
I have a messages page, and set up a little notification dot to show when a message is unread. My question is, how can I send this data to my sticky header so even when I’m on different pages I can see how many unread messages I have.
User A sends a message by starting a Chat data type with them, but my notification is built on messages which have a “From” and an “isRead”. Is there a way to do 2 “search fors” so I can search for messages containing Current User & ones that are “From <> Current User” and “isRead = no”?
Pics of how it works and where I’m stuck
Should the notification show the number of unread messages or the number of chats with unread messages? For example, I have 2 chats with unread messages. One chat has 1 unread message. The other chat has 5 unread messages. Should the header notification show 2 or 6?
Edit: thanks to your question I was able to figure it out! I added a “From” and “isRead” to my Chats and just went with displaying the unread number of chats, which makes more sense anyway.
My only other question is: everything updates in real time when I’m on the messages page. i.e. if I get a new message, the header shows I have a new unread message. However, if I’m on any other page, it doesn’t show up until I refresh. Any thoughts?
“From” is a property of messages, not chats. To a lesser extent, the same is true for “isRead”
With your previous configuration of the two datatypes you could achieve this by doing the following:
Do a search for messages where from <> current user and isRead=no: each item’s chat: unique elements: count
This solution assumes that your privacy rules are set up correctly and the current user does not have access to other messages, but based on your previous screenshots it seems that’s not the case.
A good approach is to have both users on the message data type so you can configure a privacy rule that allows the current user to search for messages where fieldX contains current user.