Commit 3296f58859

3296f58859ef9673cd3c77d2cc6d01203a6d6072

parent: 26802bab55

Unregistered key

VAWVAW <94846592+VAWVAW@users.noreply.github.com> · 2025-05-29 03:23 UTC
committer: <noreply@github.com>

Omit room name on desktop notifications for DMs (#428)

Layout: unified · split

src/notifications.rs +12 −32
@@ -199,18 +199,18 @@ pub async fn parse_full_notification(
199199 .unwrap_or_else(|| sender_id.localpart());
200200
201201 let summary = if let Some(room_name) = room.cached_display_name() {
202 format!("{sender_name} in {room_name}")
202 if room.is_direct().await.map_err(IambError::from)? && sender_name == room_name.to_string()
203 {
204 sender_name.to_string()
205 } else {
206 format!("{sender_name} in {room_name}")
207 }
203208 } else {
204209 sender_name.to_string()
205210 };
206211
207212 let body = if show_body {
208 event_notification_body(
209 &event,
210 sender_name,
211 room.is_direct().await.map_err(IambError::from)?,
212 )
213 .map(truncate)
213 event_notification_body(&event, sender_name).map(truncate)
214214 } else {
215215 None
216216 };
@@ -218,11 +218,7 @@ pub async fn parse_full_notification(
218218 return Ok((summary, body, server_ts));
219219}
220220
221pub fn event_notification_body(
222 event: &AnySyncTimelineEvent,
223 sender_name: &str,
224 is_direct: bool,
225) -> Option<String> {
221pub fn event_notification_body(event: &AnySyncTimelineEvent, sender_name: &str) -> Option<String> {
226222 let AnySyncTimelineEvent::MessageLike(event) = event else {
227223 return None;
228224 };
@@ -233,10 +229,7 @@ pub fn event_notification_body(
233229 MessageType::Audio(_) => {
234230 format!("{sender_name} sent an audio file.")
235231 },
236 MessageType::Emote(content) => {
237 let message = &content.body;
238 format!("{sender_name}: {message}")
239 },
232 MessageType::Emote(content) => content.body,
240233 MessageType::File(_) => {
241234 format!("{sender_name} sent a file.")
242235 },
@@ -246,22 +239,9 @@ pub fn event_notification_body(
246239 MessageType::Location(_) => {
247240 format!("{sender_name} sent their location.")
248241 },
249 MessageType::Notice(content) => {
250 let message = &content.body;
251 format!("{sender_name}: {message}")
252 },
253 MessageType::ServerNotice(content) => {
254 let message = &content.body;
255 format!("{sender_name}: {message}")
256 },
257 MessageType::Text(content) => {
258 if is_direct {
259 content.body
260 } else {
261 let message = &content.body;
262 format!("{sender_name}: {message}")
263 }
264 },
242 MessageType::Notice(content) => content.body,
243 MessageType::ServerNotice(content) => content.body,
244 MessageType::Text(content) => content.body,
265245 MessageType::Video(_) => {
266246 format!("{sender_name} sent a video.")
267247 },