feat(sdk): Remove the `avatar_url` logic in `SlidingSyncRoom`.
With the previous commit, the avatar is properly synchronized with the `Room`. The result is that `SlidingSyncRoom` no longer needs to hold the `avatar_url`.
This commit is contained in:
parent
e00532f5d2
commit
90f1a34855
|
@ -10,7 +10,7 @@ use ruma::{
|
|||
api::client::sync::sync_events::{v4, UnreadNotificationsCount},
|
||||
events::AnySyncStateEvent,
|
||||
serde::Raw,
|
||||
OwnedMxcUri, OwnedRoomId, RoomId,
|
||||
OwnedRoomId, RoomId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -74,13 +74,6 @@ impl SlidingSyncRoom {
|
|||
inner.name.to_owned()
|
||||
}
|
||||
|
||||
/// Get the room avatar URL.
|
||||
pub fn avatar_url(&self) -> Option<OwnedMxcUri> {
|
||||
let inner = self.inner.inner.read().unwrap();
|
||||
|
||||
inner.avatar.clone().into_option()
|
||||
}
|
||||
|
||||
/// Is this a direct message?
|
||||
pub fn is_dm(&self) -> Option<bool> {
|
||||
let inner = self.inner.inner.read().unwrap();
|
||||
|
@ -459,22 +452,6 @@ mod tests {
|
|||
_ = Some("gordon".to_owned());
|
||||
}
|
||||
|
||||
test_avatar {
|
||||
avatar_url() = None;
|
||||
receives room_response!({"avatar": "mxc://homeserver/media"});
|
||||
_ = Some(mxc_uri!("mxc://homeserver/media").to_owned());
|
||||
receives nothing;
|
||||
_ = Some(mxc_uri!("mxc://homeserver/media").to_owned());
|
||||
}
|
||||
|
||||
test_avatar_unset {
|
||||
avatar_url() = None;
|
||||
receives room_response!({ "avatar": null });
|
||||
_ = None;
|
||||
receives nothing;
|
||||
_ = None;
|
||||
}
|
||||
|
||||
test_room_is_dm {
|
||||
is_dm() = None;
|
||||
receives room_response!({"is_dm": true});
|
||||
|
@ -1059,21 +1036,4 @@ mod tests {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_avatar_set_then_unset() {
|
||||
let mut room = new_room(room_id!("!foo:bar.org"), room_response!({})).await;
|
||||
assert_eq!(room.avatar_url(), None);
|
||||
|
||||
room.update(room_response!({ "avatar": "mxc://homeserver/media" }), vec![]);
|
||||
assert_eq!(room.avatar_url().as_deref(), Some(mxc_uri!("mxc://homeserver/media")));
|
||||
|
||||
// avatar is undefined.
|
||||
room.update(room_response!({}), vec![]);
|
||||
assert_eq!(room.avatar_url().as_deref(), Some(mxc_uri!("mxc://homeserver/media")));
|
||||
|
||||
// avatar is null => reset it to None.
|
||||
room.update(room_response!({ "avatar": null }), vec![]);
|
||||
assert_eq!(room.avatar_url().as_deref(), None);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,17 +168,11 @@ async fn test_room_avatar_group_conversation() -> Result<()> {
|
|||
let alice_room = alice.get_room(alice_room.room_id()).unwrap();
|
||||
assert_eq!(alice_room.state(), RoomState::Joined);
|
||||
|
||||
let sliding_room = sliding_alice
|
||||
.get_room(alice_room.room_id())
|
||||
.await
|
||||
.expect("sliding sync finds alice's own room");
|
||||
|
||||
// Here, there should be no avatar (group conversation and no avatar has been
|
||||
// set in the room).
|
||||
for _ in 0..3 {
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
assert_eq!(alice_room.avatar_url(), None);
|
||||
assert_eq!(sliding_room.avatar_url(), None);
|
||||
|
||||
// Force a new server response.
|
||||
alice_room.send(RoomMessageEventContent::text_plain("hello world")).await?;
|
||||
|
@ -191,7 +185,6 @@ async fn test_room_avatar_group_conversation() -> Result<()> {
|
|||
for _ in 0..3 {
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
assert_eq!(alice_room.avatar_url().as_deref(), Some(group_avatar_uri));
|
||||
assert_eq!(sliding_room.avatar_url().as_deref(), Some(group_avatar_uri));
|
||||
|
||||
// Force a new server response.
|
||||
alice_room.send(RoomMessageEventContent::text_plain("hello world")).await?;
|
||||
|
@ -203,7 +196,6 @@ async fn test_room_avatar_group_conversation() -> Result<()> {
|
|||
for _ in 0..3 {
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
assert_eq!(alice_room.avatar_url(), None);
|
||||
assert_eq!(sliding_room.avatar_url(), None);
|
||||
|
||||
// Force a new server response.
|
||||
alice_room.send(RoomMessageEventContent::text_plain("hello world")).await?;
|
||||
|
|
Loading…
Reference in New Issue