mirror of
https://github.com/nostrlabs-io/notepush.git
synced 2025-06-21 21:32:51 +00:00
Add support to "only notifications from following" setting
Testing ------- PASS Devices: Mix of iPhone simulators and real devices notepush: This commit Damus: 4ea6c360e6e33747cb09ecf085049948ec1dadd1 (WIP change from GH issue #2360) Setup: - Account A with push notifications enabled, DM notifications enabled, and "only notifications from following enabled" - Account A follows B but not C Steps: 1. Send DM to A from B. Push notification appears 2. Send DM to A from C. Push notification does not appear Signed-off-by: Daniel D’Aquino <daniel@daquino.me> Closes: https://github.com/damus-io/damus/issues/2360
This commit is contained in:
@ -13,7 +13,7 @@ use tokio::sync::Mutex;
|
||||
use std::collections::HashSet;
|
||||
use tokio;
|
||||
|
||||
use super::mute_manager::MuteManager;
|
||||
use super::nostr_network_helper::NostrNetworkHelper;
|
||||
use super::ExtendedEvent;
|
||||
use super::SqlStringConvertible;
|
||||
use nostr::Event;
|
||||
@ -28,7 +28,7 @@ pub struct NotificationManager {
|
||||
apns_topic: String,
|
||||
apns_client: Mutex<Client>,
|
||||
|
||||
mute_manager: Mutex<MuteManager>,
|
||||
nostr_network_helper: Mutex<NostrNetworkHelper>,
|
||||
}
|
||||
|
||||
impl NotificationManager {
|
||||
@ -43,7 +43,7 @@ impl NotificationManager {
|
||||
apns_environment: a2::client::Endpoint,
|
||||
apns_topic: String,
|
||||
) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
let mute_manager = MuteManager::new(relay_url.clone()).await?;
|
||||
let mute_manager = NostrNetworkHelper::new(relay_url.clone()).await?;
|
||||
|
||||
let connection = db.get()?;
|
||||
Self::setup_database(&connection)?;
|
||||
@ -61,7 +61,7 @@ impl NotificationManager {
|
||||
apns_topic,
|
||||
apns_client: Mutex::new(client),
|
||||
db: Mutex::new(db),
|
||||
mute_manager: Mutex::new(mute_manager),
|
||||
nostr_network_helper: Mutex::new(mute_manager),
|
||||
})
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ impl NotificationManager {
|
||||
let mut pubkeys_to_notify = HashSet::new();
|
||||
for pubkey in relevant_pubkeys_yet_to_receive {
|
||||
let should_mute: bool = {
|
||||
let mute_manager_mutex_guard = self.mute_manager.lock().await;
|
||||
let mute_manager_mutex_guard = self.nostr_network_helper.lock().await;
|
||||
mute_manager_mutex_guard
|
||||
.should_mute_notification_for_pubkey(event, &pubkey)
|
||||
.await
|
||||
@ -285,6 +285,12 @@ impl NotificationManager {
|
||||
event: &Event,
|
||||
) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
let notification_preferences = self.get_user_notification_settings(pubkey, device_token).await?;
|
||||
if notification_preferences.only_notifications_from_following_enabled {
|
||||
let nostr_network_helper_mutex_guard = self.nostr_network_helper.lock().await;
|
||||
if !nostr_network_helper_mutex_guard.does_pubkey_follow_pubkey(pubkey, &event.author()).await {
|
||||
return Ok(false);
|
||||
}
|
||||
}
|
||||
match event.kind {
|
||||
Kind::TextNote => Ok(notification_preferences.mention_notifications_enabled), // TODO: Not 100% accurate
|
||||
Kind::EncryptedDirectMessage => Ok(notification_preferences.dm_notifications_enabled),
|
||||
|
Reference in New Issue
Block a user