From fb853aa26ed1d8c31a2bd4a0d5c97ca67a7e2194 Mon Sep 17 00:00:00 2001 From: Sam Peters Date: Mon, 19 Feb 2024 17:19:12 -0600 Subject: [PATCH] chore(notifications): rename messages --- core/notifications/src/email_executor/mod.rs | 2 +- .../src/email_executor/smtp/mod.rs | 4 +-- core/notifications/src/messages/mod.rs | 32 ++++++++--------- core/notifications/src/notification_event.rs | 34 +++++++++---------- .../src/push_executor/fcm/mod.rs | 4 +-- core/notifications/src/push_executor/mod.rs | 2 +- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/core/notifications/src/email_executor/mod.rs b/core/notifications/src/email_executor/mod.rs index 50ff3aefab..30f1250229 100644 --- a/core/notifications/src/email_executor/mod.rs +++ b/core/notifications/src/email_executor/mod.rs @@ -39,7 +39,7 @@ impl EmailExecutor { .ok() .and_then(|s| s.email_address().map(|addr| (s, addr))) { - let msg = event.to_localized_msg(settings.locale().unwrap_or_default()); + let msg = event.to_localized_push_msg(settings.locale().unwrap_or_default()); self.smtp.send_email(msg, addr).await?; } Ok(()) diff --git a/core/notifications/src/email_executor/smtp/mod.rs b/core/notifications/src/email_executor/smtp/mod.rs index b3b3c04594..dde967f93b 100644 --- a/core/notifications/src/email_executor/smtp/mod.rs +++ b/core/notifications/src/email_executor/smtp/mod.rs @@ -7,7 +7,7 @@ use lettre::{ AsyncSmtpTransport, AsyncTransport, Tokio1Executor, }; -use crate::{messages::LocalizedMessage, primitives::GaloyEmailAddress}; +use crate::{messages::LocalizedPushMessage, primitives::GaloyEmailAddress}; pub use config::*; use error::*; @@ -33,7 +33,7 @@ impl SmtpClient { pub async fn send_email( &self, - msg: LocalizedMessage, + msg: LocalizedPushMessage, recipient_addr: GaloyEmailAddress, ) -> Result<(), SmtpError> { let email = Message::builder() diff --git a/core/notifications/src/messages/mod.rs b/core/notifications/src/messages/mod.rs index 0be17e02a2..63aaf05fce 100644 --- a/core/notifications/src/messages/mod.rs +++ b/core/notifications/src/messages/mod.rs @@ -2,15 +2,15 @@ use rust_i18n::t; use crate::{notification_event::*, primitives::*}; -pub struct LocalizedMessage { +pub struct LocalizedPushMessage { pub title: String, pub body: String, } -pub struct Messages {} +pub struct PushMessages {} -impl Messages { - pub fn circle_grew(locale: &str, event: &CircleGrew) -> LocalizedMessage { +impl PushMessages { + pub fn circle_grew(locale: &str, event: &CircleGrew) -> LocalizedPushMessage { let circle_type = match event.circle_type { CircleType::Inner => t!("circle_type.inner", locale = locale), CircleType::Outer => t!("circle_type.outer", locale = locale), @@ -22,13 +22,13 @@ impl Messages { circle_type = circle_type ) .to_string(); - LocalizedMessage { title, body } + LocalizedPushMessage { title, body } } pub fn circle_threshold_reached( locale: &str, event: &CircleThresholdReached, - ) -> LocalizedMessage { + ) -> LocalizedPushMessage { let title = match event.circle_type { CircleType::Inner => t!("circle_threshold_reached.inner.title", locale = locale), CircleType::Outer => t!("circle_threshold_reached.outer.title", locale = locale), @@ -53,22 +53,22 @@ impl Messages { ), } .to_string(); - LocalizedMessage { title, body } + LocalizedPushMessage { title, body } } pub fn identity_verification_approved( locale: &str, _event: &IdentityVerificationApproved, - ) -> LocalizedMessage { + ) -> LocalizedPushMessage { let title = t!("identity_verification_approved.title", locale = locale).to_string(); let body = t!("identity_verification_approved.body", locale = locale).to_string(); - LocalizedMessage { title, body } + LocalizedPushMessage { title, body } } pub fn identity_verification_declined( locale: &str, event: &IdentityVerificationDeclined, - ) -> LocalizedMessage { + ) -> LocalizedPushMessage { let reason = match event.declined_reason { IdentityVerificationDeclinedReason::DocumentsNotClear => { t!( @@ -119,20 +119,20 @@ impl Messages { reason = reason ) .to_string(); - LocalizedMessage { title, body } + LocalizedPushMessage { title, body } } pub fn identity_verification_review_pending( locale: &str, _event: &IdentityVerificationReviewPending, - ) -> LocalizedMessage { + ) -> LocalizedPushMessage { let title = t!( "identity_verification_review_pending.title", locale = locale ) .to_string(); let body = t!("identity_verification_review_pending.body", locale = locale).to_string(); - LocalizedMessage { title, body } + LocalizedPushMessage { title, body } } } @@ -148,7 +148,7 @@ mod tests { this_month_circle_size: 1, all_time_circle_size: 2, }; - let localized_message = Messages::circle_grew("en", &event); + let localized_message = PushMessages::circle_grew("en", &event); assert_eq!(localized_message.title, "Your Blink Circles are growing!"); assert_eq!( localized_message.body, @@ -164,14 +164,14 @@ mod tests { time_frame: CircleTimeFrame::AllTime, threshold: 2, }; - let localized_message = Messages::circle_threshold_reached("en", &event); + let localized_message = PushMessages::circle_threshold_reached("en", &event); assert_eq!(localized_message.title, "Nice Inner Circle! 🤙"); assert_eq!( localized_message.body, "You have welcomed 2 people to Blink. Keep it up!" ); - let localized_message = Messages::circle_threshold_reached("de", &event); + let localized_message = PushMessages::circle_threshold_reached("de", &event); assert_eq!(localized_message.title, "Schöner Innerer Kreis! 🤙"); assert_eq!( localized_message.body, diff --git a/core/notifications/src/notification_event.rs b/core/notifications/src/notification_event.rs index 296c199e79..93bdd9e37b 100644 --- a/core/notifications/src/notification_event.rs +++ b/core/notifications/src/notification_event.rs @@ -11,7 +11,7 @@ pub trait NotificationEvent: std::fmt::Debug + Into + fn category(&self) -> UserNotificationCategory; fn user_id(&self) -> &GaloyUserId; fn deep_link(&self) -> DeepLink; - fn to_localized_msg(&self, locale: GaloyLocale) -> LocalizedMessage; + fn to_localized_push_msg(&self, locale: GaloyLocale) -> LocalizedPushMessage; fn should_send_email(&self) -> bool; } @@ -56,20 +56,20 @@ impl NotificationEvent for NotificationEventPayload { } } - fn to_localized_msg(&self, locale: GaloyLocale) -> LocalizedMessage { + fn to_localized_push_msg(&self, locale: GaloyLocale) -> LocalizedPushMessage { match self { - NotificationEventPayload::CircleGrew(event) => event.to_localized_msg(locale), + NotificationEventPayload::CircleGrew(event) => event.to_localized_push_msg(locale), NotificationEventPayload::CircleThresholdReached(event) => { - event.to_localized_msg(locale) + event.to_localized_push_msg(locale) } NotificationEventPayload::IdentityVerificationApproved(event) => { - event.to_localized_msg(locale) + event.to_localized_push_msg(locale) } NotificationEventPayload::IdentityVerificationDeclined(event) => { - event.to_localized_msg(locale) + event.to_localized_push_msg(locale) } NotificationEventPayload::IdentityVerificationReviewPending(event) => { - event.to_localized_msg(locale) + event.to_localized_push_msg(locale) } } } @@ -112,8 +112,8 @@ impl NotificationEvent for CircleGrew { DeepLink::Circles } - fn to_localized_msg(&self, locale: GaloyLocale) -> LocalizedMessage { - Messages::circle_grew(locale.as_ref(), self) + fn to_localized_push_msg(&self, locale: GaloyLocale) -> LocalizedPushMessage { + PushMessages::circle_grew(locale.as_ref(), self) } fn should_send_email(&self) -> bool { @@ -148,8 +148,8 @@ impl NotificationEvent for CircleThresholdReached { DeepLink::Circles } - fn to_localized_msg(&self, locale: GaloyLocale) -> LocalizedMessage { - Messages::circle_threshold_reached(locale.as_ref(), self) + fn to_localized_push_msg(&self, locale: GaloyLocale) -> LocalizedPushMessage { + PushMessages::circle_threshold_reached(locale.as_ref(), self) } fn should_send_email(&self) -> bool { @@ -181,8 +181,8 @@ impl NotificationEvent for IdentityVerificationApproved { DeepLink::None } - fn to_localized_msg(&self, locale: GaloyLocale) -> LocalizedMessage { - Messages::identity_verification_approved(locale.as_ref(), self) + fn to_localized_push_msg(&self, locale: GaloyLocale) -> LocalizedPushMessage { + PushMessages::identity_verification_approved(locale.as_ref(), self) } fn should_send_email(&self) -> bool { @@ -225,8 +225,8 @@ impl NotificationEvent for IdentityVerificationDeclined { DeepLink::None } - fn to_localized_msg(&self, locale: GaloyLocale) -> LocalizedMessage { - Messages::identity_verification_declined(locale.as_ref(), self) + fn to_localized_push_msg(&self, locale: GaloyLocale) -> LocalizedPushMessage { + PushMessages::identity_verification_declined(locale.as_ref(), self) } fn should_send_email(&self) -> bool { @@ -258,8 +258,8 @@ impl NotificationEvent for IdentityVerificationReviewPending { DeepLink::None } - fn to_localized_msg(&self, locale: GaloyLocale) -> LocalizedMessage { - Messages::identity_verification_review_pending(locale.as_ref(), self) + fn to_localized_push_msg(&self, locale: GaloyLocale) -> LocalizedPushMessage { + PushMessages::identity_verification_review_pending(locale.as_ref(), self) } fn should_send_email(&self) -> bool { diff --git a/core/notifications/src/push_executor/fcm/mod.rs b/core/notifications/src/push_executor/fcm/mod.rs index 66a3fe64e6..ffc448c58b 100644 --- a/core/notifications/src/push_executor/fcm/mod.rs +++ b/core/notifications/src/push_executor/fcm/mod.rs @@ -11,7 +11,7 @@ use google_fcm1::{ use std::collections::HashMap; -use crate::{messages::LocalizedMessage, notification_event::*, primitives::PushDeviceToken}; +use crate::{messages::LocalizedPushMessage, notification_event::*, primitives::PushDeviceToken}; pub use config::*; use error::*; @@ -63,7 +63,7 @@ impl FcmClient { pub async fn send( &self, device_token: &PushDeviceToken, - msg: &LocalizedMessage, + msg: &LocalizedPushMessage, deep_link: DeepLink, ) -> Result<(), FcmError> { let mut data = HashMap::new(); diff --git a/core/notifications/src/push_executor/mod.rs b/core/notifications/src/push_executor/mod.rs index 65f733afaf..208c8c7eaa 100644 --- a/core/notifications/src/push_executor/mod.rs +++ b/core/notifications/src/push_executor/mod.rs @@ -41,7 +41,7 @@ impl PushExecutor { return Ok(()); } - let msg = event.to_localized_msg(settings.locale().unwrap_or_default()); + let msg = event.to_localized_push_msg(settings.locale().unwrap_or_default()); let mut should_persist = false; let mut last_err = None;