Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Unread Count via Hook #479

Open
amcdnl opened this issue May 17, 2022 · 5 comments
Open

Get Unread Count via Hook #479

amcdnl opened this issue May 17, 2022 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@amcdnl
Copy link
Contributor

amcdnl commented May 17, 2022

Feature

It would be great to have the ability to get the unread count via the hook.

const { unreadCount } = useIntercom();

The primary driver behind the request is getting the notification count in a location that is not easy to get from the provider.

I handled this for now using my own context provider but it seems like the library could do this internally pretty easily.

@devrnt devrnt added the enhancement New feature or request label May 17, 2022
@devrnt
Copy link
Owner

devrnt commented May 23, 2022

Hi, thanks for the feature request.

We could possibly integrate this, however, this would mean that we deviate from the "1on1" IntercomJS API mapping. (I'm aware that we deviated from this "1on1" mapping in the past)

Anyway, how did you handle this in your own context provider?

@amcdnl
Copy link
Contributor Author

amcdnl commented May 23, 2022

I have a global context that I bind events on the IntercomProvider to.

onUnreadCountChange={setNotificationCount}

I can appreciate the sentiment of wanting to be 1:1 - This doesn't change the API - it just provides easier access.

@devrnt
Copy link
Owner

devrnt commented May 23, 2022

I have a global context that I bind events on the IntercomProvider to.

onUnreadCountChange={setNotificationCount}

I see, but this will result in being undefined until the event is triggered?

I can appreciate the sentiment of wanting to be 1:1 - This doesn't change the API - it just provides easier access.

Indeed. However, most of the time I can refer to official Intercom docs/fora to resolve an issue, which saves quite some time. Introducing some new functionality/extending the API is a bit more heavy lifting in the sense of answering the issues

@jotaRenan
Copy link

@devrnt, first of all, thank you so much for your work on this lib.

As to the topic in discussion, I believe that making this available through the hook wouldn't be directly breaking 1:1 compatibility because window.Intercom('onUnreadCountChange') can be called anywhere from within the app once the Intercom client is defined. The docs say:

This method allows you to register a function that will be called immediately when invoked, and again whenever the current number of unread messages changes.

So it is both an event-driven method as well as a procedural one. I just wish they made it possible to unregister a listener, but that doesn't seem to be the case.

@devrnt
Copy link
Owner

devrnt commented Apr 4, 2023

Thanks for the kind words, appreciate it!

As to the topic in discussion, I believe that making this available through the hook wouldn't be directly breaking 1:1 compatibility because window.Intercom('onUnreadCountChange') can be called anywhere from within the app once the Intercom client is defined. The docs say

I wasn't really referring to the fact that some additional logic (setting a count) would be introduced in this callback. I just didn't want to deviate from the 1:1 mapping by extending (returning the count) the API

Anyway, coming back to this, I feel like we should extend the API to return the count of unread messages. Would you like to pick this up? I would be happy to merge it. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants