From b808c45af6a301587783d689138ec744bc6b9536 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Mon, 20 Jan 2025 16:40:17 +0100 Subject: Check tokens array length This is much better than `.filter` because there's already a check on the SQL query --- src/graphql/types/alert.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/graphql/types/alert.rs b/src/graphql/types/alert.rs index 481eae6..2f06225 100644 --- a/src/graphql/types/alert.rs +++ b/src/graphql/types/alert.rs @@ -389,21 +389,22 @@ pub mod mutations { .map(|row| { format!("ExponentPushToken[{}]", row.get::(0)) }) - .filter(|token| token.len() > 19) .collect(); - expo::send( - (*state.expo).clone(), - tokens, - "New Alert!".to_string(), - match level.text { - "One" => alert.text1.clone(), - "Two" => alert.text2.clone(), - "Three" => alert.text3.clone(), - _ => "Check it out in app!".to_string(), - }, - ) - .await?; + if tokens.len() > 0 { + expo::send( + (*state.expo).clone(), + tokens, + "New Alert!".to_string(), + match level.text { + "One" => alert.text1.clone(), + "Two" => alert.text2.clone(), + "Three" => alert.text3.clone(), + _ => "Check it out in app!".to_string(), + }, + ) + .await?; + } } alerted_positions.extend(positions.iter().map(|p| p.id).collect::>()); -- cgit v1.2.3-18-g5258