firstUnread property

  1. @override
Rx<ChatItem>? get firstUnread
override

Returns the first ChatItem unread by the currently authenticated MyUser in this chat.

Implementation

@override
Rx<ChatItem>? get firstUnread {
  Log.debug('get firstUnread', '$runtimeType($id)');

  if (chat.value.unreadCount != 0) {
    PreciseDateTime? myRead =
        chat.value.lastReads.firstWhereOrNull((e) => e.memberId == me)?.at;

    if (myRead != null) {
      return messages.firstWhereOrNull(
        (e) => myRead.isBefore(e.value.at) && e.value.author.id != me,
      );
    } else {
      return messages.firstOrNull;
    }
  }

  return null;
}