Commit 3296f58859
Unregistered key
Layout: unified · split
src/notifications.rs +12 −32
| @@ -199,18 +199,18 @@ pub async fn parse_full_notification( | ||
| 199 | 199 | .unwrap_or_else(|| sender_id.localpart()); |
| 200 | 200 | |
| 201 | 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 | 208 | } else { |
| 204 | 209 | sender_name.to_string() |
| 205 | 210 | }; |
| 206 | 211 | |
| 207 | 212 | 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) | |
| 214 | 214 | } else { |
| 215 | 215 | None |
| 216 | 216 | }; |
| @@ -218,11 +218,7 @@ pub async fn parse_full_notification( | ||
| 218 | 218 | return Ok((summary, body, server_ts)); |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | pub fn event_notification_body( | |
| 222 | event: &AnySyncTimelineEvent, | |
| 223 | sender_name: &str, | |
| 224 | is_direct: bool, | |
| 225 | ) -> Option<String> { | |
| 221 | pub fn event_notification_body(event: &AnySyncTimelineEvent, sender_name: &str) -> Option<String> { | |
| 226 | 222 | let AnySyncTimelineEvent::MessageLike(event) = event else { |
| 227 | 223 | return None; |
| 228 | 224 | }; |
| @@ -233,10 +229,7 @@ pub fn event_notification_body( | ||
| 233 | 229 | MessageType::Audio(_) => { |
| 234 | 230 | format!("{sender_name} sent an audio file.") |
| 235 | 231 | }, |
| 236 | MessageType::Emote(content) => { | |
| 237 | let message = &content.body; | |
| 238 | format!("{sender_name}: {message}") | |
| 239 | }, | |
| 232 | MessageType::Emote(content) => content.body, | |
| 240 | 233 | MessageType::File(_) => { |
| 241 | 234 | format!("{sender_name} sent a file.") |
| 242 | 235 | }, |
| @@ -246,22 +239,9 @@ pub fn event_notification_body( | ||
| 246 | 239 | MessageType::Location(_) => { |
| 247 | 240 | format!("{sender_name} sent their location.") |
| 248 | 241 | }, |
| 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, | |
| 265 | 245 | MessageType::Video(_) => { |
| 266 | 246 | format!("{sender_name} sent a video.") |
| 267 | 247 | }, |