Implement custom event deserialization
This commit is contained in:
parent
cbe22a84eb
commit
3b78391fbc
@ -394,9 +394,9 @@ impl TryFromRaw for Event {
|
|||||||
Sticker(c) => conv(Sticker, Event::Sticker, c),
|
Sticker(c) => conv(Sticker, Event::Sticker, c),
|
||||||
Tag(c) => conv(Tag, Event::Tag, c),
|
Tag(c) => conv(Tag, Event::Tag, c),
|
||||||
Typing(c) => conv(Typing, Event::Typing, c),
|
Typing(c) => conv(Typing, Event::Typing, c),
|
||||||
Custom(c) => Ok(Event::Custom(c)),
|
Custom(c) => conv(Custom, Event::Custom, c),
|
||||||
CustomRoom(c) => Ok(Event::CustomRoom(c)),
|
CustomRoom(c) => conv(CustomRoom, Event::CustomRoom, c),
|
||||||
CustomState(c) => Ok(Event::CustomState(c)),
|
CustomState(c) => conv(CustomState, Event::CustomState, c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -439,8 +439,8 @@ impl TryFromRaw for RoomEvent {
|
|||||||
RoomTombstone(c) => conv(RoomTombstone, RoomEvent::RoomTombstone, c),
|
RoomTombstone(c) => conv(RoomTombstone, RoomEvent::RoomTombstone, c),
|
||||||
RoomTopic(c) => conv(RoomTopic, RoomEvent::RoomTopic, c),
|
RoomTopic(c) => conv(RoomTopic, RoomEvent::RoomTopic, c),
|
||||||
Sticker(c) => conv(Sticker, RoomEvent::Sticker, c),
|
Sticker(c) => conv(Sticker, RoomEvent::Sticker, c),
|
||||||
CustomRoom(c) => Ok(RoomEvent::CustomRoom(c)),
|
CustomRoom(c) => conv(CustomRoom, RoomEvent::CustomRoom, c),
|
||||||
CustomState(c) => Ok(RoomEvent::CustomState(c)),
|
CustomState(c) => conv(CustomState, RoomEvent::CustomState, c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -474,7 +474,7 @@ impl TryFromRaw for StateEvent {
|
|||||||
}
|
}
|
||||||
RoomTombstone(c) => conv(RoomTombstone, StateEvent::RoomTombstone, c),
|
RoomTombstone(c) => conv(RoomTombstone, StateEvent::RoomTombstone, c),
|
||||||
RoomTopic(c) => conv(RoomTopic, StateEvent::RoomTopic, c),
|
RoomTopic(c) => conv(RoomTopic, StateEvent::RoomTopic, c),
|
||||||
CustomState(c) => Ok(StateEvent::CustomState(c)),
|
CustomState(c) => conv(CustomState, StateEvent::CustomState, c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ impl TryFromRaw for Event {
|
|||||||
Receipt(c) => conv(Receipt, Event::Receipt, c),
|
Receipt(c) => conv(Receipt, Event::Receipt, c),
|
||||||
Tag(c) => conv(Tag, Event::Tag, c),
|
Tag(c) => conv(Tag, Event::Tag, c),
|
||||||
Typing(c) => conv(Typing, Event::Typing, c),
|
Typing(c) => conv(Typing, Event::Typing, c),
|
||||||
Custom(c) => Ok(Event::Custom(c)),
|
Custom(c) => conv(Custom, Event::Custom, c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ impl TryFromRaw for RoomEvent {
|
|||||||
RoomMessageFeedback(c) => conv(RoomMessageFeedback, RoomEvent::RoomMessageFeedback, c),
|
RoomMessageFeedback(c) => conv(RoomMessageFeedback, RoomEvent::RoomMessageFeedback, c),
|
||||||
RoomRedaction(c) => conv(RoomRedaction, RoomEvent::RoomRedaction, c),
|
RoomRedaction(c) => conv(RoomRedaction, RoomEvent::RoomRedaction, c),
|
||||||
Sticker(c) => conv(Sticker, RoomEvent::Sticker, c),
|
Sticker(c) => conv(Sticker, RoomEvent::Sticker, c),
|
||||||
CustomRoom(c) => Ok(RoomEvent::CustomRoom(c)),
|
CustomRoom(c) => conv(CustomRoom, RoomEvent::CustomRoom, c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,9 @@ use crate::{
|
|||||||
answer::raw::AnswerEvent, candidates::raw::CandidatesEvent, hangup::raw::HangupEvent,
|
answer::raw::AnswerEvent, candidates::raw::CandidatesEvent, hangup::raw::HangupEvent,
|
||||||
invite::raw::InviteEvent,
|
invite::raw::InviteEvent,
|
||||||
},
|
},
|
||||||
|
custom::raw::CustomEvent,
|
||||||
|
custom_room::raw::CustomRoomEvent,
|
||||||
|
custom_state::raw::CustomStateEvent,
|
||||||
direct::raw::DirectEvent,
|
direct::raw::DirectEvent,
|
||||||
dummy::raw::DummyEvent,
|
dummy::raw::DummyEvent,
|
||||||
forwarded_room_key::raw::ForwardedRoomKeyEvent,
|
forwarded_room_key::raw::ForwardedRoomKeyEvent,
|
||||||
@ -48,7 +51,7 @@ use crate::{
|
|||||||
tag::raw::TagEvent,
|
tag::raw::TagEvent,
|
||||||
typing::raw::TypingEvent,
|
typing::raw::TypingEvent,
|
||||||
util::get_field,
|
util::get_field,
|
||||||
CustomEvent, CustomRoomEvent, CustomStateEvent, EventType,
|
EventType,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A basic event, room event, or state event.
|
/// A basic event, room event, or state event.
|
||||||
@ -391,8 +394,18 @@ impl<'de> Deserialize<'de> for Event {
|
|||||||
Sticker => from_value(value, Event::Sticker),
|
Sticker => from_value(value, Event::Sticker),
|
||||||
Tag => from_value(value, Event::Tag),
|
Tag => from_value(value, Event::Tag),
|
||||||
Typing => from_value(value, Event::Typing),
|
Typing => from_value(value, Event::Typing),
|
||||||
// TODO
|
Custom(_event_type_name) => {
|
||||||
Custom(_event_type_name) => Err(D::Error::custom("invalid event type")),
|
if value.get("state_key").is_some() {
|
||||||
|
from_value(value, Event::CustomState)
|
||||||
|
} else if value.get("event_id").is_some()
|
||||||
|
&& value.get("room_id").is_some()
|
||||||
|
&& value.get("sender").is_some()
|
||||||
|
{
|
||||||
|
from_value(value, Event::CustomRoom)
|
||||||
|
} else {
|
||||||
|
from_value(value, Event::Custom)
|
||||||
|
}
|
||||||
|
}
|
||||||
__Nonexhaustive => {
|
__Nonexhaustive => {
|
||||||
unreachable!("__Nonexhaustive variant should be impossible to obtain.")
|
unreachable!("__Nonexhaustive variant should be impossible to obtain.")
|
||||||
}
|
}
|
||||||
@ -437,7 +450,13 @@ impl<'de> Deserialize<'de> for RoomEvent {
|
|||||||
RoomTombstone => from_value(value, RoomEvent::RoomTombstone),
|
RoomTombstone => from_value(value, RoomEvent::RoomTombstone),
|
||||||
RoomTopic => from_value(value, RoomEvent::RoomTopic),
|
RoomTopic => from_value(value, RoomEvent::RoomTopic),
|
||||||
Sticker => from_value(value, RoomEvent::Sticker),
|
Sticker => from_value(value, RoomEvent::Sticker),
|
||||||
//Custom(_event_type_name) => unimplemented!("todo"),
|
Custom(_event_type_name) => {
|
||||||
|
if value.get("state_key").is_some() {
|
||||||
|
from_value(value, RoomEvent::CustomState)
|
||||||
|
} else {
|
||||||
|
from_value(value, RoomEvent::CustomRoom)
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => Err(D::Error::custom("invalid event type")),
|
_ => Err(D::Error::custom("invalid event type")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -471,7 +490,7 @@ impl<'de> Deserialize<'de> for StateEvent {
|
|||||||
RoomThirdPartyInvite => from_value(value, StateEvent::RoomThirdPartyInvite),
|
RoomThirdPartyInvite => from_value(value, StateEvent::RoomThirdPartyInvite),
|
||||||
RoomTombstone => from_value(value, StateEvent::RoomTombstone),
|
RoomTombstone => from_value(value, StateEvent::RoomTombstone),
|
||||||
RoomTopic => from_value(value, StateEvent::RoomTopic),
|
RoomTopic => from_value(value, StateEvent::RoomTopic),
|
||||||
//Custom(_event_type_name) => unimplemented!("todo"),
|
Custom(_event_type_name) => from_value(value, StateEvent::CustomState),
|
||||||
_ => Err(D::Error::custom("invalid event type")),
|
_ => Err(D::Error::custom("invalid event type")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ use crate::{
|
|||||||
answer::raw::AnswerEvent, candidates::raw::CandidatesEvent, hangup::raw::HangupEvent,
|
answer::raw::AnswerEvent, candidates::raw::CandidatesEvent, hangup::raw::HangupEvent,
|
||||||
invite::raw::InviteEvent,
|
invite::raw::InviteEvent,
|
||||||
},
|
},
|
||||||
|
custom::raw::CustomEvent,
|
||||||
|
custom_room::raw::CustomRoomEvent,
|
||||||
direct::raw::DirectEvent,
|
direct::raw::DirectEvent,
|
||||||
dummy::raw::DummyEvent,
|
dummy::raw::DummyEvent,
|
||||||
forwarded_room_key::raw::ForwardedRoomKeyEvent,
|
forwarded_room_key::raw::ForwardedRoomKeyEvent,
|
||||||
@ -33,7 +35,7 @@ use crate::{
|
|||||||
tag::raw::TagEvent,
|
tag::raw::TagEvent,
|
||||||
typing::raw::TypingEvent,
|
typing::raw::TypingEvent,
|
||||||
util::get_field,
|
util::get_field,
|
||||||
CustomEvent, CustomRoomEvent, EventType,
|
EventType,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A basic event.
|
/// A basic event.
|
||||||
@ -173,7 +175,7 @@ impl<'de> Deserialize<'de> for Event {
|
|||||||
Receipt => from_value(value, Event::Receipt),
|
Receipt => from_value(value, Event::Receipt),
|
||||||
Tag => from_value(value, Event::Tag),
|
Tag => from_value(value, Event::Tag),
|
||||||
Typing => from_value(value, Event::Typing),
|
Typing => from_value(value, Event::Typing),
|
||||||
//Custom(_event_type_name) => unimplemented!("todo"),
|
Custom(_event_type_name) => from_value(value, Event::Custom),
|
||||||
_ => Err(D::Error::custom("invalid event type")),
|
_ => Err(D::Error::custom("invalid event type")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,7 +202,7 @@ impl<'de> Deserialize<'de> for RoomEvent {
|
|||||||
RoomMessageFeedback => from_value(value, RoomEvent::RoomMessageFeedback),
|
RoomMessageFeedback => from_value(value, RoomEvent::RoomMessageFeedback),
|
||||||
RoomRedaction => from_value(value, RoomEvent::RoomRedaction),
|
RoomRedaction => from_value(value, RoomEvent::RoomRedaction),
|
||||||
Sticker => from_value(value, RoomEvent::Sticker),
|
Sticker => from_value(value, RoomEvent::Sticker),
|
||||||
//Custom(_event_type_name) => unimplemented!("todo"),
|
Custom(_event_type_name) => from_value(value, RoomEvent::CustomRoom),
|
||||||
_ => Err(D::Error::custom("invalid event type")),
|
_ => Err(D::Error::custom("invalid event type")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user