From 2e5d8ed30595dd77e308f2030565fc2afeec5027 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 15 Apr 2021 19:29:02 +0200 Subject: [PATCH] Send notifications for users who asked for it --- src/helpers/push_notifications_helper.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/helpers/push_notifications_helper.rs b/src/helpers/push_notifications_helper.rs index 6921a7e..5264c50 100644 --- a/src/helpers/push_notifications_helper.rs +++ b/src/helpers/push_notifications_helper.rs @@ -9,7 +9,7 @@ use crate::data::error::Res; use crate::data::push_notification::PushNotification; use crate::data::user::UserID; use crate::data::user_token::{PushNotificationToken, UserAccessToken}; -use crate::helpers::{account_helper, conversations_helper, independent_push_notifications_service_helper, user_helper, firebase_notifications_helper}; +use crate::helpers::{account_helper, conversations_helper, firebase_notifications_helper, independent_push_notifications_service_helper, user_helper}; use crate::helpers::events_helper::Event; /// Un-register for previous push notifications service @@ -136,13 +136,21 @@ pub fn create_conversation_notification(msg: &ConversationMessage) -> Res { timeout: None, }; - let list = conversations_helper::get_list_members(msg.conv_id)? + let list: Vec = conversations_helper::get_list_members(msg.conv_id)? .into_iter() .filter(|m| m.following && m.user_id != user_id) .map(|m| m.user_id) .collect(); - push_notification_to_users(¬if, list) + // Select only users who allowed push notifications + let mut dest_list = vec![]; + for el in list { + if user_helper::find_user_by_id(&el)?.allow_notif_conv { + dest_list.push(el); + } + } + + push_notification_to_users(¬if, dest_list) } /// Dismiss a conversation notification