Bring back direct, dummy, push_rules
This commit is contained in:
		
							parent
							
								
									63a2e5e4eb
								
							
						
					
					
						commit
						924ff5096b
					
				| @ -1,5 +1,17 @@ | |||||||
| use ruma_events_macros::event_content_enum; | 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! { | event_content_enum! { | ||||||
|     /// Any message event's content.
 |     /// Any message event's content.
 | ||||||
|     name: AnyMessageEventContent, |     name: AnyMessageEventContent, | ||||||
| @ -40,9 +52,3 @@ event_content_enum! { | |||||||
|     name: AnyEphemeralRoomEventContent, |     name: AnyEphemeralRoomEventContent, | ||||||
|     events: [ "m.typing", "m.receipt" ] |     events: [ "m.typing", "m.receipt" ] | ||||||
| } | } | ||||||
| 
 |  | ||||||
| event_content_enum! { |  | ||||||
|     /// A basic event.
 |  | ||||||
|     name: AnyBasicEventContent, |  | ||||||
|     events: [ "m.ignored_user_list", "m.room_key" ] |  | ||||||
| } |  | ||||||
|  | |||||||
| @ -1,22 +1,36 @@ | |||||||
| //! Types for the *m.direct* event.
 | //! 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 ruma_identifiers::{RoomId, UserId}; | ||||||
|  | use serde::{Deserialize, Serialize}; | ||||||
| 
 | 
 | ||||||
| ruma_event! { |  | ||||||
| /// Informs the client about the rooms that are considered direct by a user.
 | /// Informs the client about the rooms that are considered direct by a user.
 | ||||||
|     DirectEvent { | pub type DirectEvent = crate::BasicEvent<DirectEventContent>; | ||||||
|         kind: Event, | 
 | ||||||
|         event_type: "m.direct", |  | ||||||
|         content_type_alias: { |  | ||||||
| /// The payload for `DirectEvent`.
 | /// The payload for `DirectEvent`.
 | ||||||
| ///
 | ///
 | ||||||
| /// A mapping of `UserId`s to a list of `RoomId`s which are considered *direct* for that
 | /// A mapping of `UserId`s to a list of `RoomId`s which are considered *direct* for that
 | ||||||
| /// particular user.
 | /// particular user.
 | ||||||
|             BTreeMap<UserId, Vec<RoomId>> | #[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] |     #[test] | ||||||
|     fn serialization() { |     fn serialization() { | ||||||
|         let mut content: DirectEventContent = BTreeMap::new(); |         let mut content = DirectEventContent(BTreeMap::new()); | ||||||
|         let alice = UserId::new("ruma.io").unwrap(); |         let alice = UserId::new("ruma.io").unwrap(); | ||||||
|         let room = vec![RoomId::new("ruma.io").unwrap()]; |         let room = vec![RoomId::new("ruma.io").unwrap()]; | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										37
									
								
								src/dummy.rs
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								src/dummy.rs
									
									
									
									
									
								
							| @ -1,9 +1,13 @@ | |||||||
| //! Types for the *m.dummy* event.
 | //! Types for the *m.dummy* event.
 | ||||||
| 
 | 
 | ||||||
| use ruma_events_macros::ruma_event; | use std::ops::{Deref, DerefMut}; | ||||||
| use ruma_serde::empty::Empty; | 
 | ||||||
|  | use ruma_events_macros::BasicEventContent; | ||||||
|  | use ruma_serde::empty::Empty; | ||||||
|  | use serde::{Deserialize, Serialize}; | ||||||
|  | 
 | ||||||
|  | use crate::BasicEvent; | ||||||
| 
 | 
 | ||||||
| ruma_event! { |  | ||||||
| /// This event type is used to indicate new Olm sessions for end-to-end encryption.
 | /// 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.
 | /// Typically it is encrypted as an *m.room.encrypted* event, then sent as a to-device event.
 | ||||||
| @ -13,26 +17,39 @@ ruma_event! { | |||||||
| /// this *m.dummy* event as the most recent event and using the keyshare request to set up the
 | /// 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
 | /// session. The keyshare request and *m.dummy* combination should result in the original
 | ||||||
| /// sending client receiving keys over the newly established session.
 | /// sending client receiving keys over the newly established session.
 | ||||||
|     DummyEvent { | pub type DummyEvent = BasicEvent<DummyEventContent>; | ||||||
|         kind: Event, | 
 | ||||||
|         event_type: "m.dummy", | #[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] | ||||||
|         content_type_alias: { | #[ruma_event(type = "m.dummy")] | ||||||
| /// The payload for `DummyEvent`.
 | /// The payload for `DummyEvent`.
 | ||||||
|             Empty | 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)] | #[cfg(test)] | ||||||
| mod tests { | mod tests { | ||||||
|     use super::{DummyEvent, Empty}; |     use super::{DummyEvent, DummyEventContent, Empty}; | ||||||
|     use crate::EventJson; |     use crate::EventJson; | ||||||
| 
 | 
 | ||||||
|     use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; |     use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; | ||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn serialization() { |     fn serialization() { | ||||||
|         let dummy_event = DummyEvent { content: Empty }; |         let dummy_event = DummyEvent { | ||||||
|  |             content: DummyEventContent(Empty), | ||||||
|  |         }; | ||||||
|         let actual = to_json_value(dummy_event).unwrap(); |         let actual = to_json_value(dummy_event).unwrap(); | ||||||
| 
 | 
 | ||||||
|         let expected = json!({ |         let expected = json!({ | ||||||
|  | |||||||
| @ -145,14 +145,14 @@ extern crate self as ruma_events; | |||||||
| 
 | 
 | ||||||
| pub mod call; | pub mod call; | ||||||
| pub mod custom; | pub mod custom; | ||||||
| // pub mod direct;
 | pub mod direct; | ||||||
| // pub mod dummy;
 | pub mod dummy; | ||||||
| pub mod forwarded_room_key; | pub mod forwarded_room_key; | ||||||
| pub mod fully_read; | pub mod fully_read; | ||||||
| pub mod ignored_user_list; | pub mod ignored_user_list; | ||||||
| pub mod key; | pub mod key; | ||||||
| pub mod presence; | pub mod presence; | ||||||
| // pub mod push_rules;
 | pub mod push_rules; | ||||||
| pub mod receipt; | pub mod receipt; | ||||||
| pub mod room; | pub mod room; | ||||||
| pub mod room_key; | pub mod room_key; | ||||||
|  | |||||||
| @ -1,18 +1,19 @@ | |||||||
| //! Types for the the *m.push_rules* event.
 | //! Types for the the *m.push_rules* event.
 | ||||||
| 
 | 
 | ||||||
| use ruma_events_macros::ruma_event; | use ruma_events_macros::BasicEventContent; | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| 
 | 
 | ||||||
| ruma_event! { | use crate::BasicEvent; | ||||||
|  | 
 | ||||||
| /// Describes all push rules for a user.
 | /// Describes all push rules for a user.
 | ||||||
|     PushRulesEvent { | pub type PushRulesEvent = BasicEvent<PushRulesEventContent>; | ||||||
|         kind: Event, | 
 | ||||||
|         event_type: "m.push_rules", | /// The payload for `PushRulesEvent`.
 | ||||||
|         content: { | #[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] | ||||||
|  | #[ruma_event(type = "m.push_rules")] | ||||||
|  | pub struct PushRulesEventContent { | ||||||
|     /// The global ruleset.
 |     /// The global ruleset.
 | ||||||
|     pub global: Ruleset, |     pub global: Ruleset, | ||||||
|         }, |  | ||||||
|     } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub use ruma_common::push::Action; | pub use ruma_common::push::Action; | ||||||
| @ -153,7 +154,7 @@ mod tests { | |||||||
|     use matches::assert_matches; |     use matches::assert_matches; | ||||||
|     use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; |     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; |     use crate::EventJson; | ||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user