Update custom module

This commit is contained in:
Jonas Platte 2020-06-07 17:50:47 +02:00
parent 283370ff2f
commit dd89b24aa4
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
2 changed files with 37 additions and 107 deletions

View File

@ -2,145 +2,75 @@
use std::time::SystemTime;
use crate::{EventType, UnsignedData};
use ruma_events_macros::FromRaw;
use ruma_identifiers::{EventId, RoomId, UserId};
use serde::Serialize;
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
use crate::{EventType, UnsignedData};
// TODO: (De)serialization
/// A custom event's type and `content` JSON object.
#[derive(Clone, Debug, Serialize)]
pub struct CustomEventContent {
/// The event type string.
#[serde(skip)]
pub event_type: String,
/// The actual `content` JSON object.
pub json: JsonValue,
}
/// A custom event not covered by the Matrix specification.
#[derive(Clone, Debug, FromRaw, Serialize)]
pub struct CustomEvent {
#[derive(Clone, Debug)]
pub struct CustomBasicEvent {
/// The event's content.
pub content: CustomEventContent,
/// The custom type of the event.
#[serde(rename = "type")]
pub event_type: String,
}
/// The payload for `CustomEvent`.
pub type CustomEventContent = JsonValue;
/// A custom room event not covered by the Matrix specification.
#[derive(Clone, Debug, FromRaw, Serialize)]
pub struct CustomRoomEvent {
/// A custom message event not covered by the Matrix specification.
#[derive(Clone, Debug)]
pub struct CustomMessageEvent {
/// The event's content.
pub content: CustomRoomEventContent,
/// The unique identifier for the event.
pub event_id: EventId,
/// The custom type of the event.
#[serde(rename = "type")]
pub event_type: String,
pub content: CustomEventContent,
/// Time on originating homeserver when this event was sent.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
pub origin_server_ts: SystemTime,
/// The unique identifier for the room associated with this event.
pub room_id: Option<RoomId>,
/// The unique identifier for the user who sent this event.
pub sender: UserId,
/// Additional key-value pairs not signed by the homeserver.
#[serde(skip_serializing_if = "UnsignedData::is_empty")]
pub unsigned: UnsignedData,
}
/// The payload for `CustomRoomEvent`.
pub type CustomRoomEventContent = JsonValue;
/// A custom state event not covered by the Matrix specification.
#[derive(Clone, Debug, FromRaw, Serialize)]
#[derive(Clone, Debug)]
pub struct CustomStateEvent {
/// The event's content.
pub content: CustomStateEventContent,
pub content: CustomEventContent,
/// The unique identifier for the event.
pub event_id: EventId,
/// The custom type of the event.
#[serde(rename = "type")]
pub event_type: String,
/// Time on originating homeserver when this event was sent.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
pub origin_server_ts: SystemTime,
/// The previous content for this state key, if any.
pub prev_content: Option<CustomStateEventContent>,
pub prev_content: Option<CustomEventContent>,
/// The unique identifier for the room associated with this event.
pub room_id: Option<RoomId>,
/// The unique identifier for the user who sent this event.
pub sender: UserId,
/// A key that determines which piece of room state the event represents.
pub state_key: String,
/// Additional key-value pairs not signed by the homeserver.
#[serde(skip_serializing_if = "UnsignedData::is_empty")]
pub unsigned: UnsignedData,
}
/// The payload for `CustomStateEvent`.
pub type CustomStateEventContent = JsonValue;
pub(crate) mod raw {
use std::time::SystemTime;
use ruma_identifiers::{EventId, RoomId, UserId};
use serde::Deserialize;
use super::{
CustomEventContent, CustomRoomEventContent, CustomStateEventContent, UnsignedData,
};
/// A custom event not covered by the Matrix specification.
#[derive(Clone, Debug, Deserialize)]
pub struct CustomEvent {
/// The event's content.
pub content: CustomEventContent,
/// The custom type of the event.
#[serde(rename = "type")]
pub event_type: String,
}
/// A custom room event not covered by the Matrix specification.
#[derive(Clone, Debug, Deserialize)]
pub struct CustomRoomEvent {
/// The event's content.
pub content: CustomRoomEventContent,
/// The unique identifier for the event.
pub event_id: EventId,
/// The custom type of the event.
#[serde(rename = "type")]
pub event_type: String,
/// Time on originating homeserver when this event was sent.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
pub origin_server_ts: SystemTime,
/// The unique identifier for the room associated with this event.
pub room_id: Option<RoomId>,
/// The unique identifier for the user who sent this event.
pub sender: UserId,
/// Additional key-value pairs not signed by the homeserver.
#[serde(default)]
pub unsigned: UnsignedData,
}
/// A custom state event not covered by the Matrix specification.
#[derive(Clone, Debug, Deserialize)]
pub struct CustomStateEvent {
/// The event's content.
pub content: CustomStateEventContent,
/// The unique identifier for the event.
pub event_id: EventId,
/// The custom type of the event.
#[serde(rename = "type")]
pub event_type: String,
/// Time on originating homeserver when this event was sent.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
pub origin_server_ts: SystemTime,
/// The previous content for this state key, if any.
pub prev_content: Option<CustomStateEventContent>,
/// The unique identifier for the room associated with this event.
pub room_id: Option<RoomId>,
/// The unique identifier for the user who sent this event.
pub sender: UserId,
/// A key that determines which piece of room state the event represents.
pub state_key: String,
/// Additional key-value pairs not signed by the homeserver.
#[serde(default)]
pub unsigned: UnsignedData,
}
}

View File

@ -144,7 +144,7 @@ pub mod util;
extern crate self as ruma_events;
pub mod call;
// pub mod custom;
pub mod custom;
// pub mod direct;
// pub mod dummy;
pub mod forwarded_room_key;