getTitle method

String getTitle(
  1. Iterable<RxUser> users,
  2. UserId? me
)

Returns text represented title of this Chat.

Implementation

String getTitle(Iterable<RxUser> users, UserId? me) {
  String title = 'dot'.l10n * 3;

  switch (kind) {
    case ChatKind.monolog:
      title = name?.val ?? 'label_chat_monolog'.l10n;
      break;

    case ChatKind.dialog:
      final String? name =
          users.firstWhereOrNull((u) => u.id != me)?.title ??
          members.firstWhereOrNull((e) => e.user.id != me)?.user.title;
      if (name != null) {
        title = name;
      }
      break;

    case ChatKind.group:
      if (name == null) {
        final Iterable<String> names;

        if (users.length < membersCount && users.length < 3) {
          names = members.take(3).map((e) => e.user.title);
        } else {
          names = users.take(3).map((e) => e.title);
        }

        title = names.join('comma_space'.l10n);
        if (membersCount > 3) {
          title += 'comma_space'.l10n + ('dot'.l10n * 3);
        }
      } else {
        title = name!.val;
      }
      break;

    case ChatKind.artemisUnknown:
      // No-op.
      break;
  }

  return title;
}