Incorrect unread message count

Despite calling the markAsRead method on all chats (I have two), Client.getUserUnread returns an incorrect value of 1. I wanted to be extra sure, that I’m not missing anything so I also did the same for evety single message in the chat.

Hello @jfiejka ,
Thanks for the details! Could you also share:

  • The platform and SDK version you’re using
  • Code snippets where you’re calling markAsRead() and Client.getUserUnread()

This will help us reproduce and check on our side.

I’m using ts-sdk 7.2.0 and this is how my code looks like

const unreadCount = ref(0);
const channels = ref([]);

const unsubscribeUnreadCount = Client.getUserUnread(({ data }) => {
  if (data) {
    unreadCount.value = data.unreadCount;
  }
});

const unsubscribeChannels = ChannelRepository.getChannels({
  membership: "member",
  limit: 30,
  isDeleted: false
}, ({ data }) => {

  if (data) {
    channels.value = data;
  }
});

In another place when I display a single chat:

const { id } = defineProps<{ id: string }>();

const chat = ref();

const unsubscribeChannel = ChannelRepository.getChannel(id, ({ error, data, loading }) => {
  if (error) console.error(error);
  if (data && !loading) {
    chat.value = data;

    if (data.subChannelsUnreadCount) {
      data.markAsRead();
    }
  }
});

The user for whom this error occurs has two chats and for both subChannelsUnreadCount and unreadCount is equal to 0 but getUserUnread somehow returns 1.

1 Like

Hello @jfiejka , Please make sure to call the unread sync function before retrieving unread counts.
Refer to this section in our docs for details:

Specifically, you should call the sync function first before using getChannels or getUserUnread, to ensure the count is accurate.

Let us know if the issue persists after that!

Unfortunately it didn’t help. It still returns incorrect value. Do you have any other suggestions?

Maybe there’s a way to check what message is unread?

Hello @jfiejka, Thank you for the update. If possible, could you please share your updated code as well? We’ll pass it to our team for further review.

const unreadCount = ref(0);
const channels = ref([]);


const subscribeUnreadCount = () =>
    Client.getUserUnread(({ data }) => {
        if (data) {
            unreadCount.value = data.unreadCount;
        }
    });

const subscribeChannels = () =>
    ChannelRepository.getChannels(
        {
            membership: 'member',
            limit: 30,
            isDeleted: false,
        },
        ({ data }) => {
            if (data) {
                channels.value = data;
            }
        }
    );

const init = async () => {
    await Client.startUnreadSync();
    unsubscribeChannels = subscribeChannels();
    unsubscribeUnreadCount = subscribeUnreadCount();
};

Here you go. But you didn’t answer my question, is there a way to get unread messages?

Thank you for sharing the code. Once our team has reviewed it, we’ll get back to you to confirm whether there are any alternative solutions. We appreciate your patience.

1 Like

Hey, do you have any updates?

Hello @jfiejka , Our team was unable to reproduce the issue on our side. However, we recommend using mark message as read instead of mark channel as read to ensure accurate unread counts.

Please refer to our documentation for more details:

Let us know if you need further assistance or have any additional questions.

I did both, marked channel as read and every message as read, I mentioned it in the first message. Didn’t help.

Also you still didn’t answer my question, how do I check what messages are unread?

Hello @jfiejka, our team is currently investigating and coordinating with your team via email. We’ll keep you updated there.

1 Like