countUnreadMentions method

int countUnreadMentions()

Counts the number of unread messages mentioning the current user.

NOTE: The method relies on the Channel.messages list and doesn't do any API call. Therefore, the count might be not reliable as it relies on the local data.

Implementation

int countUnreadMentions() {
  final lastRead = currentUserRead?.lastRead;
  final userId = _channel.client.state.currentUser?.id;

  var count = 0;
  for (final message in messages) {
    if (_countMessageAsUnread(message) &&
        (lastRead == null || message.createdAt.isAfter(lastRead)) &&
        message.mentionedUsers.any((user) => user.id == userId) == true) {
      count++;
    }
  }
  return count;
}