Bring back direct, dummy, push_rules

This commit is contained in:
Jonas Platte 2020-06-09 01:54:58 +02:00
parent 63a2e5e4eb
commit 924ff5096b
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
5 changed files with 95 additions and 57 deletions

View File

@ -1,5 +1,17 @@
use ruma_events_macros::event_content_enum;
event_content_enum! {
/// A basic event.
name: AnyBasicEventContent,
events: [
"m.direct",
"m.dummy",
"m.ignored_user_list",
"m.push_rules",
"m.room_key",
]
}
event_content_enum! {
/// Any message event's content.
name: AnyMessageEventContent,
@ -40,9 +52,3 @@ event_content_enum! {
name: AnyEphemeralRoomEventContent,
events: [ "m.typing", "m.receipt" ]
}
event_content_enum! {
/// A basic event.
name: AnyBasicEventContent,
events: [ "m.ignored_user_list", "m.room_key" ]
}

View File

@ -1,22 +1,36 @@
//! Types for the *m.direct* event.
use std::collections::BTreeMap;
use std::{
collections::BTreeMap,
ops::{Deref, DerefMut},
};
use ruma_events_macros::ruma_event;
use ruma_events_macros::BasicEventContent;
use ruma_identifiers::{RoomId, UserId};
use serde::{Deserialize, Serialize};
ruma_event! {
/// Informs the client about the rooms that are considered direct by a user.
DirectEvent {
kind: Event,
event_type: "m.direct",
content_type_alias: {
/// The payload for `DirectEvent`.
///
/// A mapping of `UserId`s to a list of `RoomId`s which are considered *direct* for that
/// particular user.
BTreeMap<UserId, Vec<RoomId>>
},
/// Informs the client about the rooms that are considered direct by a user.
pub type DirectEvent = crate::BasicEvent<DirectEventContent>;
/// The payload for `DirectEvent`.
///
/// A mapping of `UserId`s to a list of `RoomId`s which are considered *direct* for that
/// particular user.
#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)]
#[ruma_event(type = "m.direct")]
pub struct DirectEventContent(pub BTreeMap<UserId, Vec<RoomId>>);
impl Deref for DirectEventContent {
type Target = BTreeMap<UserId, Vec<RoomId>>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for DirectEventContent {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
@ -32,7 +46,7 @@ mod tests {
#[test]
fn serialization() {
let mut content: DirectEventContent = BTreeMap::new();
let mut content = DirectEventContent(BTreeMap::new());
let alice = UserId::new("ruma.io").unwrap();
let room = vec![RoomId::new("ruma.io").unwrap()];

View File

@ -1,38 +1,55 @@
//! Types for the *m.dummy* event.
use ruma_events_macros::ruma_event;
use ruma_serde::empty::Empty;
use std::ops::{Deref, DerefMut};
ruma_event! {
/// This event type is used to indicate new Olm sessions for end-to-end encryption.
///
/// Typically it is encrypted as an *m.room.encrypted* event, then sent as a to-device event.
///
/// The event does not have any content associated with it. The sending client is expected to
/// send a key share request shortly after this message, causing the receiving client to process
/// this *m.dummy* event as the most recent event and using the keyshare request to set up the
/// session. The keyshare request and *m.dummy* combination should result in the original
/// sending client receiving keys over the newly established session.
DummyEvent {
kind: Event,
event_type: "m.dummy",
content_type_alias: {
/// The payload for `DummyEvent`.
Empty
use ruma_events_macros::BasicEventContent;
use ruma_serde::empty::Empty;
use serde::{Deserialize, Serialize};
use crate::BasicEvent;
/// This event type is used to indicate new Olm sessions for end-to-end encryption.
///
/// Typically it is encrypted as an *m.room.encrypted* event, then sent as a to-device event.
///
/// The event does not have any content associated with it. The sending client is expected to
/// send a key share request shortly after this message, causing the receiving client to process
/// this *m.dummy* event as the most recent event and using the keyshare request to set up the
/// session. The keyshare request and *m.dummy* combination should result in the original
/// sending client receiving keys over the newly established session.
pub type DummyEvent = BasicEvent<DummyEventContent>;
#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)]
#[ruma_event(type = "m.dummy")]
/// The payload for `DummyEvent`.
pub struct DummyEventContent(pub Empty);
impl Deref for DummyEventContent {
type Target = Empty;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for DummyEventContent {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
#[cfg(test)]
mod tests {
use super::{DummyEvent, Empty};
use super::{DummyEvent, DummyEventContent, Empty};
use crate::EventJson;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
#[test]
fn serialization() {
let dummy_event = DummyEvent { content: Empty };
let dummy_event = DummyEvent {
content: DummyEventContent(Empty),
};
let actual = to_json_value(dummy_event).unwrap();
let expected = json!({

View File

@ -145,14 +145,14 @@ extern crate self as ruma_events;
pub mod call;
pub mod custom;
// pub mod direct;
// pub mod dummy;
pub mod direct;
pub mod dummy;
pub mod forwarded_room_key;
pub mod fully_read;
pub mod ignored_user_list;
pub mod key;
pub mod presence;
// pub mod push_rules;
pub mod push_rules;
pub mod receipt;
pub mod room;
pub mod room_key;

View File

@ -1,18 +1,19 @@
//! Types for the the *m.push_rules* event.
use ruma_events_macros::ruma_event;
use ruma_events_macros::BasicEventContent;
use serde::{Deserialize, Serialize};
ruma_event! {
/// Describes all push rules for a user.
PushRulesEvent {
kind: Event,
event_type: "m.push_rules",
content: {
use crate::BasicEvent;
/// Describes all push rules for a user.
pub type PushRulesEvent = BasicEvent<PushRulesEventContent>;
/// The payload for `PushRulesEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)]
#[ruma_event(type = "m.push_rules")]
pub struct PushRulesEventContent {
/// The global ruleset.
pub global: Ruleset,
},
}
}
pub use ruma_common::push::Action;
@ -153,7 +154,7 @@ mod tests {
use matches::assert_matches;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
use super::PushCondition;
use super::{PushCondition, PushRulesEvent};
use crate::EventJson;
#[test]