client-api: Fix deserialization of KnockedRoom
`knock_state` in `KnockedRoom` and `events` in `KnockState` are no longer required during deserialization and are no longer serialized if they are empty. This was a deviation from the spec, those fields were never required.
This commit is contained in:
parent
ec42dd491a
commit
c4f55b3990
@ -1,5 +1,19 @@
|
|||||||
# [unreleased]
|
# [unreleased]
|
||||||
|
|
||||||
|
# 0.20.0
|
||||||
|
|
||||||
|
Breaking changes:
|
||||||
|
|
||||||
|
- `ErrorKind` does not implement `AsRef<str>` and `Display` anymore. To get the
|
||||||
|
same result, use `ErrorKind::errcode()`. The `ErrorCode` that is returned
|
||||||
|
implements those traits.
|
||||||
|
|
||||||
|
Bug fixes:
|
||||||
|
|
||||||
|
- `knock_state` in `KnockedRoom` and `events` in `KnockState` are no longer
|
||||||
|
required during deserialization and are no longer serialized if they are empty.
|
||||||
|
This was a deviation from the spec, those fields were never required.
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
- Add unstable support for reporting rooms, according to MSC4151.
|
- Add unstable support for reporting rooms, according to MSC4151.
|
||||||
|
@ -316,22 +316,54 @@ impl JoinedRoom {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates to knocked rooms.
|
/// Updates to a room that the user has knocked upon.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct KnockedRoom {
|
pub struct KnockedRoom {
|
||||||
/// The knock state.
|
/// Updates to the stripped state of the room.
|
||||||
|
#[serde(default, skip_serializing_if = "KnockState::is_empty")]
|
||||||
pub knock_state: KnockState,
|
pub knock_state: KnockState,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A mapping from a key `events` to a list of `StrippedStateEvent`.
|
impl KnockedRoom {
|
||||||
|
/// Creates an empty `KnockedRoom`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether there are updates for this room.
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.knock_state.is_empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<KnockState> for KnockedRoom {
|
||||||
|
fn from(knock_state: KnockState) -> Self {
|
||||||
|
KnockedRoom { knock_state, ..Default::default() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stripped state updates of a room that the user has knocked upon.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct KnockState {
|
pub struct KnockState {
|
||||||
/// The list of events.
|
/// The stripped state of a room that the user has knocked upon.
|
||||||
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
pub events: Vec<Raw<AnyStrippedStateEvent>>,
|
pub events: Vec<Raw<AnyStrippedStateEvent>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl KnockState {
|
||||||
|
/// Creates an empty `KnockState`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether there are stripped state updates in this room.
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.events.is_empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Events in the room.
|
/// Events in the room.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user