events: Add CallNotify event as described by MSC4075
https://github.com/matrix-org/matrix-spec-proposals/pull/4075
This commit is contained in:
parent
877b1c63fe
commit
ef9f790928
@ -1,5 +1,8 @@
|
|||||||
# [unreleased]
|
# [unreleased]
|
||||||
|
|
||||||
|
- Add unstable support for `m.call.notify` events
|
||||||
|
(unstable type `org.matrix.msc4075.call.notify`)
|
||||||
|
|
||||||
# 0.27.10
|
# 0.27.10
|
||||||
|
|
||||||
Deprecations:
|
Deprecations:
|
||||||
|
@ -40,6 +40,7 @@ unstable-msc3927 = ["unstable-msc3551"]
|
|||||||
unstable-msc3954 = ["unstable-msc1767"]
|
unstable-msc3954 = ["unstable-msc1767"]
|
||||||
unstable-msc3955 = ["unstable-msc1767"]
|
unstable-msc3955 = ["unstable-msc1767"]
|
||||||
unstable-msc3956 = ["unstable-msc1767"]
|
unstable-msc3956 = ["unstable-msc1767"]
|
||||||
|
unstable-msc4075 = []
|
||||||
unstable-pdu = []
|
unstable-pdu = []
|
||||||
|
|
||||||
# Allow some mandatory fields to be missing, defaulting them to an empty string
|
# Allow some mandatory fields to be missing, defaulting them to an empty string
|
||||||
|
@ -9,6 +9,8 @@ pub mod invite;
|
|||||||
#[cfg(feature = "unstable-msc3401")]
|
#[cfg(feature = "unstable-msc3401")]
|
||||||
pub mod member;
|
pub mod member;
|
||||||
pub mod negotiate;
|
pub mod negotiate;
|
||||||
|
#[cfg(feature = "unstable-msc4075")]
|
||||||
|
pub mod notify;
|
||||||
pub mod reject;
|
pub mod reject;
|
||||||
pub mod select_answer;
|
pub mod select_answer;
|
||||||
|
|
||||||
|
77
crates/ruma-events/src/call/notify.rs
Normal file
77
crates/ruma-events/src/call/notify.rs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
//! Type for the matrixRTC notify event ([MSC4075]).
|
||||||
|
//!
|
||||||
|
//! [MSC4075]: https://github.com/matrix-org/matrix-spec-proposals/pull/4075
|
||||||
|
|
||||||
|
use ruma_macros::EventContent;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use super::member::Application;
|
||||||
|
use crate::Mentions;
|
||||||
|
|
||||||
|
/// The content of an `m.call.notify` event.
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
#[ruma_event(type = "m.call.notify", kind = MessageLike)]
|
||||||
|
pub struct CallNotifyEventContent {
|
||||||
|
/// A unique identifier for the call.
|
||||||
|
pub call_id: String,
|
||||||
|
|
||||||
|
/// The application this notify event applies to.
|
||||||
|
pub application: ApplicationType,
|
||||||
|
|
||||||
|
/// How this notify event should notify the receiver.
|
||||||
|
pub notify_type: NotifyType,
|
||||||
|
|
||||||
|
/// The users that are notified by this event (See [MSC3952] (Intentional Mentions)).
|
||||||
|
///
|
||||||
|
/// [MSC3952]: https://github.com/matrix-org/matrix-spec-proposals/pull/3952
|
||||||
|
#[serde(rename = "m.mentions")]
|
||||||
|
pub mentions: Mentions,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CallNotifyEventContent {
|
||||||
|
/// Creates a new `CallNotifyEventContent` with the given configuration.
|
||||||
|
pub fn new(
|
||||||
|
call_id: String,
|
||||||
|
application: ApplicationType,
|
||||||
|
notify_type: NotifyType,
|
||||||
|
mentions: Mentions,
|
||||||
|
) -> Self {
|
||||||
|
Self { call_id, application, notify_type, mentions }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// How this notify event should notify the receiver.
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
pub enum NotifyType {
|
||||||
|
/// The receiving client should ring with an audible sound.
|
||||||
|
#[serde(rename = "ring")]
|
||||||
|
Ring,
|
||||||
|
|
||||||
|
/// The receiving client should display a visual notification.
|
||||||
|
#[serde(rename = "notify")]
|
||||||
|
Notify,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The type of matrix RTC application.
|
||||||
|
///
|
||||||
|
/// This is different to [`Application`] because application contains all the information from the
|
||||||
|
/// `m.call.member` event.
|
||||||
|
///
|
||||||
|
/// An `Application` can be converted into an `ApplicationType` using `.into()`.
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
pub enum ApplicationType {
|
||||||
|
/// A VoIP call.
|
||||||
|
#[serde(rename = "m.call")]
|
||||||
|
Call,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Application> for ApplicationType {
|
||||||
|
fn from(val: Application) -> Self {
|
||||||
|
match val {
|
||||||
|
Application::Call(_) => ApplicationType::Call,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -93,6 +93,9 @@ event_enum! {
|
|||||||
#[cfg(feature = "unstable-msc3245")]
|
#[cfg(feature = "unstable-msc3245")]
|
||||||
#[ruma_enum(alias = "m.voice")]
|
#[ruma_enum(alias = "m.voice")]
|
||||||
"org.matrix.msc3245.voice.v2" => super::voice,
|
"org.matrix.msc3245.voice.v2" => super::voice,
|
||||||
|
#[cfg(feature = "unstable-msc4075")]
|
||||||
|
#[ruma_enum(alias = "m.call.notify")]
|
||||||
|
"org.matrix.msc4075.call.notify" => super::call::notify,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Any state event.
|
/// Any state event.
|
||||||
@ -352,6 +355,8 @@ impl AnyMessageLikeEventContent {
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "unstable-msc3381")]
|
#[cfg(feature = "unstable-msc3381")]
|
||||||
Self::PollStart(_) | Self::UnstablePollStart(_) => None,
|
Self::PollStart(_) | Self::UnstablePollStart(_) => None,
|
||||||
|
#[cfg(feature = "unstable-msc4075")]
|
||||||
|
Self::CallNotify(_) => None,
|
||||||
Self::CallNegotiate(_)
|
Self::CallNegotiate(_)
|
||||||
| Self::CallReject(_)
|
| Self::CallReject(_)
|
||||||
| Self::CallSelectAnswer(_)
|
| Self::CallSelectAnswer(_)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
#[cfg(feature = "unstable-msc4075")]
|
||||||
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
use assert_matches2::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
#[cfg(feature = "unstable-msc2747")]
|
#[cfg(feature = "unstable-msc2747")]
|
||||||
use assign::assign;
|
use assign::assign;
|
||||||
@ -5,6 +8,11 @@ use js_int::uint;
|
|||||||
use ruma_common::{room_id, serde::CanBeEmpty, MilliSecondsSinceUnixEpoch, VoipVersionId};
|
use ruma_common::{room_id, serde::CanBeEmpty, MilliSecondsSinceUnixEpoch, VoipVersionId};
|
||||||
#[cfg(feature = "unstable-msc2747")]
|
#[cfg(feature = "unstable-msc2747")]
|
||||||
use ruma_events::call::CallCapabilities;
|
use ruma_events::call::CallCapabilities;
|
||||||
|
#[cfg(feature = "unstable-msc4075")]
|
||||||
|
use ruma_events::{
|
||||||
|
call::notify::{ApplicationType, CallNotifyEventContent, NotifyType},
|
||||||
|
Mentions,
|
||||||
|
};
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
call::{
|
call::{
|
||||||
answer::CallAnswerEventContent,
|
answer::CallAnswerEventContent,
|
||||||
@ -598,3 +606,83 @@ fn select_v1_answer_event_deserialization() {
|
|||||||
assert_eq!(content.selected_party_id, "6336");
|
assert_eq!(content.selected_party_id, "6336");
|
||||||
assert_eq!(content.version, VoipVersionId::V1);
|
assert_eq!(content.version, VoipVersionId::V1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-msc4075")]
|
||||||
|
#[test]
|
||||||
|
fn notify_event_serialization() {
|
||||||
|
use ruma_common::owned_user_id;
|
||||||
|
|
||||||
|
let content_user_mention = CallNotifyEventContent::new(
|
||||||
|
"abcdef".into(),
|
||||||
|
ApplicationType::Call,
|
||||||
|
NotifyType::Ring,
|
||||||
|
Mentions::with_user_ids(vec![
|
||||||
|
owned_user_id!("@user:example.com"),
|
||||||
|
owned_user_id!("@user2:example.com"),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
let content_room_mention = CallNotifyEventContent::new(
|
||||||
|
"abcdef".into(),
|
||||||
|
ApplicationType::Call,
|
||||||
|
NotifyType::Ring,
|
||||||
|
Mentions::with_room_mention(),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
to_json_value(&content_user_mention).unwrap(),
|
||||||
|
json!({
|
||||||
|
"call_id": "abcdef",
|
||||||
|
"application": "m.call",
|
||||||
|
"m.mentions": {
|
||||||
|
"user_ids": ["@user2:example.com","@user:example.com"],
|
||||||
|
},
|
||||||
|
"notify_type": "ring",
|
||||||
|
})
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
to_json_value(&content_room_mention).unwrap(),
|
||||||
|
json!({
|
||||||
|
"call_id": "abcdef",
|
||||||
|
"application": "m.call",
|
||||||
|
"m.mentions": { "room": true },
|
||||||
|
"notify_type": "ring",
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-msc4075")]
|
||||||
|
#[test]
|
||||||
|
fn notify_event_deserialization() {
|
||||||
|
use ruma_common::owned_user_id;
|
||||||
|
|
||||||
|
let json_data = json!({
|
||||||
|
"content": {
|
||||||
|
"call_id": "abcdef",
|
||||||
|
"application": "m.call",
|
||||||
|
"m.mentions": {
|
||||||
|
"room": false,
|
||||||
|
"user_ids": ["@user:example.com", "@user2:example.com"],
|
||||||
|
},
|
||||||
|
"notify_type": "ring",
|
||||||
|
},
|
||||||
|
"event_id": "$event:notareal.hs",
|
||||||
|
"origin_server_ts": 134_829_848,
|
||||||
|
"room_id": "!roomid:notareal.hs",
|
||||||
|
"sender": "@user:notareal.hs",
|
||||||
|
"type": "m.call.notify",
|
||||||
|
});
|
||||||
|
|
||||||
|
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
||||||
|
assert_matches!(
|
||||||
|
event,
|
||||||
|
AnyMessageLikeEvent::CallNotify(MessageLikeEvent::Original(message_event))
|
||||||
|
);
|
||||||
|
let content = message_event.content;
|
||||||
|
assert_eq!(content.call_id, "abcdef");
|
||||||
|
assert!(!content.mentions.room);
|
||||||
|
assert_eq!(
|
||||||
|
content.mentions.user_ids,
|
||||||
|
BTreeSet::from([owned_user_id!("@user:example.com"), owned_user_id!("@user2:example.com")])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
# [unreleased]
|
# [unreleased]
|
||||||
|
|
||||||
|
Upgrade `ruma-events` and re-export its new `unstable-msc4075` feature.
|
||||||
|
|
||||||
# 0.9.3
|
# 0.9.3
|
||||||
|
|
||||||
Upgrade `ruma-client-api` and re-export its new `unstable-msc3983` feature.
|
Upgrade `ruma-client-api` and re-export its new `unstable-msc3983` feature.
|
||||||
|
@ -214,6 +214,7 @@ unstable-msc3955 = ["ruma-events?/unstable-msc3955"]
|
|||||||
unstable-msc3956 = ["ruma-events?/unstable-msc3956"]
|
unstable-msc3956 = ["ruma-events?/unstable-msc3956"]
|
||||||
unstable-msc3958 = ["ruma-common/unstable-msc3958"]
|
unstable-msc3958 = ["ruma-common/unstable-msc3958"]
|
||||||
unstable-msc3983 = ["ruma-client-api?/unstable-msc3983"]
|
unstable-msc3983 = ["ruma-client-api?/unstable-msc3983"]
|
||||||
|
unstable-msc4075 = ["ruma-events?/unstable-msc4075"]
|
||||||
unstable-pdu = ["ruma-events?/unstable-pdu"]
|
unstable-pdu = ["ruma-events?/unstable-pdu"]
|
||||||
unstable-unspecified = [
|
unstable-unspecified = [
|
||||||
"ruma-common/unstable-unspecified",
|
"ruma-common/unstable-unspecified",
|
||||||
@ -259,6 +260,7 @@ __ci = [
|
|||||||
"unstable-msc3956",
|
"unstable-msc3956",
|
||||||
"unstable-msc3958",
|
"unstable-msc3958",
|
||||||
"unstable-msc3983",
|
"unstable-msc3983",
|
||||||
|
"unstable-msc4075",
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user