|
| 1 | +#[cfg(feature = "unstable-msc4075")] |
| 2 | +use std::collections::BTreeSet; |
| 3 | + |
1 | 4 | use assert_matches2::assert_matches; |
2 | 5 | #[cfg(feature = "unstable-msc2747")] |
3 | 6 | use assign::assign; |
4 | 7 | use js_int::uint; |
| 8 | +#[cfg(feature = "unstable-msc4075")] |
| 9 | +use ruma_common::UserId; |
5 | 10 | use ruma_common::{room_id, serde::CanBeEmpty, MilliSecondsSinceUnixEpoch, VoipVersionId}; |
6 | 11 | #[cfg(feature = "unstable-msc2747")] |
7 | 12 | use ruma_events::call::CallCapabilities; |
| 13 | +#[cfg(feature = "unstable-msc4075")] |
| 14 | +use ruma_events::{ |
| 15 | + call::notify::{ApplicationType, CallNotifyEventContent, NotifyType}, |
| 16 | + Mentions, |
| 17 | +}; |
8 | 18 | use ruma_events::{ |
9 | 19 | call::{ |
10 | 20 | answer::CallAnswerEventContent, |
@@ -598,3 +608,76 @@ fn select_v1_answer_event_deserialization() { |
598 | 608 | assert_eq!(content.selected_party_id, "6336"); |
599 | 609 | assert_eq!(content.version, VoipVersionId::V1); |
600 | 610 | } |
| 611 | +#[cfg(feature = "unstable-msc4075")] |
| 612 | +#[test] |
| 613 | +fn notify_event_serialization() { |
| 614 | + let content_user_mention = CallNotifyEventContent::new( |
| 615 | + "abcdef".into(), |
| 616 | + ApplicationType::Call, |
| 617 | + NotifyType::Ring, |
| 618 | + Mentions::with_user_ids(vec![ |
| 619 | + <&UserId>::try_from("@user:example.com").unwrap().into(), |
| 620 | + <&UserId>::try_from("@user2:example.com").unwrap().into(), |
| 621 | + ]), |
| 622 | + ); |
| 623 | + |
| 624 | + let content_room_mention = CallNotifyEventContent::new( |
| 625 | + "abcdef".into(), |
| 626 | + ApplicationType::Call, |
| 627 | + NotifyType::Ring, |
| 628 | + Mentions::with_room_mention(), |
| 629 | + ); |
| 630 | + |
| 631 | + assert_eq!( |
| 632 | + to_json_value(&content_user_mention).unwrap(), |
| 633 | + json!({ |
| 634 | + "call_id": "abcdef", |
| 635 | + "application": "m.call", |
| 636 | + "m.mentions": {"user_ids": ["@user2:example.com","@user:example.com"]}, |
| 637 | + "notify_type": "ring", |
| 638 | + }) |
| 639 | + ); |
| 640 | + assert_eq!( |
| 641 | + to_json_value(&content_room_mention).unwrap(), |
| 642 | + json!({ |
| 643 | + "call_id": "abcdef", |
| 644 | + "application": "m.call", |
| 645 | + "m.mentions": {"room": true}, |
| 646 | + "notify_type": "ring", |
| 647 | + }) |
| 648 | + ); |
| 649 | +} |
| 650 | + |
| 651 | +#[cfg(feature = "unstable-msc4075")] |
| 652 | +#[test] |
| 653 | +fn notify_event_deserialization() { |
| 654 | + let json_data = json!({ |
| 655 | + "content": { |
| 656 | + "call_id": "abcdef", |
| 657 | + "application": "m.call", |
| 658 | + "m.mentions": {"room": false, "user_ids": ["@user:example.com", "@user2:example.com"]}, |
| 659 | + "notify_type": "ring", |
| 660 | + }, |
| 661 | + "event_id": "$event:notareal.hs", |
| 662 | + "origin_server_ts": 134_829_848, |
| 663 | + "room_id": "!roomid:notareal.hs", |
| 664 | + "sender": "@user:notareal.hs", |
| 665 | + "type": "m.call.notify", |
| 666 | + }); |
| 667 | + |
| 668 | + let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(); |
| 669 | + assert_matches!( |
| 670 | + event, |
| 671 | + AnyMessageLikeEvent::CallNotify(MessageLikeEvent::Original(message_event)) |
| 672 | + ); |
| 673 | + let content = message_event.content; |
| 674 | + assert_eq!(content.call_id, "abcdef"); |
| 675 | + assert!(!content.mentions.room); |
| 676 | + assert_eq!( |
| 677 | + content.mentions.user_ids, |
| 678 | + BTreeSet::from([ |
| 679 | + <&UserId>::try_from("@user:example.com").unwrap().to_owned(), |
| 680 | + <&UserId>::try_from("@user2:example.com").unwrap().to_owned(), |
| 681 | + ]) |
| 682 | + ); |
| 683 | +} |
0 commit comments