Add m.room.tombstone.

This commit is contained in:
Jimmy Cuadra 2019-06-13 01:34:05 -07:00
parent 9836222b73
commit 668e8b2239
5 changed files with 63 additions and 0 deletions

View File

@ -26,6 +26,7 @@ use crate::{
redaction::RedactionEvent,
server_acl::ServerAclEvent,
third_party_invite::ThirdPartyInviteEvent,
tombstone::TombstoneEvent,
topic::TopicEvent,
},
sticker::StickerEvent,
@ -91,6 +92,8 @@ pub enum Event {
RoomServerAcl(ServerAclEvent),
/// m.room.third_party_invite
RoomThirdPartyInvite(ThirdPartyInviteEvent),
/// m.room.tombstone
RoomTombstone(TombstoneEvent),
/// m.room.topic
RoomTopic(TopicEvent),
/// m.sticker
@ -151,6 +154,8 @@ pub enum RoomEvent {
RoomServerAcl(ServerAclEvent),
/// m.room.third_party_invite
RoomThirdPartyInvite(ThirdPartyInviteEvent),
/// m.room.tombstone
RoomTombstone(TombstoneEvent),
/// m.room.topic
RoomTopic(TopicEvent),
/// m.sticker
@ -191,6 +196,8 @@ pub enum StateEvent {
RoomServerAcl(ServerAclEvent),
/// m.room.third_party_invite
RoomThirdPartyInvite(ThirdPartyInviteEvent),
/// m.room.tombstone
RoomTombstone(TombstoneEvent),
/// m.room.topic
RoomTopic(TopicEvent),
/// Any state event that is not part of the specification.
@ -228,6 +235,7 @@ impl Serialize for Event {
Event::RoomRedaction(ref event) => event.serialize(serializer),
Event::RoomServerAcl(ref event) => event.serialize(serializer),
Event::RoomThirdPartyInvite(ref event) => event.serialize(serializer),
Event::RoomTombstone(ref event) => event.serialize(serializer),
Event::RoomTopic(ref event) => event.serialize(serializer),
Event::Sticker(ref event) => event.serialize(serializer),
Event::Tag(ref event) => event.serialize(serializer),
@ -457,6 +465,14 @@ impl<'de> Deserialize<'de> for Event {
Ok(Event::RoomThirdPartyInvite(event))
}
EventType::RoomTombstone => {
let event = match from_value::<TombstoneEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::RoomTombstone(event))
}
EventType::RoomTopic => {
let event = match from_value::<TopicEvent>(value) {
Ok(event) => event,
@ -546,6 +562,7 @@ impl Serialize for RoomEvent {
RoomEvent::RoomRedaction(ref event) => event.serialize(serializer),
RoomEvent::RoomServerAcl(ref event) => event.serialize(serializer),
RoomEvent::RoomThirdPartyInvite(ref event) => event.serialize(serializer),
RoomEvent::RoomTombstone(ref event) => event.serialize(serializer),
RoomEvent::RoomTopic(ref event) => event.serialize(serializer),
RoomEvent::Sticker(ref event) => event.serialize(serializer),
RoomEvent::CustomRoom(ref event) => event.serialize(serializer),
@ -732,6 +749,14 @@ impl<'de> Deserialize<'de> for RoomEvent {
Ok(RoomEvent::RoomThirdPartyInvite(event))
}
EventType::RoomTombstone => {
let event = match from_value::<TombstoneEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(RoomEvent::RoomTombstone(event))
}
EventType::RoomTopic => {
let event = match from_value::<TopicEvent>(value) {
Ok(event) => event,
@ -795,6 +820,7 @@ impl Serialize for StateEvent {
StateEvent::RoomPowerLevels(ref event) => event.serialize(serializer),
StateEvent::RoomServerAcl(ref event) => event.serialize(serializer),
StateEvent::RoomThirdPartyInvite(ref event) => event.serialize(serializer),
StateEvent::RoomTombstone(ref event) => event.serialize(serializer),
StateEvent::RoomTopic(ref event) => event.serialize(serializer),
StateEvent::CustomState(ref event) => event.serialize(serializer),
}
@ -923,6 +949,14 @@ impl<'de> Deserialize<'de> for StateEvent {
Ok(StateEvent::RoomThirdPartyInvite(event))
}
EventType::RoomTombstone => {
let event = match from_value::<TombstoneEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(StateEvent::RoomTombstone(event))
}
EventType::RoomTopic => {
let event = match from_value::<TopicEvent>(value) {
Ok(event) => event,
@ -993,6 +1027,7 @@ impl_from_t_for_event!(PowerLevelsEvent, RoomPowerLevels);
impl_from_t_for_event!(RedactionEvent, RoomRedaction);
impl_from_t_for_event!(ServerAclEvent, RoomServerAcl);
impl_from_t_for_event!(ThirdPartyInviteEvent, RoomThirdPartyInvite);
impl_from_t_for_event!(TombstoneEvent, RoomTombstone);
impl_from_t_for_event!(TopicEvent, RoomTopic);
impl_from_t_for_event!(StickerEvent, Sticker);
impl_from_t_for_event!(TagEvent, Tag);
@ -1032,6 +1067,7 @@ impl_from_t_for_room_event!(RedactionEvent, RoomRedaction);
impl_from_t_for_room_event!(ServerAclEvent, RoomServerAcl);
impl_from_t_for_room_event!(StickerEvent, Sticker);
impl_from_t_for_room_event!(ThirdPartyInviteEvent, RoomThirdPartyInvite);
impl_from_t_for_room_event!(TombstoneEvent, RoomTombstone);
impl_from_t_for_room_event!(TopicEvent, RoomTopic);
impl_from_t_for_room_event!(CustomRoomEvent, CustomRoom);
impl_from_t_for_room_event!(CustomStateEvent, CustomState);
@ -1059,5 +1095,6 @@ impl_from_t_for_state_event!(PinnedEventsEvent, RoomPinnedEvents);
impl_from_t_for_state_event!(PowerLevelsEvent, RoomPowerLevels);
impl_from_t_for_state_event!(ServerAclEvent, RoomServerAcl);
impl_from_t_for_state_event!(ThirdPartyInviteEvent, RoomThirdPartyInvite);
impl_from_t_for_state_event!(TombstoneEvent, RoomTombstone);
impl_from_t_for_state_event!(TopicEvent, RoomTopic);
impl_from_t_for_state_event!(CustomStateEvent, CustomState);

View File

@ -189,6 +189,7 @@ impl<'de> Deserialize<'de> for Event {
| EventType::RoomRedaction
| EventType::RoomServerAcl
| EventType::RoomThirdPartyInvite
| EventType::RoomTombstone
| EventType::RoomTopic
| EventType::Sticker => Err(D::Error::custom(
"not exclusively a basic event".to_string(),
@ -324,6 +325,7 @@ impl<'de> Deserialize<'de> for RoomEvent {
| EventType::RoomPowerLevels
| EventType::RoomServerAcl
| EventType::RoomThirdPartyInvite
| EventType::RoomTombstone
| EventType::RoomTopic
| EventType::Tag
| EventType::Typing => {

View File

@ -185,6 +185,8 @@ pub enum EventType {
RoomServerAcl,
/// m.room.third_party_invite
RoomThirdPartyInvite,
/// m.room.tombstone
RoomTombstone,
/// m.room.topic
RoomTopic,
/// m.sticker
@ -286,6 +288,7 @@ impl Display for EventType {
EventType::RoomRedaction => "m.room.redaction",
EventType::RoomServerAcl => "m.room.server_acl",
EventType::RoomThirdPartyInvite => "m.room.third_party_invite",
EventType::RoomTombstone => "m.room.tombstone",
EventType::RoomTopic => "m.room.topic",
EventType::Sticker => "m.sticker",
EventType::Tag => "m.tag",
@ -325,6 +328,7 @@ impl<'a> From<&'a str> for EventType {
"m.room.redaction" => EventType::RoomRedaction,
"m.room.server_acl" => EventType::RoomServerAcl,
"m.room.third_party_invite" => EventType::RoomThirdPartyInvite,
"m.room.tombstone" => EventType::RoomTombstone,
"m.room.topic" => EventType::RoomTopic,
"m.sticker" => EventType::Sticker,
"m.tag" => EventType::Tag,

View File

@ -21,6 +21,7 @@ pub mod power_levels;
pub mod redaction;
pub mod server_acl;
pub mod third_party_invite;
pub mod tombstone;
pub mod topic;
/// Metadata about an image.

19
src/room/tombstone.rs Normal file
View File

@ -0,0 +1,19 @@
//! Types for the *m.room.tombstone* event.
use ruma_identifiers::RoomId;
use serde::{Deserialize, Serialize};
state_event! {
/// A state event signifying that a room has been upgraded to a different room version, and that
/// clients should go there.
pub struct TombstoneEvent(TombstoneEventContent) {}
}
/// The payload of an *m.room.tombstone* event.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct TombstoneEventContent {
/// A server-defined message.
pub body: String,
/// The new room the client should be visiting.
pub replacement_room: RoomId,
}