Need help showing a badge to users when they have an unread message. I have a custom event running every 3 secs on the page, to check if a user has any unread messages.
I have 2x data types relevant to this: chatThreads and chatMessages
chatThreads has a ‘Last Message’ field of type ‘chatMessages’
chatMessages has a ‘Seen By’ field of type ‘list of users’ (I have an event that adds a user to this list when they view a message
I run the following custom event, but am having trouble with the filter - what is the right way to see if the current user is not in the ‘seen by’ on each ‘last message’ in each ‘chat thread’
In my apps I would have a single field on the message that is yes/no and default is set to no to represent if the message is read or not.
I make assumptions, that if the user who receives the message has the conversation open than the message would be read, and if that user who receives the message does not have the conversation open, than the message is unread.
On my inbox reusable element that allows a user to select a conversation to read, when they open it, I run a make changes to list of things, for all messages in which they are the receiver, whose ‘read’ field value is ‘no’ to update to ‘yes’ as an assumption is that if they click to view the conversation, all messages will be read.
I have a conditional workflow trigger, that when the URL parameter of conversation is not empty (ie: user is reading the conversation) and the list of messages filtered (filter to receiver is current user and read is no) to change those messages to ‘read’ field value of ‘yes’.
This way, by default when a message is sent, it is not read, and if the conversation is open, the message will switch to read yes, and when a conversation is opened at some later point the message is switched to read yes on open of the conversation.
You do not need to have chatThreads because you can just use the data from chatMessages.
Thanks - I should have mentioned this is actually a chat, not a typical inbox/messages. There could be more than 2 people in the chat.
So how would I get the Count in the scenario I’ve mentioned? Looking at my test data/scenario, which I’ve confirmed is all set up correctly, my user should be showing as 1 unread.
Is a combination of :filtered and Advanced not the right thing to do?
I have no idea why, but it seemingly works perfectly now. Not sure if it was cacheing or what, but I have it set up how I had it in the original screenshot above, and it works perfectly!
Instead of a yes/no field, make a it a list of users and add the current user to the list in the same manner as I explained for changing the yes/no fields. Basically the same way you are saving it now, except instead of needing to do something every 3 seconds that causes you to search your database every 3 seconds that cost a lot of WUs…I also do not see in the screen shots how you save from the custom state if the user is in that list or not.
Glad you got your thing working though, but if you want to not overspend and add overhead to the app, consider altering the do every 3 second approach.
I don’t think so because then you are needing to update the user data type as well and referencing it as well instead of the single data type of chat_message