Skip to content

Commit

Permalink
Merge pull request #2496 from acterglobal/ben-fix-ios-support-for-com…
Browse files Browse the repository at this point in the history
…ment-notifs

Fixing notification support for iOS build
  • Loading branch information
gnunicorn authored Jan 15, 2025
2 parents 0003582 + 848da93 commit 07198dc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ LIB_OUT_DIR = "debug"
TARGET_OS = "unknown"
DEV = true
RELEASE = false
# FIXME currently needed to fix building for ios
# see https://github.com/matrix-org/matrix-rust-sdk/issues/4416
CARGO_FEATURE_NO_NEON=1

[env.release]
RELEASE = true
Expand Down
63 changes: 49 additions & 14 deletions native/acter/src/api/uniffi_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,69 @@ impl NotificationItem {

let ApiNotificationItem {
title,
push_style,
target_url,
room_invite,
thread_id,
body,
noisy,
sender,
image,
inner,
..
} = value;

let target_url = inner.target_url();
let room_invite = inner.room_invite();
let push_style = inner.key();
let body = inner.body();

let mut msg_title = title;
let mut short_msg = None;

if let Some(invite) = room_invite {
short_msg = Some(invite);
} else if let Some(content) = body {
short_msg = Some(content.body());
let parent_title = if let Some(p) = inner.parent() {
let parent_title = p.title().unwrap_or("boost".to_owned());
let parent_emoji = p.emoji();
Some(format!("{parent_emoji} {parent_title}"))
} else {
None
};

let sender_name = sender
.display_name()
.clone()
.unwrap_or_else(|| sender.user_id());

if let Some(content) = body {
let msg = Some(content.body());
short_msg = Some(format!("${sender_name}: $msg"))
}

if push_style == "chat" {
if let Some(sender_name) = sender.display_name() {
// wrap the user display name before the message
short_msg = Some(format!("${sender_name}: $short_msg"));
match push_style.as_str() {
"invite" => {
if let Some(invite_id) = room_invite {
short_msg = Some(invite_id.to_string());
}
}
"comment" => {
if let Some(pt) = parent_title {
msg_title = format!("💬 Comment on {pt}");
} else {
msg_title = "💬 Comment".to_owned();
}
}
"reaction" => {
short_msg = Some(sender_name);
let reaction = inner.reaction_key().unwrap_or("❤️".to_owned());

if let Some(pt) = parent_title {
msg_title = format!("{reaction} to {pt}");
} else {
msg_title = reaction;
}
}
_ => {
// e.g. "chat" -> default is fine.
}
}

NotificationItem {
title,
title: msg_title,
body: short_msg,
push_style,
target_url,
Expand Down

0 comments on commit 07198dc

Please sign in to comment.