mirror of
https://github.com/nostrlabs-io/notepush.git
synced 2025-06-14 11:07:43 +00:00
Add timeout to mute list fetching
If a relay does not have a user's mutelist, a function in our pipeline would wait indefinitely, causing all other requests to be locked as well. This commit adds a timeout to avoid this issue Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
use super::ExtendedEvent;
|
||||
use nostr_sdk::prelude::*;
|
||||
use tokio::time::{timeout, Duration};
|
||||
|
||||
pub struct MuteManager {
|
||||
client: Client,
|
||||
@ -99,19 +100,27 @@ impl MuteManager {
|
||||
|
||||
let mut mute_list: Option<Event> = None;
|
||||
let mut notifications = self.client.notifications();
|
||||
while let Ok(notification) = notifications.recv().await {
|
||||
if let RelayPoolNotification::Event {
|
||||
subscription_id,
|
||||
event,
|
||||
..
|
||||
} = notification
|
||||
{
|
||||
if this_subscription_id == subscription_id && event.kind == Kind::MuteList {
|
||||
mute_list = Some((*event).clone());
|
||||
break;
|
||||
|
||||
let timeout_duration = Duration::from_secs(10);
|
||||
while let Ok(result) = timeout(timeout_duration, notifications.recv()).await {
|
||||
if let Ok(notification) = result {
|
||||
if let RelayPoolNotification::Event {
|
||||
subscription_id,
|
||||
event,
|
||||
..
|
||||
} = notification
|
||||
{
|
||||
if this_subscription_id == subscription_id && event.kind == Kind::MuteList {
|
||||
mute_list = Some((*event).clone());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if mute_list.is_none() {
|
||||
log::debug!("Mute list not found for pubkey {:?}", pubkey);
|
||||
}
|
||||
|
||||
self.client.unsubscribe(this_subscription_id).await;
|
||||
mute_list
|
||||
|
Reference in New Issue
Block a user