findPreferredMethodSunny static method

FutureOr<Contactable?> findPreferredMethodSunny(
  1. ISunnyContact contact,
  2. ContactableType? type
)

Implementation

static FutureOr<Contactable?> findPreferredMethodSunny(
    ISunnyContact contact, ContactableType? type) async {
  /// Look up a preferred contact method
  if (type != null) {
    final key =
        Contactable.preferredContactKey(contactId: contact.id!, type: type);
    final pref = await sunny.userPreferencesService.get(key);
    _log.info("Found pref for $key: $pref");
    if (pref.toString().isNotEmpty == true) {
      final found = Lists.firstOrNull(contact.contactables,
          filter: (c) => "$c" == "$pref");
      return found;
    }
  }

  return null;
}