| 1 | use std::{fmt, sync::Arc}; |
| 2 | |
| 3 | use ruma::{ |
| 4 | OwnedDeviceId, OwnedEventId, OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, OwnedRoomOrAliasId, |
| 5 | OwnedServerName, OwnedTransactionId, OwnedUserId, |
| 6 | events::{ |
| 7 | AnyGlobalAccountDataEventContent, AnyRoomAccountDataEventContent, AnySyncTimelineEvent, |
| 8 | GlobalAccountDataEventType, RoomAccountDataEventType, |
| 9 | room::member::StrippedRoomMemberEvent, |
| 10 | }, |
| 11 | serde::Raw, |
| 12 | }; |
| 13 | #[cfg(feature = "serde")] |
| 14 | use serde::{Deserialize, Serialize}; |
| 15 | |
| 16 | /// every command answers exactly once through `ClientHandle::send` or `execute`. |
| 17 | /// the event stream only ever carries state |
| 18 | #[derive(Debug)] |
| 19 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 20 | #[non_exhaustive] |
| 21 | pub enum Command { |
| 22 | Account(AccountCommand), |
| 23 | Room(RoomCommand), |
| 24 | Timeline(TimelineCommand), |
| 25 | Media(MediaCommand), |
| 26 | Encryption(EncryptionCommand), |
| 27 | Notification(NotificationCommand), |
| 28 | Lifecycle(LifecycleCommand), |
| 29 | } |
| 30 | |
| 31 | #[derive(Debug)] |
| 32 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 33 | #[non_exhaustive] |
| 34 | pub enum AccountCommand { |
| 35 | Logout, |
| 36 | SetAccountData { |
| 37 | event_type: GlobalAccountDataEventType, |
| 38 | content: Raw<AnyGlobalAccountDataEventContent>, |
| 39 | }, |
| 40 | SetDisplayName(Option<String>), |
| 41 | SetAvatar(Option<OwnedMxcUri>), |
| 42 | /// uploads the image and points the profile at it, same byte cap as any upload |
| 43 | UploadAvatar { |
| 44 | mimetype: String, |
| 45 | bytes: Vec<u8>, |
| 46 | }, |
| 47 | RenameDevice { |
| 48 | device_id: OwnedDeviceId, |
| 49 | display_name: String, |
| 50 | }, |
| 51 | DeleteDevices { |
| 52 | device_ids: Vec<OwnedDeviceId>, |
| 53 | auth: Option<crate::InteractiveAuth>, |
| 54 | }, |
| 55 | } |
| 56 | |
| 57 | #[derive(Clone, Debug)] |
| 58 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 59 | #[non_exhaustive] |
| 60 | pub enum RoomCommand { |
| 61 | /// the snapshot turns up as `Event::TimelineReset`. opening an open room sends a fresh one |
| 62 | Open(OwnedRoomId), |
| 63 | Close(OwnedRoomId), |
| 64 | Join { |
| 65 | room: OwnedRoomOrAliasId, |
| 66 | via: Vec<OwnedServerName>, |
| 67 | }, |
| 68 | Leave(OwnedRoomId), |
| 69 | Forget(OwnedRoomId), |
| 70 | AcceptInvite(OwnedRoomId), |
| 71 | RejectInvite(OwnedRoomId), |
| 72 | InviteUser { |
| 73 | room_id: OwnedRoomId, |
| 74 | user_id: OwnedUserId, |
| 75 | }, |
| 76 | KickUser { |
| 77 | room_id: OwnedRoomId, |
| 78 | user_id: OwnedUserId, |
| 79 | reason: Option<String>, |
| 80 | }, |
| 81 | BanUser { |
| 82 | room_id: OwnedRoomId, |
| 83 | user_id: OwnedUserId, |
| 84 | reason: Option<String>, |
| 85 | }, |
| 86 | UnbanUser { |
| 87 | room_id: OwnedRoomId, |
| 88 | user_id: OwnedUserId, |
| 89 | reason: Option<String>, |
| 90 | }, |
| 91 | SetPowerLevels { |
| 92 | room_id: OwnedRoomId, |
| 93 | changes: PowerLevelChanges, |
| 94 | }, |
| 95 | SetUserPowerLevel { |
| 96 | room_id: OwnedRoomId, |
| 97 | user_id: OwnedUserId, |
| 98 | level: i64, |
| 99 | }, |
| 100 | Create(CreateRoomOptions), |
| 101 | /// hands back the existing dm if there is one |
| 102 | CreateDirect(OwnedUserId), |
| 103 | CancelSend { |
| 104 | room_id: OwnedRoomId, |
| 105 | transaction_id: OwnedTransactionId, |
| 106 | }, |
| 107 | RetrySend { |
| 108 | room_id: OwnedRoomId, |
| 109 | transaction_id: OwnedTransactionId, |
| 110 | }, |
| 111 | SetTyping { |
| 112 | room_id: OwnedRoomId, |
| 113 | typing: bool, |
| 114 | }, |
| 115 | SetAccountData { |
| 116 | room_id: OwnedRoomId, |
| 117 | event_type: RoomAccountDataEventType, |
| 118 | content: Raw<AnyRoomAccountDataEventContent>, |
| 119 | }, |
| 120 | } |
| 121 | |
| 122 | #[derive(Clone, Debug, Default, Eq, PartialEq)] |
| 123 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 124 | #[non_exhaustive] |
| 125 | pub struct CreateRoomOptions { |
| 126 | pub name: Option<String>, |
| 127 | pub topic: Option<String>, |
| 128 | pub alias_localpart: Option<String>, |
| 129 | pub invite: Vec<OwnedUserId>, |
| 130 | pub direct: bool, |
| 131 | pub visibility: RoomVisibility, |
| 132 | pub preset: Option<RoomPreset>, |
| 133 | } |
| 134 | |
| 135 | impl CreateRoomOptions { |
| 136 | #[must_use] |
| 137 | pub fn with_name(mut self, name: impl Into<String>) -> Self { |
| 138 | self.name = Some(name.into()); |
| 139 | self |
| 140 | } |
| 141 | |
| 142 | #[must_use] |
| 143 | pub fn with_topic(mut self, topic: impl Into<String>) -> Self { |
| 144 | self.topic = Some(topic.into()); |
| 145 | self |
| 146 | } |
| 147 | |
| 148 | #[must_use] |
| 149 | pub fn with_alias_localpart(mut self, localpart: impl Into<String>) -> Self { |
| 150 | self.alias_localpart = Some(localpart.into()); |
| 151 | self |
| 152 | } |
| 153 | |
| 154 | #[must_use] |
| 155 | pub fn with_invite(mut self, invite: impl IntoIterator<Item = OwnedUserId>) -> Self { |
| 156 | self.invite = invite.into_iter().collect(); |
| 157 | self |
| 158 | } |
| 159 | |
| 160 | #[must_use] |
| 161 | pub const fn with_direct(mut self, direct: bool) -> Self { |
| 162 | self.direct = direct; |
| 163 | self |
| 164 | } |
| 165 | |
| 166 | #[must_use] |
| 167 | pub const fn with_visibility(mut self, visibility: RoomVisibility) -> Self { |
| 168 | self.visibility = visibility; |
| 169 | self |
| 170 | } |
| 171 | |
| 172 | #[must_use] |
| 173 | pub const fn with_preset(mut self, preset: RoomPreset) -> Self { |
| 174 | self.preset = Some(preset); |
| 175 | self |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] |
| 180 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 181 | pub enum RoomVisibility { |
| 182 | #[default] |
| 183 | Private, |
| 184 | Public, |
| 185 | } |
| 186 | |
| 187 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 188 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 189 | pub enum RoomPreset { |
| 190 | PrivateChat, |
| 191 | TrustedPrivateChat, |
| 192 | PublicChat, |
| 193 | } |
| 194 | |
| 195 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 196 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 197 | #[non_exhaustive] |
| 198 | pub enum TimelineCommand { |
| 199 | OpenThread { |
| 200 | room_id: OwnedRoomId, |
| 201 | root_event_id: OwnedEventId, |
| 202 | }, |
| 203 | CloseThread { |
| 204 | room_id: OwnedRoomId, |
| 205 | root_event_id: OwnedEventId, |
| 206 | }, |
| 207 | /// Re-emit an authoritative reset for an open room or thread without |
| 208 | /// closing it. The reset arrives before this command's terminal result. |
| 209 | Resync { |
| 210 | timeline_id: TimelineId, |
| 211 | }, |
| 212 | Paginate { |
| 213 | timeline_id: TimelineId, |
| 214 | limit: u16, |
| 215 | }, |
| 216 | Send { |
| 217 | timeline_id: TimelineId, |
| 218 | content: MessageContent, |
| 219 | }, |
| 220 | Edit { |
| 221 | timeline_id: TimelineId, |
| 222 | target: EventRef, |
| 223 | content: MessageEditContent, |
| 224 | }, |
| 225 | /// redacting your own unsent message just cancels it |
| 226 | Redact { |
| 227 | timeline_id: TimelineId, |
| 228 | target: EventRef, |
| 229 | reason: Option<String>, |
| 230 | }, |
| 231 | ToggleReaction { |
| 232 | timeline_id: TimelineId, |
| 233 | target: EventRef, |
| 234 | key: String, |
| 235 | }, |
| 236 | /// works on a closed room too, it just can't refuse to move the marker backwards |
| 237 | MarkRead { |
| 238 | timeline_id: TimelineId, |
| 239 | event_id: OwnedEventId, |
| 240 | }, |
| 241 | } |
| 242 | |
| 243 | impl TimelineCommand { |
| 244 | #[must_use] |
| 245 | pub const fn room_id(&self) -> &OwnedRoomId { |
| 246 | match self { |
| 247 | Self::OpenThread { room_id, .. } | Self::CloseThread { room_id, .. } => room_id, |
| 248 | Self::Resync { timeline_id } |
| 249 | | Self::Paginate { timeline_id, .. } |
| 250 | | Self::Send { timeline_id, .. } |
| 251 | | Self::Edit { timeline_id, .. } |
| 252 | | Self::Redact { timeline_id, .. } |
| 253 | | Self::ToggleReaction { timeline_id, .. } |
| 254 | | Self::MarkRead { timeline_id, .. } => timeline_id.room_id(), |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | #[must_use] |
| 259 | pub const fn timeline_id(&self) -> Option<&TimelineId> { |
| 260 | match self { |
| 261 | Self::OpenThread { .. } | Self::CloseThread { .. } => None, |
| 262 | Self::Resync { timeline_id } |
| 263 | | Self::Paginate { timeline_id, .. } |
| 264 | | Self::Send { timeline_id, .. } |
| 265 | | Self::Edit { timeline_id, .. } |
| 266 | | Self::Redact { timeline_id, .. } |
| 267 | | Self::ToggleReaction { timeline_id, .. } |
| 268 | | Self::MarkRead { timeline_id, .. } => Some(timeline_id), |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | #[derive(Clone, Debug, Eq, Hash, PartialEq)] |
| 274 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 275 | #[non_exhaustive] |
| 276 | pub enum TimelineId { |
| 277 | Room(OwnedRoomId), |
| 278 | Thread { |
| 279 | room_id: OwnedRoomId, |
| 280 | root_event_id: OwnedEventId, |
| 281 | }, |
| 282 | } |
| 283 | |
| 284 | impl TimelineId { |
| 285 | #[must_use] |
| 286 | pub const fn room_id(&self) -> &OwnedRoomId { |
| 287 | match self { |
| 288 | Self::Room(room_id) | Self::Thread { room_id, .. } => room_id, |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | #[must_use] |
| 293 | pub fn thread(room_id: OwnedRoomId, root_event_id: OwnedEventId) -> Self { |
| 294 | Self::Thread { |
| 295 | room_id, |
| 296 | root_event_id, |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | #[must_use] |
| 301 | pub fn thread_root(&self) -> Option<&OwnedEventId> { |
| 302 | match self { |
| 303 | Self::Room(_) => None, |
| 304 | Self::Thread { root_event_id, .. } => Some(root_event_id), |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | impl From<OwnedRoomId> for TimelineId { |
| 310 | fn from(room_id: OwnedRoomId) -> Self { |
| 311 | Self::Room(room_id) |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 316 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 317 | #[non_exhaustive] |
| 318 | pub enum MediaCommand { |
| 319 | /// succeeds once the send queue has it. progress and failure arrive as events |
| 320 | Upload(AttachmentUpload), |
| 321 | } |
| 322 | |
| 323 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 324 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 325 | #[non_exhaustive] |
| 326 | pub struct AttachmentUpload { |
| 327 | pub timeline_id: TimelineId, |
| 328 | pub filename: String, |
| 329 | pub mimetype: String, |
| 330 | pub bytes: Vec<u8>, |
| 331 | pub caption: Option<String>, |
| 332 | pub details: Option<UploadDetails>, |
| 333 | pub thumbnail: Option<UploadThumbnail>, |
| 334 | } |
| 335 | |
| 336 | impl AttachmentUpload { |
| 337 | #[must_use] |
| 338 | pub fn new( |
| 339 | timeline_id: impl Into<TimelineId>, |
| 340 | filename: impl Into<String>, |
| 341 | mimetype: impl Into<String>, |
| 342 | bytes: Vec<u8>, |
| 343 | ) -> Self { |
| 344 | Self { |
| 345 | timeline_id: timeline_id.into(), |
| 346 | filename: filename.into(), |
| 347 | mimetype: mimetype.into(), |
| 348 | bytes, |
| 349 | caption: None, |
| 350 | details: None, |
| 351 | thumbnail: None, |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 357 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 358 | #[non_exhaustive] |
| 359 | pub enum UploadDetails { |
| 360 | Image { |
| 361 | width: Option<u32>, |
| 362 | height: Option<u32>, |
| 363 | blurhash: Option<String>, |
| 364 | }, |
| 365 | Video { |
| 366 | width: Option<u32>, |
| 367 | height: Option<u32>, |
| 368 | duration_ms: Option<u64>, |
| 369 | blurhash: Option<String>, |
| 370 | }, |
| 371 | Audio { |
| 372 | duration_ms: Option<u64>, |
| 373 | }, |
| 374 | Voice { |
| 375 | duration_ms: u64, |
| 376 | waveform: Vec<u16>, |
| 377 | }, |
| 378 | File, |
| 379 | } |
| 380 | |
| 381 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 382 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 383 | #[non_exhaustive] |
| 384 | pub struct UploadThumbnail { |
| 385 | pub bytes: Vec<u8>, |
| 386 | pub mimetype: String, |
| 387 | pub width: u32, |
| 388 | pub height: u32, |
| 389 | } |
| 390 | |
| 391 | impl UploadThumbnail { |
| 392 | #[must_use] |
| 393 | pub fn new(bytes: Vec<u8>, mimetype: impl Into<String>, width: u32, height: u32) -> Self { |
| 394 | Self { |
| 395 | bytes, |
| 396 | mimetype: mimetype.into(), |
| 397 | width, |
| 398 | height, |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | #[derive(Eq, PartialEq)] |
| 404 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 405 | #[non_exhaustive] |
| 406 | pub enum EncryptionCommand { |
| 407 | Recover(String), |
| 408 | CreateKeyBackup, |
| 409 | EnableKeyBackup, |
| 410 | DisableKeyBackup { delete_from_server: bool }, |
| 411 | RecoverKeyBackup(String), |
| 412 | StartVerification(VerificationTarget), |
| 413 | Verify(VerificationAction), |
| 414 | } |
| 415 | |
| 416 | impl fmt::Debug for EncryptionCommand { |
| 417 | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 418 | match self { |
| 419 | Self::Recover(_) => formatter.debug_tuple("Recover").field(&"...").finish(), |
| 420 | Self::CreateKeyBackup => formatter.write_str("CreateKeyBackup"), |
| 421 | Self::EnableKeyBackup => formatter.write_str("EnableKeyBackup"), |
| 422 | Self::DisableKeyBackup { delete_from_server } => formatter |
| 423 | .debug_struct("DisableKeyBackup") |
| 424 | .field("delete_from_server", delete_from_server) |
| 425 | .finish(), |
| 426 | Self::RecoverKeyBackup(_) => formatter |
| 427 | .debug_tuple("RecoverKeyBackup") |
| 428 | .field(&"...") |
| 429 | .finish(), |
| 430 | Self::StartVerification(target) => formatter |
| 431 | .debug_tuple("StartVerification") |
| 432 | .field(target) |
| 433 | .finish(), |
| 434 | Self::Verify(action) => formatter.debug_tuple("Verify").field(action).finish(), |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 440 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 441 | #[non_exhaustive] |
| 442 | pub enum NotificationCommand { |
| 443 | SetRoomMode { |
| 444 | room_id: OwnedRoomId, |
| 445 | mode: RoomNotificationMode, |
| 446 | }, |
| 447 | ResetRoomMode(OwnedRoomId), |
| 448 | SetDefaultMode { |
| 449 | encrypted: bool, |
| 450 | one_to_one: bool, |
| 451 | mode: RoomNotificationMode, |
| 452 | }, |
| 453 | AddKeyword(String), |
| 454 | RemoveKeyword(String), |
| 455 | } |
| 456 | |
| 457 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 458 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 459 | #[non_exhaustive] |
| 460 | pub enum LifecycleCommand { |
| 461 | Shutdown, |
| 462 | } |
| 463 | |
| 464 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 465 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 466 | #[non_exhaustive] |
| 467 | pub enum CommandOutput { |
| 468 | Done, |
| 469 | Room(OwnedRoomId), |
| 470 | } |
| 471 | |
| 472 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 473 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 474 | #[non_exhaustive] |
| 475 | pub enum MessageContent { |
| 476 | Text { |
| 477 | content: RichText, |
| 478 | mentions: MessageMentions, |
| 479 | }, |
| 480 | Emote { |
| 481 | content: RichText, |
| 482 | mentions: MessageMentions, |
| 483 | }, |
| 484 | Reply { |
| 485 | event_id: OwnedEventId, |
| 486 | content: RichText, |
| 487 | mentions: MessageMentions, |
| 488 | notify_replied_to: bool, |
| 489 | }, |
| 490 | } |
| 491 | |
| 492 | impl MessageContent { |
| 493 | #[must_use] |
| 494 | pub fn text(body: impl Into<String>) -> Self { |
| 495 | Self::Text { |
| 496 | content: RichText::plain(body), |
| 497 | mentions: MessageMentions::default(), |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | #[must_use] |
| 502 | pub fn html(body: impl Into<String>, formatted_body: impl Into<String>) -> Self { |
| 503 | Self::Text { |
| 504 | content: RichText::html(body, formatted_body), |
| 505 | mentions: MessageMentions::default(), |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | #[must_use] |
| 510 | pub fn emote(content: RichText, mentions: MessageMentions) -> Self { |
| 511 | Self::Emote { content, mentions } |
| 512 | } |
| 513 | |
| 514 | #[must_use] |
| 515 | pub fn reply(event_id: OwnedEventId, content: RichText, mentions: MessageMentions) -> Self { |
| 516 | Self::Reply { |
| 517 | event_id, |
| 518 | content, |
| 519 | mentions, |
| 520 | notify_replied_to: true, |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | #[must_use] |
| 525 | pub fn reply_without_notification( |
| 526 | event_id: OwnedEventId, |
| 527 | content: RichText, |
| 528 | mentions: MessageMentions, |
| 529 | ) -> Self { |
| 530 | Self::Reply { |
| 531 | event_id, |
| 532 | content, |
| 533 | mentions, |
| 534 | notify_replied_to: false, |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 540 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 541 | #[non_exhaustive] |
| 542 | pub enum MessageEditContent { |
| 543 | Text { |
| 544 | content: RichText, |
| 545 | mentions: MessageMentions, |
| 546 | }, |
| 547 | Emote { |
| 548 | content: RichText, |
| 549 | mentions: MessageMentions, |
| 550 | }, |
| 551 | } |
| 552 | |
| 553 | impl MessageEditContent { |
| 554 | #[must_use] |
| 555 | pub fn text(body: impl Into<String>) -> Self { |
| 556 | Self::Text { |
| 557 | content: RichText::plain(body), |
| 558 | mentions: MessageMentions::default(), |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | #[must_use] |
| 563 | pub fn html(body: impl Into<String>, formatted_body: impl Into<String>) -> Self { |
| 564 | Self::Text { |
| 565 | content: RichText::html(body, formatted_body), |
| 566 | mentions: MessageMentions::default(), |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | #[must_use] |
| 571 | pub fn emote(content: RichText, mentions: MessageMentions) -> Self { |
| 572 | Self::Emote { content, mentions } |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | #[derive(Clone, Debug, Default, Eq, PartialEq)] |
| 577 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 578 | #[non_exhaustive] |
| 579 | pub struct RichText { |
| 580 | pub body: String, |
| 581 | pub formatted_body: Option<String>, |
| 582 | } |
| 583 | |
| 584 | impl RichText { |
| 585 | #[must_use] |
| 586 | pub fn plain(body: impl Into<String>) -> Self { |
| 587 | Self { |
| 588 | body: body.into(), |
| 589 | formatted_body: None, |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | #[must_use] |
| 594 | pub fn html(body: impl Into<String>, formatted_body: impl Into<String>) -> Self { |
| 595 | Self { |
| 596 | body: body.into(), |
| 597 | formatted_body: Some(formatted_body.into()), |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | #[derive(Clone, Debug, Default, Eq, PartialEq)] |
| 603 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 604 | #[non_exhaustive] |
| 605 | pub struct MessageMentions { |
| 606 | pub user_ids: Vec<OwnedUserId>, |
| 607 | pub room: bool, |
| 608 | } |
| 609 | |
| 610 | impl MessageMentions { |
| 611 | #[must_use] |
| 612 | pub fn with_user_ids(user_ids: impl IntoIterator<Item = OwnedUserId>) -> Self { |
| 613 | Self { |
| 614 | user_ids: user_ids.into_iter().collect(), |
| 615 | room: false, |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | #[must_use] |
| 620 | pub fn room() -> Self { |
| 621 | Self { |
| 622 | user_ids: Vec::new(), |
| 623 | room: true, |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 629 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 630 | #[non_exhaustive] |
| 631 | pub enum Event { |
| 632 | ConnectionChanged(ConnectionState), |
| 633 | Authenticated { |
| 634 | user_id: OwnedUserId, |
| 635 | }, |
| 636 | /// Refresh tokens changed. Persist a fresh `ClientHandle::session_record()` |
| 637 | /// atomically; a record captured before this event may no longer restore. |
| 638 | SessionTokensChanged, |
| 639 | /// the server stopped honouring our token and the engine stops. on a soft |
| 640 | /// logout keep the store and log in again with the same device, otherwise |
| 641 | /// the record and the store are both dead |
| 642 | SessionAccessRejected { |
| 643 | soft_logout: bool, |
| 644 | }, |
| 645 | NotificationSettingsChanged, |
| 646 | VerificationTargetChanged(VerificationTarget), |
| 647 | RoomsChanged, |
| 648 | /// replaces whatever you had for this timeline. every diff after it applies to it |
| 649 | TimelineReset { |
| 650 | timeline_id: TimelineId, |
| 651 | items: Vec<TimelineItem>, |
| 652 | }, |
| 653 | TimelineChanged { |
| 654 | timeline_id: TimelineId, |
| 655 | diffs: Vec<TimelineDiff>, |
| 656 | }, |
| 657 | HistoryChanged { |
| 658 | timeline_id: TimelineId, |
| 659 | state: HistoryState, |
| 660 | }, |
| 661 | TypingChanged(TypingState), |
| 662 | MediaUploadProgress { |
| 663 | room_id: OwnedRoomId, |
| 664 | transaction_id: OwnedTransactionId, |
| 665 | uploaded_bytes: u64, |
| 666 | total_bytes: u64, |
| 667 | complete: bool, |
| 668 | }, |
| 669 | MediaUploadFailed { |
| 670 | room_id: OwnedRoomId, |
| 671 | transaction_id: OwnedTransactionId, |
| 672 | kind: crate::ErrorKind, |
| 673 | recoverable: bool, |
| 674 | }, |
| 675 | EncryptionChanged(EncryptionState), |
| 676 | VerificationChanged(VerificationState), |
| 677 | /// logout went through and the engine stops. delete the record and the store |
| 678 | LoggedOut, |
| 679 | Failed(EngineFailure), |
| 680 | /// always the last event. keep the saved record unless `LoggedOut` or a |
| 681 | /// hard `SessionAccessRejected` came first. commands still in flight answer `Interrupted` |
| 682 | Stopped, |
| 683 | } |
| 684 | |
| 685 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 686 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 687 | #[non_exhaustive] |
| 688 | pub enum ConnectionState { |
| 689 | Idle, |
| 690 | Connecting, |
| 691 | Online, |
| 692 | Offline, |
| 693 | Stopped, |
| 694 | } |
| 695 | |
| 696 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 697 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 698 | #[non_exhaustive] |
| 699 | pub struct RoomSummary { |
| 700 | pub room_id: OwnedRoomId, |
| 701 | pub name: String, |
| 702 | pub membership: RoomMembership, |
| 703 | pub unread_messages: u64, |
| 704 | pub unread_mentions: u64, |
| 705 | /// unread events the push rules said to notify about, which is neither of the above |
| 706 | pub unread_notifications: u64, |
| 707 | pub encrypted: bool, |
| 708 | pub space: bool, |
| 709 | pub direct: bool, |
| 710 | pub favourite: bool, |
| 711 | pub low_priority: bool, |
| 712 | pub avatar: Option<OwnedMxcUri>, |
| 713 | pub latest_event_timestamp_ms: Option<u64>, |
| 714 | pub latest_event: Option<LatestEvent>, |
| 715 | pub notification_mode: Option<RoomNotificationMode>, |
| 716 | pub notification_mode_custom: bool, |
| 717 | pub topic: Option<String>, |
| 718 | pub canonical_alias: Option<OwnedRoomAliasId>, |
| 719 | pub joined_members: u64, |
| 720 | pub invited_members: u64, |
| 721 | /// who a nameless room gets named after |
| 722 | pub heroes: Vec<RoomHero>, |
| 723 | /// set once the room has been upgraded, this is where everyone went |
| 724 | pub successor: Option<OwnedRoomId>, |
| 725 | pub inviter: Option<OwnedUserId>, |
| 726 | /// joined spaces that list this room as a child |
| 727 | pub parent_spaces: Vec<OwnedRoomId>, |
| 728 | /// for a space, the children it lists, joined or not |
| 729 | pub children: Vec<OwnedRoomId>, |
| 730 | } |
| 731 | |
| 732 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 733 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 734 | #[non_exhaustive] |
| 735 | pub struct RoomHero { |
| 736 | pub user_id: OwnedUserId, |
| 737 | pub display_name: Option<String>, |
| 738 | pub avatar: Option<OwnedMxcUri>, |
| 739 | } |
| 740 | |
| 741 | /// enough for a room list preview line. `kind` and `body` are only set for messages, |
| 742 | /// and an edit shows its new text |
| 743 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 744 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 745 | #[non_exhaustive] |
| 746 | pub struct LatestEvent { |
| 747 | pub sender: Option<OwnedUserId>, |
| 748 | pub kind: Option<MessageKind>, |
| 749 | pub body: Option<String>, |
| 750 | pub timestamp_ms: Option<u64>, |
| 751 | pub send_state: SendState, |
| 752 | } |
| 753 | |
| 754 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 755 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 756 | #[non_exhaustive] |
| 757 | pub struct Profile { |
| 758 | pub user_id: OwnedUserId, |
| 759 | pub display_name: Option<String>, |
| 760 | pub avatar: Option<OwnedMxcUri>, |
| 761 | } |
| 762 | |
| 763 | /// one room in a space's hierarchy, as the server describes it, which may be a room you're not in |
| 764 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 765 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 766 | #[non_exhaustive] |
| 767 | pub struct SpaceChild { |
| 768 | pub room_id: OwnedRoomId, |
| 769 | pub name: String, |
| 770 | pub topic: Option<String>, |
| 771 | pub avatar: Option<OwnedMxcUri>, |
| 772 | pub canonical_alias: Option<OwnedRoomAliasId>, |
| 773 | pub joined_members: u64, |
| 774 | pub space: bool, |
| 775 | pub children_count: u64, |
| 776 | pub membership: Option<RoomMembership>, |
| 777 | pub via: Vec<OwnedServerName>, |
| 778 | pub suggested: bool, |
| 779 | pub world_readable: Option<bool>, |
| 780 | pub guest_can_join: bool, |
| 781 | } |
| 782 | |
| 783 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 784 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 785 | #[non_exhaustive] |
| 786 | pub enum RoomNotificationMode { |
| 787 | AllMessages, |
| 788 | MentionsAndKeywordsOnly, |
| 789 | Mute, |
| 790 | } |
| 791 | |
| 792 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 793 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 794 | #[non_exhaustive] |
| 795 | pub struct RoomNotificationSettings { |
| 796 | pub mode: RoomNotificationMode, |
| 797 | pub custom: bool, |
| 798 | } |
| 799 | |
| 800 | #[derive(Clone, Debug)] |
| 801 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 802 | #[non_exhaustive] |
| 803 | pub enum PushNotificationStatus { |
| 804 | Event(Box<PushNotification>), |
| 805 | NotFound, |
| 806 | FilteredOut, |
| 807 | Redacted, |
| 808 | } |
| 809 | |
| 810 | #[derive(Clone, Debug)] |
| 811 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 812 | #[non_exhaustive] |
| 813 | pub struct PushNotification { |
| 814 | pub event_id: OwnedEventId, |
| 815 | pub event: PushNotificationEvent, |
| 816 | pub sender: PushNotificationSender, |
| 817 | pub room: PushNotificationRoom, |
| 818 | pub noisy: Option<bool>, |
| 819 | pub has_mention: Option<bool>, |
| 820 | pub thread_id: Option<OwnedEventId>, |
| 821 | } |
| 822 | |
| 823 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 824 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 825 | #[non_exhaustive] |
| 826 | pub struct PushNotificationSender { |
| 827 | pub user_id: OwnedUserId, |
| 828 | pub display_name: Option<String>, |
| 829 | pub avatar_url: Option<OwnedMxcUri>, |
| 830 | pub name_ambiguous: bool, |
| 831 | } |
| 832 | |
| 833 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 834 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 835 | #[non_exhaustive] |
| 836 | pub struct PushNotificationRoom { |
| 837 | pub room_id: OwnedRoomId, |
| 838 | pub name: String, |
| 839 | pub avatar_url: Option<OwnedMxcUri>, |
| 840 | pub canonical_alias: Option<OwnedRoomAliasId>, |
| 841 | pub topic: Option<String>, |
| 842 | pub encrypted: Option<bool>, |
| 843 | pub direct: bool, |
| 844 | pub joined_members_count: u64, |
| 845 | pub service_members: Vec<OwnedUserId>, |
| 846 | pub active_service_members_count: u64, |
| 847 | pub space: bool, |
| 848 | } |
| 849 | |
| 850 | #[derive(Clone, Debug)] |
| 851 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 852 | #[non_exhaustive] |
| 853 | pub enum PushNotificationEvent { |
| 854 | Timeline(Raw<AnySyncTimelineEvent>), |
| 855 | Invite(Raw<StrippedRoomMemberEvent>), |
| 856 | } |
| 857 | |
| 858 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 859 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 860 | #[non_exhaustive] |
| 861 | pub struct RoomPowerLevels { |
| 862 | pub ban: i64, |
| 863 | pub invite: i64, |
| 864 | pub kick: i64, |
| 865 | pub redact: i64, |
| 866 | pub events_default: i64, |
| 867 | pub state_default: i64, |
| 868 | pub users_default: i64, |
| 869 | pub room_notification: i64, |
| 870 | pub users: Vec<(OwnedUserId, i64)>, |
| 871 | pub events: Vec<(String, i64)>, |
| 872 | /// in rooms from version 12 the creators outrank everyone and aren't listed in `users` |
| 873 | pub creators: Vec<OwnedUserId>, |
| 874 | } |
| 875 | |
| 876 | #[derive(Clone, Debug, Default, Eq, PartialEq)] |
| 877 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 878 | #[non_exhaustive] |
| 879 | pub struct PowerLevelChanges { |
| 880 | pub ban: Option<i64>, |
| 881 | pub invite: Option<i64>, |
| 882 | pub kick: Option<i64>, |
| 883 | pub redact: Option<i64>, |
| 884 | pub events_default: Option<i64>, |
| 885 | pub state_default: Option<i64>, |
| 886 | pub users_default: Option<i64>, |
| 887 | pub room_notification: Option<i64>, |
| 888 | pub room_name: Option<i64>, |
| 889 | pub room_avatar: Option<i64>, |
| 890 | pub room_topic: Option<i64>, |
| 891 | pub space_child: Option<i64>, |
| 892 | pub beacon: Option<i64>, |
| 893 | pub beacon_info: Option<i64>, |
| 894 | } |
| 895 | |
| 896 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 897 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 898 | #[non_exhaustive] |
| 899 | pub enum RoomMembership { |
| 900 | Joined, |
| 901 | Invited, |
| 902 | Left, |
| 903 | Knocked, |
| 904 | Banned, |
| 905 | } |
| 906 | |
| 907 | #[derive(Clone, Debug, Default, Eq, PartialEq)] |
| 908 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 909 | #[non_exhaustive] |
| 910 | pub struct RoomListFilter { |
| 911 | pub membership: Option<RoomMembership>, |
| 912 | pub category: Option<RoomCategory>, |
| 913 | pub favourite: Option<bool>, |
| 914 | pub unread_only: bool, |
| 915 | pub search: Option<String>, |
| 916 | } |
| 917 | |
| 918 | impl RoomListFilter { |
| 919 | #[must_use] |
| 920 | pub fn with_membership(mut self, membership: RoomMembership) -> Self { |
| 921 | self.membership = Some(membership); |
| 922 | self |
| 923 | } |
| 924 | |
| 925 | #[must_use] |
| 926 | pub fn with_category(mut self, category: RoomCategory) -> Self { |
| 927 | self.category = Some(category); |
| 928 | self |
| 929 | } |
| 930 | |
| 931 | #[must_use] |
| 932 | pub fn with_favourite(mut self, favourite: bool) -> Self { |
| 933 | self.favourite = Some(favourite); |
| 934 | self |
| 935 | } |
| 936 | |
| 937 | #[must_use] |
| 938 | pub const fn with_unread_only(mut self, unread_only: bool) -> Self { |
| 939 | self.unread_only = unread_only; |
| 940 | self |
| 941 | } |
| 942 | |
| 943 | #[must_use] |
| 944 | pub fn with_search(mut self, search: impl Into<String>) -> Self { |
| 945 | self.search = Some(search.into()); |
| 946 | self |
| 947 | } |
| 948 | |
| 949 | #[must_use] |
| 950 | pub fn matches(&self, room: &RoomSummary) -> bool { |
| 951 | self.matcher().matches(room) |
| 952 | } |
| 953 | |
| 954 | /// lowercases the search once, for filtering a whole list |
| 955 | #[must_use] |
| 956 | pub fn matcher(&self) -> RoomMatcher<'_> { |
| 957 | RoomMatcher { |
| 958 | filter: self, |
| 959 | search: self.search.as_deref().map(str::to_lowercase), |
| 960 | } |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | #[derive(Debug)] |
| 965 | pub struct RoomMatcher<'a> { |
| 966 | filter: &'a RoomListFilter, |
| 967 | search: Option<String>, |
| 968 | } |
| 969 | |
| 970 | impl RoomMatcher<'_> { |
| 971 | #[must_use] |
| 972 | pub fn matches(&self, room: &RoomSummary) -> bool { |
| 973 | let filter = self.filter; |
| 974 | filter |
| 975 | .membership |
| 976 | .is_none_or(|membership| room.membership == membership) |
| 977 | && filter.category.is_none_or(|category| match category { |
| 978 | RoomCategory::People => room.direct && !room.space, |
| 979 | RoomCategory::Rooms => !room.direct && !room.space, |
| 980 | RoomCategory::Spaces => room.space, |
| 981 | }) |
| 982 | && filter |
| 983 | .favourite |
| 984 | .is_none_or(|favourite| room.favourite == favourite) |
| 985 | && (!filter.unread_only || room.unread_messages > 0 || room.unread_mentions > 0) |
| 986 | && self.search.as_ref().is_none_or(|search| { |
| 987 | room.name.to_lowercase().contains(search) |
| 988 | || room.room_id.as_str().to_lowercase().contains(search) |
| 989 | }) |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 994 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 995 | #[non_exhaustive] |
| 996 | pub enum RoomCategory { |
| 997 | People, |
| 998 | Rooms, |
| 999 | Spaces, |
| 1000 | } |
| 1001 | |
| 1002 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 1003 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1004 | #[non_exhaustive] |
| 1005 | pub enum MemberFilter { |
| 1006 | Active, |
| 1007 | Joined, |
| 1008 | Invited, |
| 1009 | Banned, |
| 1010 | Left, |
| 1011 | All, |
| 1012 | } |
| 1013 | |
| 1014 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1015 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1016 | #[non_exhaustive] |
| 1017 | pub enum MemberMembership { |
| 1018 | Joined, |
| 1019 | Invited, |
| 1020 | Left, |
| 1021 | Knocked, |
| 1022 | Banned, |
| 1023 | Custom(String), |
| 1024 | } |
| 1025 | |
| 1026 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1027 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1028 | #[non_exhaustive] |
| 1029 | pub struct MemberSummary { |
| 1030 | pub user_id: OwnedUserId, |
| 1031 | pub name: String, |
| 1032 | pub display_name: Option<String>, |
| 1033 | pub avatar: Option<OwnedMxcUri>, |
| 1034 | pub membership: MemberMembership, |
| 1035 | pub own: bool, |
| 1036 | pub name_ambiguous: bool, |
| 1037 | pub ignored: bool, |
| 1038 | pub service: bool, |
| 1039 | } |
| 1040 | |
| 1041 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1042 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1043 | #[non_exhaustive] |
| 1044 | pub struct OwnDevice { |
| 1045 | pub device_id: OwnedDeviceId, |
| 1046 | pub display_name: Option<String>, |
| 1047 | pub last_seen_ip: Option<String>, |
| 1048 | pub last_seen_timestamp_ms: Option<u64>, |
| 1049 | pub current: bool, |
| 1050 | } |
| 1051 | |
| 1052 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1053 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1054 | #[non_exhaustive] |
| 1055 | pub enum TimelineItem { |
| 1056 | Event(Box<TimelineEvent>), |
| 1057 | DayDivider { timestamp_ms: u64 }, |
| 1058 | ReadMarker, |
| 1059 | TimelineStart, |
| 1060 | } |
| 1061 | |
| 1062 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1063 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1064 | #[non_exhaustive] |
| 1065 | pub enum TimelineDiff { |
| 1066 | Append { values: Vec<TimelineItem> }, |
| 1067 | Clear, |
| 1068 | PushFront { value: TimelineItem }, |
| 1069 | PushBack { value: TimelineItem }, |
| 1070 | PopFront, |
| 1071 | PopBack, |
| 1072 | Insert { index: usize, value: TimelineItem }, |
| 1073 | Set { index: usize, value: TimelineItem }, |
| 1074 | Remove { index: usize }, |
| 1075 | Truncate { length: usize }, |
| 1076 | Reset { values: Vec<TimelineItem> }, |
| 1077 | } |
| 1078 | |
| 1079 | #[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)] |
| 1080 | #[error("timeline diff is incompatible with the current {length}-item snapshot")] |
| 1081 | pub struct TimelineDiffError { |
| 1082 | pub length: usize, |
| 1083 | } |
| 1084 | |
| 1085 | impl TimelineDiff { |
| 1086 | /// Apply a diff only when its indices match the current snapshot. |
| 1087 | /// On error the snapshot is unchanged; request `TimelineCommand::Resync` |
| 1088 | /// and ignore further diffs until the corresponding `TimelineReset`. |
| 1089 | pub fn try_apply(self, items: &mut Vec<TimelineItem>) -> Result<(), TimelineDiffError> { |
| 1090 | let length = items.len(); |
| 1091 | match self { |
| 1092 | Self::Append { values } => items.extend(values), |
| 1093 | Self::Clear => items.clear(), |
| 1094 | Self::PushFront { value } => items.insert(0, value), |
| 1095 | Self::PushBack { value } => items.push(value), |
| 1096 | Self::PopFront if length == 0 => return Err(TimelineDiffError { length }), |
| 1097 | Self::PopFront => { |
| 1098 | items.remove(0); |
| 1099 | } |
| 1100 | Self::PopBack if length == 0 => return Err(TimelineDiffError { length }), |
| 1101 | Self::PopBack => { |
| 1102 | items.pop(); |
| 1103 | } |
| 1104 | Self::Insert { index, .. } if index > length => { |
| 1105 | return Err(TimelineDiffError { length }); |
| 1106 | } |
| 1107 | Self::Insert { index, value } => items.insert(index, value), |
| 1108 | Self::Set { index, .. } if index >= length => return Err(TimelineDiffError { length }), |
| 1109 | Self::Set { index, value } => items[index] = value, |
| 1110 | Self::Remove { index } if index >= length => return Err(TimelineDiffError { length }), |
| 1111 | Self::Remove { index } => { |
| 1112 | items.remove(index); |
| 1113 | } |
| 1114 | Self::Truncate { length: target } if target > length => { |
| 1115 | return Err(TimelineDiffError { length }); |
| 1116 | } |
| 1117 | Self::Truncate { length } => items.truncate(length), |
| 1118 | Self::Reset { values } => *items = values, |
| 1119 | } |
| 1120 | Ok(()) |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | #[cfg(test)] |
| 1125 | mod tests { |
| 1126 | use super::{TimelineDiff, TimelineItem}; |
| 1127 | |
| 1128 | fn item(timestamp_ms: u64) -> TimelineItem { |
| 1129 | TimelineItem::DayDivider { timestamp_ms } |
| 1130 | } |
| 1131 | |
| 1132 | #[test] |
| 1133 | fn timeline_diff_try_apply_handles_every_variant() { |
| 1134 | let mut items = vec![item(1), item(2)]; |
| 1135 | |
| 1136 | TimelineDiff::Append { |
| 1137 | values: vec![item(3)], |
| 1138 | } |
| 1139 | .try_apply(&mut items) |
| 1140 | .unwrap(); |
| 1141 | assert_eq!(items, vec![item(1), item(2), item(3)]); |
| 1142 | |
| 1143 | TimelineDiff::Clear.try_apply(&mut items).unwrap(); |
| 1144 | assert!(items.is_empty()); |
| 1145 | |
| 1146 | TimelineDiff::PushFront { value: item(2) } |
| 1147 | .try_apply(&mut items) |
| 1148 | .unwrap(); |
| 1149 | TimelineDiff::PushBack { value: item(3) } |
| 1150 | .try_apply(&mut items) |
| 1151 | .unwrap(); |
| 1152 | assert_eq!(items, vec![item(2), item(3)]); |
| 1153 | |
| 1154 | TimelineDiff::PopFront.try_apply(&mut items).unwrap(); |
| 1155 | TimelineDiff::PopBack.try_apply(&mut items).unwrap(); |
| 1156 | assert!(items.is_empty()); |
| 1157 | |
| 1158 | TimelineDiff::Reset { |
| 1159 | values: vec![item(1), item(3)], |
| 1160 | } |
| 1161 | .try_apply(&mut items) |
| 1162 | .unwrap(); |
| 1163 | TimelineDiff::Insert { |
| 1164 | index: 1, |
| 1165 | value: item(2), |
| 1166 | } |
| 1167 | .try_apply(&mut items) |
| 1168 | .unwrap(); |
| 1169 | assert_eq!(items, vec![item(1), item(2), item(3)]); |
| 1170 | |
| 1171 | TimelineDiff::Set { |
| 1172 | index: 1, |
| 1173 | value: item(4), |
| 1174 | } |
| 1175 | .try_apply(&mut items) |
| 1176 | .unwrap(); |
| 1177 | assert_eq!(items, vec![item(1), item(4), item(3)]); |
| 1178 | |
| 1179 | TimelineDiff::Remove { index: 1 } |
| 1180 | .try_apply(&mut items) |
| 1181 | .unwrap(); |
| 1182 | assert_eq!(items, vec![item(1), item(3)]); |
| 1183 | |
| 1184 | TimelineDiff::Truncate { length: 1 } |
| 1185 | .try_apply(&mut items) |
| 1186 | .unwrap(); |
| 1187 | assert_eq!(items, vec![item(1)]); |
| 1188 | } |
| 1189 | |
| 1190 | #[test] |
| 1191 | fn invalid_timeline_diff_leaves_snapshot_unchanged() { |
| 1192 | let invalid = [ |
| 1193 | TimelineDiff::Insert { |
| 1194 | index: 3, |
| 1195 | value: item(3), |
| 1196 | }, |
| 1197 | TimelineDiff::Set { |
| 1198 | index: 2, |
| 1199 | value: item(3), |
| 1200 | }, |
| 1201 | TimelineDiff::Remove { index: 2 }, |
| 1202 | TimelineDiff::Truncate { length: 3 }, |
| 1203 | ]; |
| 1204 | for diff in invalid { |
| 1205 | let mut items = vec![item(1), item(2)]; |
| 1206 | assert_eq!(diff.try_apply(&mut items).unwrap_err().length, 2); |
| 1207 | assert_eq!(items, vec![item(1), item(2)]); |
| 1208 | } |
| 1209 | for diff in [TimelineDiff::PopFront, TimelineDiff::PopBack] { |
| 1210 | let mut items = Vec::new(); |
| 1211 | assert_eq!(diff.try_apply(&mut items).unwrap_err().length, 0); |
| 1212 | assert!(items.is_empty()); |
| 1213 | } |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | #[derive(Clone, Debug, Eq, Hash, PartialEq)] |
| 1218 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1219 | pub struct TimelineItemId(String); |
| 1220 | |
| 1221 | impl TimelineItemId { |
| 1222 | pub(crate) fn new(value: String) -> Self { |
| 1223 | Self(value) |
| 1224 | } |
| 1225 | |
| 1226 | #[must_use] |
| 1227 | pub fn as_str(&self) -> &str { |
| 1228 | &self.0 |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1233 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1234 | #[non_exhaustive] |
| 1235 | pub struct TimelineEvent { |
| 1236 | pub item_id: TimelineItemId, |
| 1237 | pub event_id: Option<OwnedEventId>, |
| 1238 | pub transaction_id: Option<OwnedTransactionId>, |
| 1239 | pub sender: Sender, |
| 1240 | pub timestamp_ms: u64, |
| 1241 | pub own: bool, |
| 1242 | pub send_state: SendState, |
| 1243 | pub content: TimelineContent, |
| 1244 | pub reply_to: Option<ReplyReference>, |
| 1245 | pub thread_root: Option<OwnedEventId>, |
| 1246 | pub thread_summary: Option<ThreadSummary>, |
| 1247 | pub reactions: Vec<Reaction>, |
| 1248 | pub read_by: Vec<OwnedUserId>, |
| 1249 | pub editable: bool, |
| 1250 | } |
| 1251 | |
| 1252 | impl TimelineEvent { |
| 1253 | /// what to hand edit, redact and react. works before the server has echoed it back |
| 1254 | #[must_use] |
| 1255 | pub fn target(&self) -> Option<EventRef> { |
| 1256 | self.event_id |
| 1257 | .clone() |
| 1258 | .map(EventRef::Remote) |
| 1259 | .or_else(|| self.transaction_id.clone().map(EventRef::Local)) |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | #[derive(Clone, Debug, Eq, Hash, PartialEq)] |
| 1264 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1265 | #[non_exhaustive] |
| 1266 | pub enum EventRef { |
| 1267 | Remote(OwnedEventId), |
| 1268 | /// a local echo, by the transaction id it was queued under |
| 1269 | Local(OwnedTransactionId), |
| 1270 | } |
| 1271 | |
| 1272 | impl From<OwnedEventId> for EventRef { |
| 1273 | fn from(event_id: OwnedEventId) -> Self { |
| 1274 | Self::Remote(event_id) |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1279 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1280 | #[non_exhaustive] |
| 1281 | pub struct Sender { |
| 1282 | pub user_id: OwnedUserId, |
| 1283 | pub display_name: Option<String>, |
| 1284 | pub avatar: Option<OwnedMxcUri>, |
| 1285 | /// someone else in the room goes by the same name, so show the user id too |
| 1286 | pub name_ambiguous: bool, |
| 1287 | } |
| 1288 | |
| 1289 | impl Sender { |
| 1290 | #[must_use] |
| 1291 | pub fn name(&self) -> &str { |
| 1292 | self.display_name |
| 1293 | .as_deref() |
| 1294 | .unwrap_or_else(|| self.user_id.as_str()) |
| 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1299 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1300 | #[non_exhaustive] |
| 1301 | pub enum TimelineContent { |
| 1302 | Message(Message), |
| 1303 | Sticker { |
| 1304 | body: String, |
| 1305 | media: MediaDescriptor, |
| 1306 | }, |
| 1307 | Poll { |
| 1308 | question: String, |
| 1309 | }, |
| 1310 | Redacted, |
| 1311 | UnableToDecrypt(UtdCause), |
| 1312 | Membership { |
| 1313 | user_id: OwnedUserId, |
| 1314 | display_name: Option<String>, |
| 1315 | change: MembershipChange, |
| 1316 | }, |
| 1317 | Profile { |
| 1318 | user_id: OwnedUserId, |
| 1319 | display_name: Option<Change<Option<String>>>, |
| 1320 | avatar: Option<Change<Option<OwnedMxcUri>>>, |
| 1321 | }, |
| 1322 | /// `None` means it was cleared, or the event was redacted |
| 1323 | RoomName(Option<String>), |
| 1324 | RoomTopic(Option<String>), |
| 1325 | RoomAvatar(Option<OwnedMxcUri>), |
| 1326 | EncryptionEnabled, |
| 1327 | RoomCreated, |
| 1328 | RoomUpgraded { |
| 1329 | successor: OwnedRoomId, |
| 1330 | }, |
| 1331 | OtherState { |
| 1332 | event_type: String, |
| 1333 | state_key: String, |
| 1334 | }, |
| 1335 | Other { |
| 1336 | event_type: String, |
| 1337 | }, |
| 1338 | } |
| 1339 | |
| 1340 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1341 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1342 | #[non_exhaustive] |
| 1343 | pub struct Message { |
| 1344 | pub kind: MessageKind, |
| 1345 | pub body: String, |
| 1346 | /// only for `MessageKind::Location` |
| 1347 | pub geo_uri: Option<String>, |
| 1348 | pub formatted_body: Option<String>, |
| 1349 | pub mentions: Option<MessageMentions>, |
| 1350 | pub edited: bool, |
| 1351 | pub media: Option<MediaDescriptor>, |
| 1352 | } |
| 1353 | |
| 1354 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1355 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1356 | #[non_exhaustive] |
| 1357 | pub enum MessageKind { |
| 1358 | Text, |
| 1359 | Emote, |
| 1360 | Notice, |
| 1361 | ServerNotice, |
| 1362 | Image, |
| 1363 | Video, |
| 1364 | Audio, |
| 1365 | File, |
| 1366 | Location, |
| 1367 | VerificationRequest, |
| 1368 | Other(String), |
| 1369 | } |
| 1370 | |
| 1371 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 1372 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1373 | #[non_exhaustive] |
| 1374 | pub enum MembershipChange { |
| 1375 | Joined, |
| 1376 | Left, |
| 1377 | Banned, |
| 1378 | Unbanned, |
| 1379 | Kicked, |
| 1380 | KickedAndBanned, |
| 1381 | Invited, |
| 1382 | InvitationAccepted, |
| 1383 | InvitationRejected, |
| 1384 | InvitationRevoked, |
| 1385 | Knocked, |
| 1386 | KnockAccepted, |
| 1387 | KnockRetracted, |
| 1388 | KnockDenied, |
| 1389 | /// nothing a person would call a change, or something the sdk couldn't make sense of |
| 1390 | Other, |
| 1391 | } |
| 1392 | |
| 1393 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1394 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1395 | pub struct Change<T> { |
| 1396 | pub old: T, |
| 1397 | pub new: T, |
| 1398 | } |
| 1399 | |
| 1400 | /// why a message couldn't be read, worth telling the user since some of these they can fix |
| 1401 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 1402 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1403 | #[non_exhaustive] |
| 1404 | pub enum UtdCause { |
| 1405 | Unknown, |
| 1406 | SentBeforeWeJoined, |
| 1407 | VerificationViolation, |
| 1408 | UnsignedDevice, |
| 1409 | UnknownDevice, |
| 1410 | HistoricalMessageAndBackupIsDisabled, |
| 1411 | WithheldForUnverifiedOrInsecureDevice, |
| 1412 | WithheldBySender, |
| 1413 | HistoricalMessageAndDeviceIsUnverified, |
| 1414 | } |
| 1415 | |
| 1416 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1417 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1418 | #[non_exhaustive] |
| 1419 | pub struct ThreadSummary { |
| 1420 | pub reply_count: u32, |
| 1421 | pub latest_event_id: Option<OwnedEventId>, |
| 1422 | pub latest_event_timestamp_ms: Option<u64>, |
| 1423 | } |
| 1424 | |
| 1425 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 1426 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1427 | #[non_exhaustive] |
| 1428 | pub enum SendState { |
| 1429 | Sent, |
| 1430 | Sending, |
| 1431 | /// `will_retry` means macltok has it in hand. otherwise it's wedged until you |
| 1432 | /// `retry_send` or `cancel_send`, so that's when to show a retry button |
| 1433 | Failed { |
| 1434 | will_retry: bool, |
| 1435 | }, |
| 1436 | } |
| 1437 | |
| 1438 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1439 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1440 | #[non_exhaustive] |
| 1441 | pub struct ReplyReference { |
| 1442 | pub event_id: OwnedEventId, |
| 1443 | pub details: ReplyDetails, |
| 1444 | } |
| 1445 | |
| 1446 | /// the replied-to event. macltok asks for it when it isn't loaded, `Pending` then turns into one of the others |
| 1447 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1448 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1449 | #[non_exhaustive] |
| 1450 | pub enum ReplyDetails { |
| 1451 | Pending, |
| 1452 | Ready { |
| 1453 | sender: Sender, |
| 1454 | content: Box<TimelineContent>, |
| 1455 | timestamp_ms: u64, |
| 1456 | }, |
| 1457 | Unavailable, |
| 1458 | } |
| 1459 | |
| 1460 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1461 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1462 | #[non_exhaustive] |
| 1463 | pub struct Reaction { |
| 1464 | pub key: String, |
| 1465 | pub count: usize, |
| 1466 | pub own: bool, |
| 1467 | pub senders: Vec<OwnedUserId>, |
| 1468 | } |
| 1469 | |
| 1470 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1471 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1472 | #[non_exhaustive] |
| 1473 | pub struct MediaDescriptor { |
| 1474 | pub id: MediaId, |
| 1475 | pub kind: MediaKind, |
| 1476 | pub filename: String, |
| 1477 | pub caption: Option<String>, |
| 1478 | pub mimetype: Option<String>, |
| 1479 | pub size_bytes: Option<u64>, |
| 1480 | pub width: Option<u64>, |
| 1481 | pub height: Option<u64>, |
| 1482 | pub duration_ms: Option<u64>, |
| 1483 | pub blurhash: Option<String>, |
| 1484 | /// the uploader sent a thumbnail, so `MediaSize::Thumbnail` won't need the server to resize |
| 1485 | pub has_thumbnail: bool, |
| 1486 | } |
| 1487 | |
| 1488 | #[derive(Clone, Debug, Eq, Hash, PartialEq)] |
| 1489 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1490 | pub struct MediaId(String); |
| 1491 | |
| 1492 | impl MediaId { |
| 1493 | pub(crate) fn new(value: String) -> Self { |
| 1494 | Self(value) |
| 1495 | } |
| 1496 | |
| 1497 | #[must_use] |
| 1498 | pub fn as_str(&self) -> &str { |
| 1499 | &self.0 |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | /// media ids are opaque but they do have to survive a trip through a browser. a made up one just fails `MediaUnknown` |
| 1504 | impl std::str::FromStr for MediaId { |
| 1505 | type Err = std::convert::Infallible; |
| 1506 | |
| 1507 | fn from_str(value: &str) -> Result<Self, Self::Err> { |
| 1508 | Ok(Self(value.to_owned())) |
| 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | impl From<String> for MediaId { |
| 1513 | fn from(value: String) -> Self { |
| 1514 | Self(value) |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | impl std::fmt::Display for MediaId { |
| 1519 | fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 1520 | self.0.fmt(formatter) |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] |
| 1525 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1526 | #[non_exhaustive] |
| 1527 | pub enum MediaSize { |
| 1528 | Full, |
| 1529 | /// a hint. an uploader's own thumbnail wins over the server resizing anything |
| 1530 | Thumbnail { |
| 1531 | width: u32, |
| 1532 | height: u32, |
| 1533 | }, |
| 1534 | } |
| 1535 | |
| 1536 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1537 | #[non_exhaustive] |
| 1538 | pub struct Media { |
| 1539 | pub bytes: Arc<[u8]>, |
| 1540 | pub mimetype: String, |
| 1541 | } |
| 1542 | |
| 1543 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 1544 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1545 | #[non_exhaustive] |
| 1546 | pub enum MediaKind { |
| 1547 | Image, |
| 1548 | Video, |
| 1549 | Audio, |
| 1550 | File, |
| 1551 | Sticker, |
| 1552 | } |
| 1553 | |
| 1554 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1555 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1556 | #[non_exhaustive] |
| 1557 | pub struct TypingState { |
| 1558 | pub room_id: OwnedRoomId, |
| 1559 | pub users: Vec<OwnedUserId>, |
| 1560 | } |
| 1561 | |
| 1562 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1563 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1564 | #[non_exhaustive] |
| 1565 | pub enum HistoryState { |
| 1566 | Idle, |
| 1567 | Loading, |
| 1568 | StartReached, |
| 1569 | Failed(String), |
| 1570 | } |
| 1571 | |
| 1572 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1573 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1574 | #[non_exhaustive] |
| 1575 | pub struct EncryptionState { |
| 1576 | pub device_id: OwnedDeviceId, |
| 1577 | pub device_verified: bool, |
| 1578 | pub recovery: RecoveryState, |
| 1579 | pub key_backup: KeyBackupState, |
| 1580 | } |
| 1581 | |
| 1582 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 1583 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1584 | #[non_exhaustive] |
| 1585 | pub enum KeyBackupState { |
| 1586 | Unknown, |
| 1587 | Creating, |
| 1588 | Enabling, |
| 1589 | Resuming, |
| 1590 | Downloading, |
| 1591 | Enabled, |
| 1592 | Disabling, |
| 1593 | } |
| 1594 | |
| 1595 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 1596 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1597 | #[non_exhaustive] |
| 1598 | pub enum RecoveryState { |
| 1599 | Unknown, |
| 1600 | Disabled, |
| 1601 | Incomplete, |
| 1602 | Enabled, |
| 1603 | } |
| 1604 | |
| 1605 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 1606 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1607 | #[non_exhaustive] |
| 1608 | pub enum VerificationAction { |
| 1609 | /// take up a request another device sent, which arrives as `VerificationState::Incoming` |
| 1610 | Accept, |
| 1611 | Confirm, |
| 1612 | Reject, |
| 1613 | Cancel, |
| 1614 | } |
| 1615 | |
| 1616 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1617 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1618 | #[non_exhaustive] |
| 1619 | pub enum VerificationTarget { |
| 1620 | OwnIdentity, |
| 1621 | User(OwnedUserId), |
| 1622 | Device { |
| 1623 | user_id: OwnedUserId, |
| 1624 | device_id: OwnedDeviceId, |
| 1625 | }, |
| 1626 | } |
| 1627 | |
| 1628 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1629 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1630 | #[non_exhaustive] |
| 1631 | pub enum VerificationState { |
| 1632 | Waiting, |
| 1633 | /// someone else asked. `Accept` to go ahead, `Cancel` to turn them down |
| 1634 | Incoming { |
| 1635 | user_id: OwnedUserId, |
| 1636 | device_id: Option<OwnedDeviceId>, |
| 1637 | }, |
| 1638 | Comparison { |
| 1639 | emojis: Vec<(String, String)>, |
| 1640 | decimals: (u16, u16, u16), |
| 1641 | }, |
| 1642 | Confirmed, |
| 1643 | Done, |
| 1644 | Cancelled(String), |
| 1645 | Failed(VerificationFailure), |
| 1646 | } |
| 1647 | |
| 1648 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1649 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1650 | #[non_exhaustive] |
| 1651 | pub enum VerificationFailure { |
| 1652 | RequestAcceptance(String), |
| 1653 | SasStartup(String), |
| 1654 | SasAcceptance(String), |
| 1655 | RequestStreamEnded, |
| 1656 | SasStreamEnded, |
| 1657 | } |
| 1658 | |
| 1659 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 1660 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1661 | #[non_exhaustive] |
| 1662 | pub struct EngineFailure { |
| 1663 | pub kind: EngineErrorKind, |
| 1664 | pub message: String, |
| 1665 | } |
| 1666 | |
| 1667 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 1668 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 1669 | #[non_exhaustive] |
| 1670 | pub enum EngineErrorKind { |
| 1671 | EventReceiverClosed, |
| 1672 | Watcher, |
| 1673 | Other, |
| 1674 | } |