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(
199 .unwrap_or_else(|| sender_id.localpart()); 199 .unwrap_or_else(|| sender_id.localpart());
200 200
201 let summary = if let Some(room_name) = room.cached_display_name() { 201 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 }
203 } else { 208 } else {
204 sender_name.to_string() 209 sender_name.to_string()
205 }; 210 };
206 211
207 let body = if show_body { 212 let body = if show_body {
208 event_notification_body( 213 event_notification_body(&event, sender_name).map(truncate)
209 &event,
210 sender_name,
211 room.is_direct().await.map_err(IambError::from)?,
212 )
213 .map(truncate)
214 } else { 214 } else {
215 None 215 None
216 }; 216 };
@@ -218,11 +218,7 @@ pub async fn parse_full_notification(
218 return Ok((summary, body, server_ts)); 218 return Ok((summary, body, server_ts));
219} 219}
220 220
221pub fn event_notification_body( 221pub fn event_notification_body(event: &AnySyncTimelineEvent, sender_name: &str) -> Option<String> {
222 event: &AnySyncTimelineEvent,
223 sender_name: &str,
224 is_direct: bool,
225) -> Option<String> {
226 let AnySyncTimelineEvent::MessageLike(event) = event else { 222 let AnySyncTimelineEvent::MessageLike(event) = event else {
227 return None; 223 return None;
228 }; 224 };
@@ -233,10 +229,7 @@ pub fn event_notification_body(
233 MessageType::Audio(_) => { 229 MessageType::Audio(_) => {
234 format!("{sender_name} sent an audio file.") 230 format!("{sender_name} sent an audio file.")
235 }, 231 },
236 MessageType::Emote(content) => { 232 MessageType::Emote(content) => content.body,
237 let message = &content.body;
238 format!("{sender_name}: {message}")
239 },
240 MessageType::File(_) => { 233 MessageType::File(_) => {
241 format!("{sender_name} sent a file.") 234 format!("{sender_name} sent a file.")
242 }, 235 },
@@ -246,22 +239,9 @@ pub fn event_notification_body(
246 MessageType::Location(_) => { 239 MessageType::Location(_) => {
247 format!("{sender_name} sent their location.") 240 format!("{sender_name} sent their location.")
248 }, 241 },
249 MessageType::Notice(content) => { 242 MessageType::Notice(content) => content.body,
250 let message = &content.body; 243 MessageType::ServerNotice(content) => content.body,
251 format!("{sender_name}: {message}") 244 MessageType::Text(content) => content.body,
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 },
265 MessageType::Video(_) => { 245 MessageType::Video(_) => {
266 format!("{sender_name} sent a video.") 246 format!("{sender_name} sent a video.")
267 }, 247 },