getSingleNip51List method
Returns a NIP-51 list by the given kind.
Retrieves the most recent list event for the specified kind.
First checks cache unless forceRefresh is true, then queries relays.
kind the kind of NIP-51 list to retrieve
forceRefresh if true, bypass cache and query relays directly
timeout maximum duration to wait for relay responses
Returns the list if found, null otherwise.
Implementation
Future<Nip51List?> getSingleNip51List(
int kind, {
bool forceRefresh = false,
Duration timeout = const Duration(seconds: 5),
}) async {
if (_eventSigner == null) {
throw Exception("cannot get nip51 list without a signer");
}
final signer = _eventSigner!;
Nip51List? list =
!forceRefresh ? await _getCachedNip51List(kind, signer) : null;
if (list == null) {
Nip51List? refreshedList;
await for (final event in _requests.query(filters: [
Filter(
authors: [signer.getPublicKey()],
kinds: [kind],
)
], timeout: timeout).stream) {
if (refreshedList == null ||
refreshedList.createdAt <= event.createdAt) {
refreshedList = await Nip51List.fromEvent(event, signer);
// if (Helpers.isNotBlank(event.content)) {
// Nip51List? decryptedList = await Nip51List.fromEvent(event, signer);
// refreshedList = decryptedList;
// }
await _cacheManager.saveEvent(event);
}
}
return refreshedList;
}
return list;
}