mirror of
https://github.com/youwen5/iamb.git
synced 2025-08-04 11:38:28 -07:00
Omit room name on desktop notifications for DMs (#428)
This commit is contained in:
parent
26802bab55
commit
3296f58859
1 changed files with 12 additions and 32 deletions
|
@ -199,18 +199,18 @@ pub async fn parse_full_notification(
|
||||||
.unwrap_or_else(|| sender_id.localpart());
|
.unwrap_or_else(|| sender_id.localpart());
|
||||||
|
|
||||||
let summary = if let Some(room_name) = room.cached_display_name() {
|
let summary = if let Some(room_name) = room.cached_display_name() {
|
||||||
|
if room.is_direct().await.map_err(IambError::from)? && sender_name == room_name.to_string()
|
||||||
|
{
|
||||||
|
sender_name.to_string()
|
||||||
|
} else {
|
||||||
format!("{sender_name} in {room_name}")
|
format!("{sender_name} in {room_name}")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sender_name.to_string()
|
sender_name.to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
let body = if show_body {
|
let body = if show_body {
|
||||||
event_notification_body(
|
event_notification_body(&event, sender_name).map(truncate)
|
||||||
&event,
|
|
||||||
sender_name,
|
|
||||||
room.is_direct().await.map_err(IambError::from)?,
|
|
||||||
)
|
|
||||||
.map(truncate)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
@ -218,11 +218,7 @@ pub async fn parse_full_notification(
|
||||||
return Ok((summary, body, server_ts));
|
return Ok((summary, body, server_ts));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn event_notification_body(
|
pub fn event_notification_body(event: &AnySyncTimelineEvent, sender_name: &str) -> Option<String> {
|
||||||
event: &AnySyncTimelineEvent,
|
|
||||||
sender_name: &str,
|
|
||||||
is_direct: bool,
|
|
||||||
) -> Option<String> {
|
|
||||||
let AnySyncTimelineEvent::MessageLike(event) = event else {
|
let AnySyncTimelineEvent::MessageLike(event) = event else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
@ -233,10 +229,7 @@ pub fn event_notification_body(
|
||||||
MessageType::Audio(_) => {
|
MessageType::Audio(_) => {
|
||||||
format!("{sender_name} sent an audio file.")
|
format!("{sender_name} sent an audio file.")
|
||||||
},
|
},
|
||||||
MessageType::Emote(content) => {
|
MessageType::Emote(content) => content.body,
|
||||||
let message = &content.body;
|
|
||||||
format!("{sender_name}: {message}")
|
|
||||||
},
|
|
||||||
MessageType::File(_) => {
|
MessageType::File(_) => {
|
||||||
format!("{sender_name} sent a file.")
|
format!("{sender_name} sent a file.")
|
||||||
},
|
},
|
||||||
|
@ -246,22 +239,9 @@ pub fn event_notification_body(
|
||||||
MessageType::Location(_) => {
|
MessageType::Location(_) => {
|
||||||
format!("{sender_name} sent their location.")
|
format!("{sender_name} sent their location.")
|
||||||
},
|
},
|
||||||
MessageType::Notice(content) => {
|
MessageType::Notice(content) => content.body,
|
||||||
let message = &content.body;
|
MessageType::ServerNotice(content) => content.body,
|
||||||
format!("{sender_name}: {message}")
|
MessageType::Text(content) => content.body,
|
||||||
},
|
|
||||||
MessageType::ServerNotice(content) => {
|
|
||||||
let message = &content.body;
|
|
||||||
format!("{sender_name}: {message}")
|
|
||||||
},
|
|
||||||
MessageType::Text(content) => {
|
|
||||||
if is_direct {
|
|
||||||
content.body
|
|
||||||
} else {
|
|
||||||
let message = &content.body;
|
|
||||||
format!("{sender_name}: {message}")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
MessageType::Video(_) => {
|
MessageType::Video(_) => {
|
||||||
format!("{sender_name} sent a video.")
|
format!("{sender_name} sent a video.")
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue