Add m.sticker.
This commit is contained in:
parent
0fdf51598f
commit
9ad9776033
@ -27,6 +27,7 @@ use crate::{
|
|||||||
third_party_invite::ThirdPartyInviteEvent,
|
third_party_invite::ThirdPartyInviteEvent,
|
||||||
topic::TopicEvent,
|
topic::TopicEvent,
|
||||||
},
|
},
|
||||||
|
sticker::StickerEvent,
|
||||||
tag::TagEvent,
|
tag::TagEvent,
|
||||||
typing::TypingEvent,
|
typing::TypingEvent,
|
||||||
CustomEvent, CustomRoomEvent, CustomStateEvent, EventType,
|
CustomEvent, CustomRoomEvent, CustomStateEvent, EventType,
|
||||||
@ -89,6 +90,8 @@ pub enum Event {
|
|||||||
RoomThirdPartyInvite(ThirdPartyInviteEvent),
|
RoomThirdPartyInvite(ThirdPartyInviteEvent),
|
||||||
/// m.room.topic
|
/// m.room.topic
|
||||||
RoomTopic(TopicEvent),
|
RoomTopic(TopicEvent),
|
||||||
|
/// m.sticker
|
||||||
|
Sticker(StickerEvent),
|
||||||
/// m.tag
|
/// m.tag
|
||||||
Tag(TagEvent),
|
Tag(TagEvent),
|
||||||
/// m.typing
|
/// m.typing
|
||||||
@ -145,6 +148,8 @@ pub enum RoomEvent {
|
|||||||
RoomThirdPartyInvite(ThirdPartyInviteEvent),
|
RoomThirdPartyInvite(ThirdPartyInviteEvent),
|
||||||
/// m.room.topic
|
/// m.room.topic
|
||||||
RoomTopic(TopicEvent),
|
RoomTopic(TopicEvent),
|
||||||
|
/// m.sticker
|
||||||
|
Sticker(StickerEvent),
|
||||||
/// Any room event that is not part of the specification.
|
/// Any room event that is not part of the specification.
|
||||||
CustomRoom(CustomRoomEvent),
|
CustomRoom(CustomRoomEvent),
|
||||||
/// Any state event that is not part of the specification.
|
/// Any state event that is not part of the specification.
|
||||||
@ -216,6 +221,7 @@ impl Serialize for Event {
|
|||||||
Event::RoomRedaction(ref event) => event.serialize(serializer),
|
Event::RoomRedaction(ref event) => event.serialize(serializer),
|
||||||
Event::RoomThirdPartyInvite(ref event) => event.serialize(serializer),
|
Event::RoomThirdPartyInvite(ref event) => event.serialize(serializer),
|
||||||
Event::RoomTopic(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),
|
Event::Tag(ref event) => event.serialize(serializer),
|
||||||
Event::Typing(ref event) => event.serialize(serializer),
|
Event::Typing(ref event) => event.serialize(serializer),
|
||||||
Event::Custom(ref event) => event.serialize(serializer),
|
Event::Custom(ref event) => event.serialize(serializer),
|
||||||
@ -443,6 +449,14 @@ impl<'de> Deserialize<'de> for Event {
|
|||||||
|
|
||||||
Ok(Event::RoomTopic(event))
|
Ok(Event::RoomTopic(event))
|
||||||
}
|
}
|
||||||
|
EventType::Sticker => {
|
||||||
|
let event = match from_value::<StickerEvent>(value) {
|
||||||
|
Ok(event) => event,
|
||||||
|
Err(error) => return Err(D::Error::custom(error.to_string())),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Event::Sticker(event))
|
||||||
|
}
|
||||||
EventType::Tag => {
|
EventType::Tag => {
|
||||||
let event = match from_value::<TagEvent>(value) {
|
let event = match from_value::<TagEvent>(value) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
@ -516,6 +530,7 @@ impl Serialize for RoomEvent {
|
|||||||
RoomEvent::RoomRedaction(ref event) => event.serialize(serializer),
|
RoomEvent::RoomRedaction(ref event) => event.serialize(serializer),
|
||||||
RoomEvent::RoomThirdPartyInvite(ref event) => event.serialize(serializer),
|
RoomEvent::RoomThirdPartyInvite(ref event) => event.serialize(serializer),
|
||||||
RoomEvent::RoomTopic(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),
|
RoomEvent::CustomRoom(ref event) => event.serialize(serializer),
|
||||||
RoomEvent::CustomState(ref event) => event.serialize(serializer),
|
RoomEvent::CustomState(ref event) => event.serialize(serializer),
|
||||||
}
|
}
|
||||||
@ -700,6 +715,14 @@ impl<'de> Deserialize<'de> for RoomEvent {
|
|||||||
|
|
||||||
Ok(RoomEvent::RoomTopic(event))
|
Ok(RoomEvent::RoomTopic(event))
|
||||||
}
|
}
|
||||||
|
EventType::Sticker => {
|
||||||
|
let event = match from_value::<StickerEvent>(value) {
|
||||||
|
Ok(event) => event,
|
||||||
|
Err(error) => return Err(D::Error::custom(error.to_string())),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(RoomEvent::Sticker(event))
|
||||||
|
}
|
||||||
EventType::Custom(_) => {
|
EventType::Custom(_) => {
|
||||||
if value.get("state_key").is_some() {
|
if value.get("state_key").is_some() {
|
||||||
let event = match from_value::<CustomStateEvent>(value) {
|
let event = match from_value::<CustomStateEvent>(value) {
|
||||||
@ -894,6 +917,7 @@ impl<'de> Deserialize<'de> for StateEvent {
|
|||||||
| EventType::RoomMessage
|
| EventType::RoomMessage
|
||||||
| EventType::RoomMessageFeedback
|
| EventType::RoomMessageFeedback
|
||||||
| EventType::RoomRedaction
|
| EventType::RoomRedaction
|
||||||
|
| EventType::Sticker
|
||||||
| EventType::Tag
|
| EventType::Tag
|
||||||
| EventType::Typing => Err(D::Error::custom("not a state event".to_string())),
|
| EventType::Typing => Err(D::Error::custom("not a state event".to_string())),
|
||||||
}
|
}
|
||||||
@ -935,6 +959,7 @@ impl_from_t_for_event!(PowerLevelsEvent, RoomPowerLevels);
|
|||||||
impl_from_t_for_event!(RedactionEvent, RoomRedaction);
|
impl_from_t_for_event!(RedactionEvent, RoomRedaction);
|
||||||
impl_from_t_for_event!(ThirdPartyInviteEvent, RoomThirdPartyInvite);
|
impl_from_t_for_event!(ThirdPartyInviteEvent, RoomThirdPartyInvite);
|
||||||
impl_from_t_for_event!(TopicEvent, RoomTopic);
|
impl_from_t_for_event!(TopicEvent, RoomTopic);
|
||||||
|
impl_from_t_for_event!(StickerEvent, Sticker);
|
||||||
impl_from_t_for_event!(TagEvent, Tag);
|
impl_from_t_for_event!(TagEvent, Tag);
|
||||||
impl_from_t_for_event!(TypingEvent, Typing);
|
impl_from_t_for_event!(TypingEvent, Typing);
|
||||||
impl_from_t_for_event!(CustomEvent, Custom);
|
impl_from_t_for_event!(CustomEvent, Custom);
|
||||||
@ -969,6 +994,7 @@ impl_from_t_for_room_event!(NameEvent, RoomName);
|
|||||||
impl_from_t_for_room_event!(PinnedEventsEvent, RoomPinnedEvents);
|
impl_from_t_for_room_event!(PinnedEventsEvent, RoomPinnedEvents);
|
||||||
impl_from_t_for_room_event!(PowerLevelsEvent, RoomPowerLevels);
|
impl_from_t_for_room_event!(PowerLevelsEvent, RoomPowerLevels);
|
||||||
impl_from_t_for_room_event!(RedactionEvent, RoomRedaction);
|
impl_from_t_for_room_event!(RedactionEvent, RoomRedaction);
|
||||||
|
impl_from_t_for_room_event!(StickerEvent, Sticker);
|
||||||
impl_from_t_for_room_event!(ThirdPartyInviteEvent, RoomThirdPartyInvite);
|
impl_from_t_for_room_event!(ThirdPartyInviteEvent, RoomThirdPartyInvite);
|
||||||
impl_from_t_for_room_event!(TopicEvent, RoomTopic);
|
impl_from_t_for_room_event!(TopicEvent, RoomTopic);
|
||||||
impl_from_t_for_room_event!(CustomRoomEvent, CustomRoom);
|
impl_from_t_for_room_event!(CustomRoomEvent, CustomRoom);
|
||||||
|
@ -18,6 +18,7 @@ use crate::{
|
|||||||
message::{feedback::FeedbackEvent, MessageEvent},
|
message::{feedback::FeedbackEvent, MessageEvent},
|
||||||
redaction::RedactionEvent,
|
redaction::RedactionEvent,
|
||||||
},
|
},
|
||||||
|
sticker::StickerEvent,
|
||||||
tag::TagEvent,
|
tag::TagEvent,
|
||||||
typing::TypingEvent,
|
typing::TypingEvent,
|
||||||
CustomEvent, CustomRoomEvent, EventType,
|
CustomEvent, CustomRoomEvent, EventType,
|
||||||
@ -62,6 +63,8 @@ pub enum RoomEvent {
|
|||||||
RoomMessageFeedback(FeedbackEvent),
|
RoomMessageFeedback(FeedbackEvent),
|
||||||
/// m.room.redaction
|
/// m.room.redaction
|
||||||
RoomRedaction(RedactionEvent),
|
RoomRedaction(RedactionEvent),
|
||||||
|
/// m.sticker
|
||||||
|
Sticker(StickerEvent),
|
||||||
/// Any room event that is not part of the specification.
|
/// Any room event that is not part of the specification.
|
||||||
CustomRoom(CustomRoomEvent),
|
CustomRoom(CustomRoomEvent),
|
||||||
}
|
}
|
||||||
@ -185,7 +188,8 @@ impl<'de> Deserialize<'de> for Event {
|
|||||||
| EventType::RoomPowerLevels
|
| EventType::RoomPowerLevels
|
||||||
| EventType::RoomRedaction
|
| EventType::RoomRedaction
|
||||||
| EventType::RoomThirdPartyInvite
|
| EventType::RoomThirdPartyInvite
|
||||||
| EventType::RoomTopic => Err(D::Error::custom(
|
| EventType::RoomTopic
|
||||||
|
| EventType::Sticker => Err(D::Error::custom(
|
||||||
"not exclusively a basic event".to_string(),
|
"not exclusively a basic event".to_string(),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
@ -205,6 +209,7 @@ impl Serialize for RoomEvent {
|
|||||||
RoomEvent::RoomMessage(ref event) => event.serialize(serializer),
|
RoomEvent::RoomMessage(ref event) => event.serialize(serializer),
|
||||||
RoomEvent::RoomMessageFeedback(ref event) => event.serialize(serializer),
|
RoomEvent::RoomMessageFeedback(ref event) => event.serialize(serializer),
|
||||||
RoomEvent::RoomRedaction(ref event) => event.serialize(serializer),
|
RoomEvent::RoomRedaction(ref event) => event.serialize(serializer),
|
||||||
|
RoomEvent::Sticker(ref event) => event.serialize(serializer),
|
||||||
RoomEvent::CustomRoom(ref event) => event.serialize(serializer),
|
RoomEvent::CustomRoom(ref event) => event.serialize(serializer),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -284,6 +289,14 @@ impl<'de> Deserialize<'de> for RoomEvent {
|
|||||||
|
|
||||||
Ok(RoomEvent::RoomRedaction(event))
|
Ok(RoomEvent::RoomRedaction(event))
|
||||||
}
|
}
|
||||||
|
EventType::Sticker => {
|
||||||
|
let event = match from_value::<StickerEvent>(value) {
|
||||||
|
Ok(event) => event,
|
||||||
|
Err(error) => return Err(D::Error::custom(error.to_string())),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(RoomEvent::Sticker(event))
|
||||||
|
}
|
||||||
EventType::Custom(_) => {
|
EventType::Custom(_) => {
|
||||||
let event = match from_value::<CustomRoomEvent>(value) {
|
let event = match from_value::<CustomRoomEvent>(value) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
@ -353,4 +366,5 @@ impl_from_t_for_room_event!(InviteEvent, CallInvite);
|
|||||||
impl_from_t_for_room_event!(MessageEvent, RoomMessage);
|
impl_from_t_for_room_event!(MessageEvent, RoomMessage);
|
||||||
impl_from_t_for_room_event!(FeedbackEvent, RoomMessageFeedback);
|
impl_from_t_for_room_event!(FeedbackEvent, RoomMessageFeedback);
|
||||||
impl_from_t_for_room_event!(RedactionEvent, RoomRedaction);
|
impl_from_t_for_room_event!(RedactionEvent, RoomRedaction);
|
||||||
|
impl_from_t_for_room_event!(StickerEvent, Sticker);
|
||||||
impl_from_t_for_room_event!(CustomRoomEvent, CustomRoom);
|
impl_from_t_for_room_event!(CustomRoomEvent, CustomRoom);
|
||||||
|
@ -123,6 +123,7 @@ pub mod ignored_user_list;
|
|||||||
pub mod presence;
|
pub mod presence;
|
||||||
pub mod receipt;
|
pub mod receipt;
|
||||||
pub mod room;
|
pub mod room;
|
||||||
|
pub mod sticker;
|
||||||
pub mod stripped;
|
pub mod stripped;
|
||||||
pub mod tag;
|
pub mod tag;
|
||||||
pub mod typing;
|
pub mod typing;
|
||||||
@ -184,6 +185,8 @@ pub enum EventType {
|
|||||||
RoomThirdPartyInvite,
|
RoomThirdPartyInvite,
|
||||||
/// m.room.topic
|
/// m.room.topic
|
||||||
RoomTopic,
|
RoomTopic,
|
||||||
|
/// m.sticker
|
||||||
|
Sticker,
|
||||||
/// m.tag
|
/// m.tag
|
||||||
Tag,
|
Tag,
|
||||||
/// m.typing
|
/// m.typing
|
||||||
@ -281,6 +284,7 @@ impl Display for EventType {
|
|||||||
EventType::RoomRedaction => "m.room.redaction",
|
EventType::RoomRedaction => "m.room.redaction",
|
||||||
EventType::RoomThirdPartyInvite => "m.room.third_party_invite",
|
EventType::RoomThirdPartyInvite => "m.room.third_party_invite",
|
||||||
EventType::RoomTopic => "m.room.topic",
|
EventType::RoomTopic => "m.room.topic",
|
||||||
|
EventType::Sticker => "m.sticker",
|
||||||
EventType::Tag => "m.tag",
|
EventType::Tag => "m.tag",
|
||||||
EventType::Typing => "m.typing",
|
EventType::Typing => "m.typing",
|
||||||
EventType::Custom(ref event_type) => event_type,
|
EventType::Custom(ref event_type) => event_type,
|
||||||
@ -318,6 +322,7 @@ impl<'a> From<&'a str> for EventType {
|
|||||||
"m.room.redaction" => EventType::RoomRedaction,
|
"m.room.redaction" => EventType::RoomRedaction,
|
||||||
"m.room.third_party_invite" => EventType::RoomThirdPartyInvite,
|
"m.room.third_party_invite" => EventType::RoomThirdPartyInvite,
|
||||||
"m.room.topic" => EventType::RoomTopic,
|
"m.room.topic" => EventType::RoomTopic,
|
||||||
|
"m.sticker" => EventType::Sticker,
|
||||||
"m.tag" => EventType::Tag,
|
"m.tag" => EventType::Tag,
|
||||||
"m.typing" => EventType::Typing,
|
"m.typing" => EventType::Typing,
|
||||||
event_type => EventType::Custom(event_type.to_string()),
|
event_type => EventType::Custom(event_type.to_string()),
|
||||||
|
22
src/sticker.rs
Normal file
22
src/sticker.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
//! Types for the *m.sticker* event.
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::room::ImageInfo;
|
||||||
|
|
||||||
|
room_event! {
|
||||||
|
/// A sticker message.
|
||||||
|
pub struct StickerEvent(StickerEventContent) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The payload of a `StickerEvent`.
|
||||||
|
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
|
pub struct StickerEventContent {
|
||||||
|
/// A textual representation or associated description of the sticker image. This could be the
|
||||||
|
/// alt text of the original image, or a message to accompany and further describe the sticker.
|
||||||
|
pub body: String,
|
||||||
|
/// Metadata about the image referred to in `url` including a thumbnail representation.
|
||||||
|
pub info: ImageInfo,
|
||||||
|
/// The URL to the sticker image. This must be a valid `mxc://` URI.
|
||||||
|
pub url: String,
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user