search method

  1. @override
Paginated<UserId, RxUser> search({
  1. UserNum? num,
  2. UserName? name,
  3. UserLogin? login,
  4. ChatDirectLinkSlug? link,
})
override

Searches Users by the given criteria.

Implementation

@override
Paginated<UserId, RxUser> search({
  UserNum? num,
  UserName? name,
  UserLogin? login,
  ChatDirectLinkSlug? link,
}) {
  Log.debug('search($num, $name, $login, $link)', '$runtimeType');

  if (num == null && name == null && login == null && link == null) {
    return PaginatedImpl();
  }

  Pagination<RxUser, UsersCursor, UserId>? pagination;
  if (name != null) {
    pagination = Pagination(
      perPage: 30,
      provider: GraphQlPageProvider(
        fetch: ({after, before, first, last}) {
          return searchByName(name, after: after, first: first);
        },
      ),
      onKey: (RxUser u) => u.id,
    );
  }

  final List<RxUser> users =
      this.users.values
          .where(
            (u) =>
                (num != null && u.user.value.num == num) ||
                (name != null &&
                    u.user.value.name?.val.toLowerCase().contains(
                          name.val.toLowerCase(),
                        ) ==
                        true),
          )
          .toList();

  Map<UserId, RxUser> toMap(RxUser? u) => {if (u != null) u.id: u};

  return PaginatedImpl(
    pagination: pagination,
    initial: [
      {for (var u in users) u.id: u},
      if (num != null) searchByNum(num).then(toMap),
      if (login != null) searchByLogin(login).then(toMap),
      if (link != null) searchByLink(link).then(toMap),
    ],
  );
}