Unread messages count

Description

Currently I’m working on an implementation of rocket.chat for a web app using API/websocket, but I have a problem with the unread messages count for a user. The current behaviour is when a user writes in a room, every other user gets the message (through the subscription in the websocket) and when an admin modifies the room every user gets the message as well. That’s ok from a user perspective. The problem I see is when a user gets the initial subscription (api/v1/subscriptions.get), the counters are always 0, the only thing that informs that there are unread messages is the alert property on the response, but it doesn’t have the same behaviour for users’ messages and for room changes. If there are users’ messages it responds with alert = true, but when there are only changes in the room alert stays false. The room changes are considered as messages when I call api/v1/groups.messages but not for the unread counters (api/v1/groups.counters or api/v1/subscriptions.get), Is this a intended behaviour?

Server Setup Information

  • Version of Rocket.Chat Server: 3.18.1
  • Operating System: Windows 10
  • Deployment Method: docker
  • Number of Running Instances: 1
  • DB Replicaset Oplog:
  • NodeJS Version: v12.22.1
  • MongoDB Version: 4.0.27 / mmapv1 (oplog Enabled)
  • Proxy: no
  • Firewalls involved:

Any additional Information

In Administration → General → Unread Count is set to All messages

FWIW, I was able to manually grab a user’s unread message count by doing the following:

const subscriptions = Subscriptions.findByUserId(user._id).fetch();
const { unread, alerts } = subscriptions.reduce(
    ({ unread, alerts }, subscription) =>
        ({ unread: unread + subscription.unread, alerts: subscription.alert === true ? true : alerts }),
    { unread: 0, alerts: false },
);

After some research in this issue, I confirm that in a newly created channel that only has messages related with room changes or users added, the groups.counters response has the correct count of messages, but after any user posts a message on the channel the counters start to count only the users’ messages and not the room changes