Skip to content

Commit

Permalink
chore(notifications): rename messages
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSamtoshi committed Feb 19, 2024
1 parent 32b9f41 commit fb853aa
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion core/notifications/src/email_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
4 changes: 2 additions & 2 deletions core/notifications/src/email_executor/smtp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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()
Expand Down
32 changes: 16 additions & 16 deletions core/notifications/src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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!(
Expand Down Expand Up @@ -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 }
}
}

Expand All @@ -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,
Expand All @@ -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,
Expand Down
34 changes: 17 additions & 17 deletions core/notifications/src/notification_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait NotificationEvent: std::fmt::Debug + Into<NotificationEventPayload> +
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;
}

Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions core/notifications/src/push_executor/fcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion core/notifications/src/push_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fb853aa

Please sign in to comment.