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:
Kévin Commaille 2024-12-31 11:30:26 +01:00 committed by strawberry
parent ec42dd491a
commit c4f55b3990
2 changed files with 50 additions and 4 deletions

View File

@ -1,5 +1,19 @@
# [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:
- Add unstable support for reporting rooms, according to MSC4151.

View File

@ -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)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
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,
}
/// 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)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
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>>,
}
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.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]