getUnreadMembers method

List<Member> getUnreadMembers(
  1. BaseMessage message,
  2. {bool includeAllMembers = false}
)

Gets the member list who haven't read the given message.

If includeAllMembers is set false, this list excludes the current logged-in User and the sender of the message. Returns the list of members who haven't read the message.

Implementation

List<Member> getUnreadMembers(BaseMessage message,
    {bool includeAllMembers = false}) {
  sbLog.i(StackTrace.current,
      'messageId: ${message.messageId}, includeAllMembers: $includeAllMembers');

  if (message is AdminMessage) return [];
  if (isSuper) return [];

  return members.where((m) {
    if (!includeAllMembers && m.isCurrentUser) return false;
    if (message.sender?.userId == m.userId) return false;
    final readStatus = chat.channelCache.find<ReadStatus>(
      channelKey: channelUrl,
      key: m.userId,
    );
    if (readStatus == null) return true;
    return readStatus.timestamp < message.createdAt;
  }).toList();
}