sliding sync: fix unsetting the avatar in a sliding sync room

The meaning of "null" and "undefined" were conflated by Ruma, previously. This updates to the latest Ruma, which changed the `avatar` type from
`Option` to `JsOption` and thus allowed us to distinguish both cases: `null` means the avatar has been unset, `undefined` means it's not changed
since the previous request.
This commit is contained in:
Benjamin Bouvier
2023-11-21 12:41:25 +01:00
parent 692be61043
commit 844340e0f7
2 changed files with 9 additions and 6 deletions

4
Cargo.lock generated
View File

@@ -4676,9 +4676,9 @@ dependencies = [
[[package]]
name = "ruma-client-api"
version = "0.17.3"
version = "0.17.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2428ee1488551cbc2bc4ef936c9452ac35ccd5c7e4e4df12c54b67afa6b262fb"
checksum = "641837258fa214a70823477514954ef0f5d3bc6ae8e1d5d85081856a33103386"
dependencies = [
"assign",
"bytes",

View File

@@ -78,7 +78,7 @@ impl SlidingSyncRoom {
pub fn avatar_url(&self) -> Option<OwnedMxcUri> {
let inner = self.inner.inner.read().unwrap();
inner.avatar.clone()
inner.avatar.clone().into_option()
}
/// Is this a direct message?
@@ -167,7 +167,10 @@ impl SlidingSyncRoom {
inner.name = name;
}
if avatar.is_some() {
// Note: in the server specification, the avatar is undefined when it hasn't
// changed, and it's set to null when it's been unset, so we
// distinguish the two here.
if !avatar.is_undefined() {
inner.avatar = avatar;
}
@@ -321,7 +324,7 @@ mod tests {
use matrix_sdk_test::async_test;
use ruma::{
api::client::sync::sync_events::v4, assign, events::room::message::RoomMessageEventContent,
mxc_uri, room_id, serde::Raw, uint, RoomId,
mxc_uri, room_id, serde::Raw, uint, JsOption, RoomId,
};
use serde_json::json;
use wiremock::MockServer;
@@ -906,7 +909,7 @@ mod tests {
v4::SlidingSyncRoom::default(),
{
name: Some("foobar".to_owned()),
avatar: Some(mxc_uri!("mxc://homeserver/media").to_owned()),
avatar: JsOption::Some(mxc_uri!("mxc://homeserver/media").to_owned()),
}
),
timeline_queue: vector![TimelineEvent::new(