getUserUnread()

Hi there,

I’m using the below effect to monitor unread for my logged in user.

I’ve created the below two functions to handle marking all messages unread upon opening up a specific page.

This works to the extent that it clears down the unread messages for the channel I am looking at.

The problem is, when the logged in user sends a message to that channel, I receive an Unread count of 1 (the message I have just sent).

I assumed that the unread count would not include this as it was generated by the logged in user?

Is this correct behaviour? If so what is the recommended way of handling?

Thanks.

  const handleMarkChannelAsRead = (subChannelId: string) => {
    //Async?
    const messagesByChannel = messages.filter(
      (msg) => msg.subChannelId === subChannelId
    )

    messagesByChannel.map((msg) => msg.markRead())
  }
  useEffect(() => {
    if (isConnected) {
      const handleLiveObject = (
        liveObject: Amity.LiveObject<Amity.UserUnread | undefined>
      ) => {
        if (liveObject.data) {
          const { unreadCount } = liveObject.data

          setUserUnreadCount(unreadCount)
        }
      }

      AmityClient.getUserUnread(handleLiveObject)
    }
  }, [isConnected])

Hello, may I know your sdk version as well, please?

Hi there,

Sure… SDK version is 6.21.0 Thanks!

Thank you, we will pass it to the team to further check. Will keep you posted on the updates.

1 Like

Hi, I still can’t reproduce this issue. May I ask have you already call Client.enableUnreadCount(); after you call login SDK?

Hi there,

Yes we do call that.

Let me try and reproduce in a fresh environment.

Hi there,

Have just reproduced in very basic POC environment.

1.Create channel.
2.Create subchannel.
3. Log in.
4. Send message.

Logged in user sends message to conversation subchannel.
getUserUnread() for logged in user shows the users own message as “unread”.

Could you share with me the env you have used to reproduce and see if I have missed anything?

Thanks.

Hello, please refer to this sample project: GitHub - AmityCo/Amity-Chat-UIKit-React-Native-OpenSource: Amity Social Cloud offers Chat and Social SDKs to streamline app development. Dive into our UI Kits and sample apps in our repositories to spark your creativity. To learn more, visit amity.co.

Hi,

That project makes no use of getUserUnread() and just uses unreadCount property of the channel?

I have the same issues when I try to use unreadCount on the subchannel and channel.

Also, is a react native app which is not what I’m using. Just using typescript in a basic react app.

amityco/ts-sdk: 6.21.0

When you call getUserUnread , did you use the same userId to log in?

Yes. We are using the same user account when we call getUserUnread.

If is worth noting that if you can mark the message as read but there is then a period of time in between the unread message being detected and it then being marked as read which is jarring for the user.

Can I confirm that default behaviour is that logged in users own messages are not initially classed as unread from the perspective of the sending user?

Hi there, has there been any update on this?

Hello @skullicious , We have addressed the issue you reported in version 6.23.0. Please check again, and if the problem persists, feel free to notify us.