1+ use std:: collections:: BTreeSet ;
2+
13use assert_matches2:: assert_matches;
24#[ cfg( feature = "unstable-msc2747" ) ]
35use assign:: assign;
46use js_int:: uint;
5- use ruma_common:: { room_id, serde:: CanBeEmpty , MilliSecondsSinceUnixEpoch , VoipVersionId } ;
7+ use ruma_common:: { room_id, serde:: CanBeEmpty , MilliSecondsSinceUnixEpoch , UserId , VoipVersionId } ;
68#[ cfg( feature = "unstable-msc2747" ) ]
79use ruma_events:: call:: CallCapabilities ;
810use ruma_events:: {
@@ -12,11 +14,12 @@ use ruma_events::{
1214 hangup:: { CallHangupEventContent , Reason } ,
1315 invite:: CallInviteEventContent ,
1416 negotiate:: CallNegotiateEventContent ,
17+ notify:: { ApplicationType , CallNotifyEventContent , NotifyType } ,
1518 reject:: CallRejectEventContent ,
1619 select_answer:: CallSelectAnswerEventContent ,
1720 SessionDescription ,
1821 } ,
19- AnyMessageLikeEvent , AnySyncMessageLikeEvent , MessageLikeEvent ,
22+ AnyMessageLikeEvent , AnySyncMessageLikeEvent , Mentions , MessageLikeEvent ,
2023} ;
2124use serde_json:: { from_value as from_json_value, json, to_value as to_json_value} ;
2225
@@ -598,3 +601,75 @@ fn select_v1_answer_event_deserialization() {
598601 assert_eq ! ( content. selected_party_id, "6336" ) ;
599602 assert_eq ! ( content. version, VoipVersionId :: V1 ) ;
600603}
604+
605+ #[ test]
606+ fn notify_event_serialization ( ) {
607+ let content_user_mention = CallNotifyEventContent :: new (
608+ "abcdef" . into ( ) ,
609+ ApplicationType :: Call ,
610+ NotifyType :: Ring ,
611+ Mentions :: with_user_ids ( vec ! [
612+ <& UserId >:: try_from( "@user:example.com" ) . unwrap( ) . into( ) ,
613+ <& UserId >:: try_from( "@user2:example.com" ) . unwrap( ) . into( ) ,
614+ ] ) ,
615+ ) ;
616+
617+ let content_room_mention = CallNotifyEventContent :: new (
618+ "abcdef" . into ( ) ,
619+ ApplicationType :: Call ,
620+ NotifyType :: Ring ,
621+ Mentions :: with_room_mention ( ) ,
622+ ) ;
623+
624+ assert_eq ! (
625+ to_json_value( & content_user_mention) . unwrap( ) ,
626+ json!( {
627+ "call_id" : "abcdef" ,
628+ "application" : "m.call" ,
629+ "m.mentions" : { "user_ids" : [ "@user2:example.com" , "@user:example.com" ] } ,
630+ "notify_type" : "ring" ,
631+ } )
632+ ) ;
633+ assert_eq ! (
634+ to_json_value( & content_room_mention) . unwrap( ) ,
635+ json!( {
636+ "call_id" : "abcdef" ,
637+ "application" : "m.call" ,
638+ "m.mentions" : { "room" : true } ,
639+ "notify_type" : "ring" ,
640+ } )
641+ ) ;
642+ }
643+
644+ #[ test]
645+ fn notify_event_deserialization ( ) {
646+ let json_data = json ! ( {
647+ "content" : {
648+ "call_id" : "abcdef" ,
649+ "application" : "m.call" ,
650+ "m.mentions" : { "room" : false , "user_ids" : [ "@user:example.com" , "@user2:example.com" ] } ,
651+ "notify_type" : "ring" ,
652+ } ,
653+ "event_id" : "$event:notareal.hs" ,
654+ "origin_server_ts" : 134_829_848 ,
655+ "room_id" : "!roomid:notareal.hs" ,
656+ "sender" : "@user:notareal.hs" ,
657+ "type" : "m.call.notify" ,
658+ } ) ;
659+
660+ let event = from_json_value :: < AnyMessageLikeEvent > ( json_data) . unwrap ( ) ;
661+ assert_matches ! (
662+ event,
663+ AnyMessageLikeEvent :: CallNotify ( MessageLikeEvent :: Original ( message_event) )
664+ ) ;
665+ let content = message_event. content ;
666+ assert_eq ! ( content. call_id, "abcdef" ) ;
667+ assert ! ( !content. mentions. room) ;
668+ assert_eq ! (
669+ content. mentions. user_ids,
670+ BTreeSet :: from( [
671+ <& UserId >:: try_from( "@user:example.com" ) . unwrap( ) . to_owned( ) ,
672+ <& UserId >:: try_from( "@user2:example.com" ) . unwrap( ) . to_owned( ) ,
673+ ] )
674+ ) ;
675+ }
0 commit comments