getSingleNip51RelaySet method
Future<Nip51Set?>
getSingleNip51RelaySet(
- String name,
- EventSigner signer, {
- bool forceRefresh = false,
return single nip51 set that match given name
Implementation
Future<Nip51Set?> getSingleNip51RelaySet(String name, EventSigner signer,
{bool forceRefresh = false}) async {
Nip51Set? relaySet = await _getCachedNip51RelaySet(name, signer);
if (relaySet == null || forceRefresh) {
Nip51Set? newRelaySet;
await for (final event in _requests.query(filters: [
Filter(
authors: [signer.getPublicKey()],
kinds: [Nip51List.RELAY_SET],
dTags: [name],
)
], cacheRead: !forceRefresh).stream) {
if (newRelaySet == null || newRelaySet.createdAt < event.createdAt) {
if (event.getDtag() != null && event.getDtag() == name) {
newRelaySet = await Nip51Set.fromEvent(event, signer);
await _cacheManager.saveEvent(event);
} else if (Helpers.isNotBlank(event.content)) {
Nip51Set? decryptedRelaySet =
await Nip51Set.fromEvent(event, signer);
if (decryptedRelaySet != null && decryptedRelaySet.name == name) {
newRelaySet = decryptedRelaySet;
await _cacheManager.saveEvent(event);
}
}
}
}
return newRelaySet;
}
return relaySet;
}