getContactList method
contact list of a given pubkey, not intended to get followers
Implementation
Future<ContactList?> getContactList(
String pubKey, {
/// skips the cache
bool forceRefresh = false,
int idleTimeout = Requests.DEFAULT_QUERY_TIMEOUT,
}) async {
ContactList? contactList = await _cacheManager.loadContactList(pubKey);
if (contactList != null && !forceRefresh) {
return contactList;
}
ContactList? loadedContactList;
try {
await for (final event in _requests.query(
filters: [
Filter(kinds: [ContactList.KIND], authors: [pubKey], limit: 1)
],
).stream) {
if (loadedContactList == null ||
loadedContactList.createdAt < event.createdAt) {
loadedContactList = ContactList.fromEvent(event);
}
}
} catch (e) {
// probably timeout;
Logger.log.e(e);
}
if (loadedContactList != null &&
(contactList == null ||
contactList.createdAt < loadedContactList.createdAt)) {
loadedContactList.loadedTimestamp =
DateTime.now().millisecondsSinceEpoch ~/ 1000;
await _cacheManager.saveContactList(loadedContactList);
contactList = loadedContactList;
}
return contactList;
}