I’m integrating Discourse into another app and am trying to surface whether someone has any new chat activity pending via the API. If there are any new messages I just want to show a red badge.
More specifically, I’m trying to leverage whatever preferences the customer has set in their “chat_header_indicator_preference” and at the moment I have that set to “all_new” which I think should show any new messages in channels I belong to as well as unread mentions/DMs.
I was hoping that by going to /session/current.json I would be able to see something there I can use for this but haven’t seen anything useful.
Is there any API endpoint out there I can use to understand if there are new messages based on a user’s chat_header_indicator_preference ??
thanks @joffreyjaffeux. I’m taking a look at /chat/api/me/channels and do see under tracking that I can go through all the channels and see if the unread_count for any of the channels > 0 which is helpful.
But this doesnt seem to have anything to do with a user’s chat_header_indicator_preference and also doesnt tell me if there have been any DMs or mentions for the user.
In theory I can try to recreate the logic of chat_header_indicator_preference by first checking if the user has that set to “all_new” and if so, check to see if any unread_counts for their channels are > 0 and if those are all 0 then check for unread DMs/mentions.
But I’m hoping there might be a better way to do it… (and I’m also not sure how to get that second piece for unread DMs/mentions).
Any help / guidance would be very much appreciated.
A user would only expect to see a red badge for new activity based on this preference. If someone has “All New Messages” set I would expect that this means a badge would show up if there is any new activity in any of the channels they are in or they’ve had a mention or DM.
You showed me how to loop through all the channels and see if there are unread messages but 1) that has nothing to do with this preference
2) that wouldnt help me understand if they have any Direct Messages or Mentions
Ideally I was hoping to find an endpoint that would help me show a badge based on the customer’s chat_header_indicator_preference.
If that is not possible then it sounds like I would need to first check if they have unreads in the “tracking section” of chat/api/me/channels, and then check a second location to see if they had DMs/mention.
I don’t know where that second location would be but was hoping someone else on here could point me in the right direction.
In tracking is there any way to know which channels are DM and which are public?
If a user has chat_header_indicator_preference set to “Direct Messages and Mentions” I wouldnt want to show a badge for regular new messages in a channel.