1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-25 23:09:22 +00:00

Send notifications for users who asked for it

This commit is contained in:
Pierre HUBERT 2021-04-15 19:29:02 +02:00
parent 42c7425aae
commit 2e5d8ed305

View File

@ -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<UserID> = 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(&notif, 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(&notif, dest_list)
}
/// Dismiss a conversation notification