Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(notifications): match iOS new_email alerts to Gmail layout (#6090)

teo8b867b35bad7
diff --git a/crates/model_notifications/src/metadata.rs b/crates/model_notifications/src/metadata.rs
index f77842419c..0b50d2350b 100644
--- a/crates/model_notifications/src/metadata.rs
+++ b/crates/model_notifications/src/metadata.rs
@@ -8,7 +8,7 @@ use model_entity::EntityType;
pub use notification::domain::models::NotificationTitle;
use notification::domain::models::{
NotifCollapseKey, Notification, NotificationExtIos,
- apple::{APNSPushNotification, AlertDictionary, Aps, PushNotificationData},
+ apple::{APNSPushNotification, Alert, AlertDictionary, Aps, PushNotificationData},
};
use rootcause::Report;
use rootcause::report;
@@ -708,12 +708,25 @@ impl notification::domain::models::Notification for NewEmailMetadata {
const TYPE_NAME: &'static str = "new_email";
}
+impl NewEmailMetadata {
+ /// Lock-screen title: the sender's display name (or email), when present.
+ fn sender_line(&self) -> Option<&str> {
+ self.sender
+ .as_deref()
+ .map(str::trim)
+ .filter(|sender| !sender.is_empty())
+ }
+}
+
impl NotificationTitle for NewEmailMetadata {
fn format_title(
&self,
_sender_id: Option<MacroUserIdStr<'_>>,
) -> Result<String, rootcause::Report> {
- Ok(self.subject.clone())
+ Ok(self
+ .sender_line()
+ .unwrap_or(self.subject.trim())
+ .to_string())
}
fn format_body(
@@ -740,6 +753,12 @@ impl NotificationExtIos for NewEmailMetadata {
notification_id: Uuid,
) -> Option<APNSPushNotification<Self::NotifData>> {
let mut apns = alert_apns(self, sender_id, notification_id, None).ok()?;
+ if let Some(Alert::Dictionary(alert)) = &mut apns.aps.alert {
+ let subject = self.subject.trim();
+ if self.sender_line().is_some() && !subject.is_empty() {
+ alert.subtitle = Some(subject.to_string());
+ }
+ }
apns.aps.thread_id = Some(self.thread_id.clone());
Some(apns)
}
diff --git a/crates/model_notifications/src/metadata/test.rs b/crates/model_notifications/src/metadata/test.rs
index 9d653ec4c1..b7beea915f 100644
--- a/crates/model_notifications/src/metadata/test.rs
+++ b/crates/model_notifications/src/metadata/test.rs
@@ -1,4 +1,7 @@
use super::*;
+use notification::domain::models::apple::{
+ APNSPushNotification, Alert, AlertDictionary, PushNotificationData,
+};
fn uid(value: &str) -> MacroUserIdStr<'static> {
MacroUserIdStr::parse_from_str(value).unwrap().into_owned()
@@ -762,28 +765,82 @@ fn new_email_metadata() -> NewEmailMetadata {
}
}
-#[test]
-fn new_email_apns_uses_subject_and_snippet() {
- let metadata = new_email_metadata();
+fn new_email_apns(metadata: &NewEmailMetadata) -> APNSPushNotification<PushNotificationData> {
let entity = EntityType::EmailThread.with_entity_str(&metadata.thread_id);
let notification_id = Uuid::parse_str("55555555-5555-4555-8555-555555555555").unwrap();
-
- let apns = metadata
+ metadata
.as_apns(None, &entity, notification_id)
- .expect("new_email should build an APNS alert");
+ .expect("new_email should build an APNS alert")
+}
- match apns.aps.alert {
- Some(notification::domain::models::apple::Alert::Dictionary(alert)) => {
- assert_eq!(alert.title.as_deref(), Some("Quarterly plan"));
- assert_eq!(alert.body.as_deref(), Some("Here is the draft"));
- }
+fn new_email_alert(metadata: &NewEmailMetadata) -> AlertDictionary {
+ match new_email_apns(metadata).aps.alert {
+ Some(Alert::Dictionary(alert)) => alert,
other => panic!("expected dictionary alert, got {other:?}"),
}
+}
+
+#[test]
+fn new_email_title_prefers_sender() {
+ assert_eq!(
+ new_email_metadata().format_title(None).unwrap(),
+ "Ada Lovelace"
+ );
+}
+
+#[test]
+fn new_email_apns_matches_gmail_layout() {
+ let metadata = new_email_metadata();
+ let alert = new_email_alert(&metadata);
+ assert_eq!(alert.title.as_deref(), Some("Ada Lovelace"));
+ assert_eq!(alert.subtitle.as_deref(), Some("Quarterly plan"));
+ assert_eq!(alert.body.as_deref(), Some("Here is the draft"));
+
+ let apns = new_email_apns(&metadata);
assert_eq!(
apns.aps.thread_id.as_deref(),
Some(metadata.thread_id.as_str())
);
- assert_eq!(apns.push_notification_data.notification_id, notification_id);
+ assert_eq!(
+ apns.push_notification_data.notification_id,
+ Uuid::parse_str("55555555-5555-4555-8555-555555555555").unwrap()
+ );
+
+ let json = serde_json::to_value(&apns).unwrap();
+ assert_eq!(json["aps"]["alert"]["title"], "Ada Lovelace");
+ assert_eq!(json["aps"]["alert"]["subtitle"], "Quarterly plan");
+ assert_eq!(json["aps"]["alert"]["body"], "Here is the draft");
+}
+
+#[test]
+fn new_email_apns_falls_back_to_subject_without_sender() {
+ let mut metadata = new_email_metadata();
+ metadata.sender = None;
+
+ let alert = new_email_alert(&metadata);
+ assert_eq!(alert.title.as_deref(), Some("Quarterly plan"));
+ assert_eq!(alert.subtitle, None);
+ assert_eq!(alert.body.as_deref(), Some("Here is the draft"));
+}
+
+#[test]
+fn new_email_apns_treats_blank_sender_as_missing() {
+ let mut metadata = new_email_metadata();
+ metadata.sender = Some(" ".to_string());
+
+ let alert = new_email_alert(&metadata);
+ assert_eq!(alert.title.as_deref(), Some("Quarterly plan"));
+ assert_eq!(alert.subtitle, None);
+}
+
+#[test]
+fn new_email_apns_omits_blank_subject_subtitle() {
+ let mut metadata = new_email_metadata();
+ metadata.subject = " ".to_string();
+
+ let alert = new_email_alert(&metadata);
+ assert_eq!(alert.title.as_deref(), Some("Ada Lovelace"));
+ assert_eq!(alert.subtitle, None);
}
#[test]