Replace all remaining manual implementations by derives
This commit is contained in:
parent
d9909a1f8b
commit
a9e1a2b0b0
@ -1,12 +1,13 @@
|
||||
//! Types for the *m.ignored_user_list* event.
|
||||
|
||||
use ruma_identifiers::UserId;
|
||||
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{util::vec_as_map_of_empty, Event as _, EventType, FromRaw};
|
||||
use crate::{util::vec_as_map_of_empty, EventType, FromRaw};
|
||||
|
||||
/// A list of users to ignore.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||
#[serde(rename = "m.ignored_user_list", tag = "type")]
|
||||
pub struct IgnoredUserListEvent {
|
||||
/// The event's content.
|
||||
pub content: IgnoredUserListEventContent,
|
||||
@ -22,20 +23,6 @@ impl FromRaw for IgnoredUserListEvent {
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for IgnoredUserListEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut state = serializer.serialize_struct("IgnoredUserListEvent", 2)?;
|
||||
|
||||
state.serialize_field("content", &self.content)?;
|
||||
state.serialize_field("type", &self.event_type())?;
|
||||
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload for `IgnoredUserListEvent`.
|
||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||
pub struct IgnoredUserListEventContent {
|
||||
|
@ -8,12 +8,13 @@ use super::{
|
||||
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString,
|
||||
VerificationMethod,
|
||||
};
|
||||
use crate::{Event, EventType, InvalidInput, TryFromRaw};
|
||||
use crate::{EventType, InvalidInput, TryFromRaw};
|
||||
|
||||
/// Begins an SAS key verification process.
|
||||
///
|
||||
/// Typically sent as a to-device event.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||
#[serde(rename = "m.key.verification.start", tag = "type")]
|
||||
pub struct StartEvent {
|
||||
/// The event's content.
|
||||
pub content: StartEventContent,
|
||||
@ -40,20 +41,6 @@ impl TryFromRaw for StartEvent {
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for StartEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut state = serializer.serialize_struct("StartEvent", 2)?;
|
||||
|
||||
state.serialize_field("content", &self.content)?;
|
||||
state.serialize_field("type", &self.event_type())?;
|
||||
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl_event!(
|
||||
StartEvent,
|
||||
StartEventContent,
|
||||
|
@ -3,16 +3,17 @@ use std::collections::HashMap;
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{DeviceId, EventId, RoomId, UserId};
|
||||
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde_json::{from_value, Map, Value};
|
||||
|
||||
use crate::{Algorithm, Event, EventType, FromRaw};
|
||||
use crate::{Algorithm, EventType, FromRaw};
|
||||
|
||||
/// This event type is used when sending encrypted events.
|
||||
///
|
||||
/// This type is to be used within a room. For a to-device event, use `EncryptedEventContent`
|
||||
/// directly.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||
#[serde(rename = "m.room.encrypted", tag = "type")]
|
||||
pub struct EncryptedEvent {
|
||||
/// The event's content.
|
||||
pub content: EncryptedEventContent,
|
||||
@ -25,12 +26,14 @@ pub struct EncryptedEvent {
|
||||
pub origin_server_ts: UInt,
|
||||
|
||||
/// The unique identifier for the room associated with this event.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
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 = "Map::is_empty")]
|
||||
pub unsigned: Map<String, Value>,
|
||||
}
|
||||
|
||||
@ -82,42 +85,6 @@ impl FromRaw for EncryptedEventContent {
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for EncryptedEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut len = 6;
|
||||
|
||||
if self.room_id.is_some() {
|
||||
len += 1;
|
||||
}
|
||||
|
||||
if !self.unsigned.is_empty() {
|
||||
len += 1;
|
||||
}
|
||||
|
||||
let mut state = serializer.serialize_struct("EncryptedEvent", len)?;
|
||||
|
||||
state.serialize_field("content", &self.content)?;
|
||||
state.serialize_field("event_id", &self.event_id)?;
|
||||
state.serialize_field("origin_server_ts", &self.origin_server_ts)?;
|
||||
|
||||
if self.room_id.is_some() {
|
||||
state.serialize_field("room_id", &self.room_id)?;
|
||||
}
|
||||
|
||||
state.serialize_field("sender", &self.sender)?;
|
||||
state.serialize_field("type", &self.event_type())?;
|
||||
|
||||
if !self.unsigned.is_empty() {
|
||||
state.serialize_field("unsigned", &self.unsigned)?;
|
||||
}
|
||||
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl_room_event!(
|
||||
EncryptedEvent,
|
||||
EncryptedEventContent,
|
||||
|
@ -6,12 +6,13 @@ use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializ
|
||||
use serde_json::{from_value, Map, Value};
|
||||
|
||||
use super::{EncryptedFile, ImageInfo, ThumbnailInfo};
|
||||
use crate::{Event, EventType, FromRaw};
|
||||
use crate::{EventType, FromRaw};
|
||||
|
||||
pub mod feedback;
|
||||
|
||||
/// A message sent to a room.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||
#[serde(rename = "m.room.message", tag = "type")]
|
||||
pub struct MessageEvent {
|
||||
/// The event's content.
|
||||
pub content: MessageEventContent,
|
||||
@ -24,12 +25,14 @@ pub struct MessageEvent {
|
||||
pub origin_server_ts: UInt,
|
||||
|
||||
/// The unique identifier for the room associated with this event.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
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 = "Map::is_empty")]
|
||||
pub unsigned: Map<String, Value>,
|
||||
}
|
||||
|
||||
@ -108,42 +111,6 @@ impl FromRaw for MessageEventContent {
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for MessageEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut len = 5;
|
||||
|
||||
if self.room_id.is_some() {
|
||||
len += 1;
|
||||
}
|
||||
|
||||
if !self.unsigned.is_empty() {
|
||||
len += 1;
|
||||
}
|
||||
|
||||
let mut state = serializer.serialize_struct("MessageEvent", len)?;
|
||||
|
||||
state.serialize_field("content", &self.content)?;
|
||||
state.serialize_field("event_id", &self.event_id)?;
|
||||
state.serialize_field("origin_server_ts", &self.origin_server_ts)?;
|
||||
|
||||
if self.room_id.is_some() {
|
||||
state.serialize_field("room_id", &self.room_id)?;
|
||||
}
|
||||
|
||||
state.serialize_field("sender", &self.sender)?;
|
||||
state.serialize_field("type", &self.event_type())?;
|
||||
|
||||
if !self.unsigned.is_empty() {
|
||||
state.serialize_field("unsigned", &self.unsigned)?;
|
||||
}
|
||||
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl_room_event!(MessageEvent, MessageEventContent, EventType::RoomMessage);
|
||||
|
||||
impl Serialize for MessageEventContent {
|
||||
|
@ -2,13 +2,14 @@
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use crate::{util::empty_string_as_none, Event as _, EventType, InvalidInput, TryFromRaw};
|
||||
use crate::{util::empty_string_as_none, EventType, InvalidInput, TryFromRaw};
|
||||
|
||||
/// A human-friendly room name designed to be displayed to the end-user.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||
#[serde(rename = "m.room.name", tag = "type")]
|
||||
pub struct NameEvent {
|
||||
/// The event's content.
|
||||
pub content: NameEventContent,
|
||||
@ -21,9 +22,11 @@ pub struct NameEvent {
|
||||
pub origin_server_ts: UInt,
|
||||
|
||||
/// The previous content for this state key, if any.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub prev_content: Option<NameEventContent>,
|
||||
|
||||
/// The unique identifier for the room associated with this event.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub room_id: Option<RoomId>,
|
||||
|
||||
/// The unique identifier for the user who sent this event.
|
||||
@ -33,6 +36,7 @@ pub struct NameEvent {
|
||||
pub state_key: String,
|
||||
|
||||
/// Additional key-value pairs not signed by the homeserver.
|
||||
#[serde(skip_serializing_if = "Map::is_empty")]
|
||||
pub unsigned: Map<String, Value>,
|
||||
}
|
||||
|
||||
@ -77,51 +81,6 @@ impl TryFromRaw for NameEventContent {
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for NameEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut len = 6;
|
||||
|
||||
if self.prev_content.is_some() {
|
||||
len += 1;
|
||||
}
|
||||
|
||||
if self.room_id.is_some() {
|
||||
len += 1;
|
||||
}
|
||||
|
||||
if !self.unsigned.is_empty() {
|
||||
len += 1;
|
||||
}
|
||||
|
||||
let mut state = serializer.serialize_struct("NameEvent", len)?;
|
||||
|
||||
state.serialize_field("content", &self.content)?;
|
||||
state.serialize_field("event_id", &self.event_id)?;
|
||||
state.serialize_field("origin_server_ts", &self.origin_server_ts)?;
|
||||
|
||||
if self.prev_content.is_some() {
|
||||
state.serialize_field("prev_content", &self.prev_content)?;
|
||||
}
|
||||
|
||||
if self.room_id.is_some() {
|
||||
state.serialize_field("room_id", &self.room_id)?;
|
||||
}
|
||||
|
||||
state.serialize_field("sender", &self.sender)?;
|
||||
state.serialize_field("state_key", &self.state_key)?;
|
||||
state.serialize_field("type", &self.event_type())?;
|
||||
|
||||
if !self.unsigned.is_empty() {
|
||||
state.serialize_field("unsigned", &self.unsigned)?;
|
||||
}
|
||||
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl_state_event!(NameEvent, NameEventContent, EventType::RoomName);
|
||||
|
||||
impl NameEventContent {
|
||||
|
@ -4,13 +4,14 @@ use std::collections::HashMap;
|
||||
|
||||
use js_int::{Int, UInt};
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use crate::{Event as _, EventType, FromRaw};
|
||||
use crate::{EventType, FromRaw};
|
||||
|
||||
/// Defines the power levels (privileges) of users in the room.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||
#[serde(rename = "m.room.power_levels", tag = "type")]
|
||||
pub struct PowerLevelsEvent {
|
||||
/// The event's content.
|
||||
pub content: PowerLevelsEventContent,
|
||||
@ -23,12 +24,15 @@ pub struct PowerLevelsEvent {
|
||||
pub origin_server_ts: UInt,
|
||||
|
||||
/// The previous content for this state key, if any.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub prev_content: Option<PowerLevelsEventContent>,
|
||||
|
||||
/// The unique identifier for the room associated with this event.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub room_id: Option<RoomId>,
|
||||
|
||||
/// Additional key-value pairs not signed by the homeserver.
|
||||
#[serde(skip_serializing_if = "Map::is_empty")]
|
||||
pub unsigned: Map<String, Value>,
|
||||
|
||||
/// The unique identifier for the user who sent this event.
|
||||
@ -124,51 +128,6 @@ impl FromRaw for PowerLevelsEventContent {
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for PowerLevelsEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut len = 6;
|
||||
|
||||
if self.prev_content.is_some() {
|
||||
len += 1;
|
||||
}
|
||||
|
||||
if self.room_id.is_some() {
|
||||
len += 1;
|
||||
}
|
||||
|
||||
if !self.unsigned.is_empty() {
|
||||
len += 1;
|
||||
}
|
||||
|
||||
let mut state = serializer.serialize_struct("PowerLevelsEvent", len)?;
|
||||
|
||||
state.serialize_field("content", &self.content)?;
|
||||
state.serialize_field("event_id", &self.event_id)?;
|
||||
state.serialize_field("origin_server_ts", &self.origin_server_ts)?;
|
||||
|
||||
if self.prev_content.is_some() {
|
||||
state.serialize_field("prev_content", &self.prev_content)?;
|
||||
}
|
||||
|
||||
if self.room_id.is_some() {
|
||||
state.serialize_field("room_id", &self.room_id)?;
|
||||
}
|
||||
|
||||
state.serialize_field("sender", &self.sender)?;
|
||||
state.serialize_field("state_key", &self.state_key)?;
|
||||
state.serialize_field("type", &self.event_type())?;
|
||||
|
||||
if !self.unsigned.is_empty() {
|
||||
state.serialize_field("unsigned", &self.unsigned)?;
|
||||
}
|
||||
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl_state_event!(
|
||||
PowerLevelsEvent,
|
||||
PowerLevelsEventContent,
|
||||
|
@ -2,13 +2,14 @@
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use crate::{util::default_true, Event as _, EventType, FromRaw};
|
||||
use crate::{util::default_true, EventType, FromRaw};
|
||||
|
||||
/// An event to indicate which servers are permitted to participate in the room.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||
#[serde(rename = "m.room.server_acl", tag = "type")]
|
||||
pub struct ServerAclEvent {
|
||||
/// The event's content.
|
||||
pub content: ServerAclEventContent,
|
||||
@ -21,9 +22,11 @@ pub struct ServerAclEvent {
|
||||
pub origin_server_ts: UInt,
|
||||
|
||||
/// The previous content for this state key, if any.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub prev_content: Option<ServerAclEventContent>,
|
||||
|
||||
/// The unique identifier for the room associated with this event.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub room_id: Option<RoomId>,
|
||||
|
||||
/// The unique identifier for the user who sent this event.
|
||||
@ -33,6 +36,7 @@ pub struct ServerAclEvent {
|
||||
pub state_key: String,
|
||||
|
||||
/// Additional key-value pairs not signed by the homeserver.
|
||||
#[serde(skip_serializing_if = "Map::is_empty")]
|
||||
pub unsigned: Map<String, Value>,
|
||||
}
|
||||
|
||||
@ -94,20 +98,6 @@ impl FromRaw for ServerAclEventContent {
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for ServerAclEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut state = serializer.serialize_struct("ServerAclEvent", 2)?;
|
||||
|
||||
state.serialize_field("content", &self.content)?;
|
||||
state.serialize_field("type", &self.event_type())?;
|
||||
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl_state_event!(
|
||||
ServerAclEvent,
|
||||
ServerAclEventContent,
|
||||
|
Loading…
x
Reference in New Issue
Block a user