mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-14 02:55:47 -04:00
feat(sdk): Implement SlidingSyncRoom::avatar_url.
Based on https://github.com/ruma/ruma/pull/1607, this patch adds support for `avatar` from a sliding sync response. This patch implements `SlidingSyncRoom::avatar_url` to get the avatar URL of a sliding sync room.
This commit is contained in:
81
Cargo.lock
generated
81
Cargo.lock
generated
@@ -2817,7 +2817,7 @@ dependencies = [
|
||||
"byteorder",
|
||||
"image 0.23.14",
|
||||
"qrcode",
|
||||
"ruma-common",
|
||||
"ruma-common 0.11.3 (git+https://github.com/ruma/ruma?rev=a641adb4287267ba9c4778ac1ee83b4ecab11e26)",
|
||||
"thiserror",
|
||||
"vodozemac",
|
||||
]
|
||||
@@ -4074,14 +4074,14 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma"
|
||||
version = "0.8.2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a641adb4287267ba9c4778ac1ee83b4ecab11e26#a641adb4287267ba9c4778ac1ee83b4ecab11e26"
|
||||
source = "git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096#201f0027d4e8be1716096c4a700eff211313c096"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"js_int",
|
||||
"js_option",
|
||||
"ruma-appservice-api",
|
||||
"ruma-client-api",
|
||||
"ruma-common",
|
||||
"ruma-common 0.11.3 (git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096)",
|
||||
"ruma-federation-api",
|
||||
"ruma-push-gateway-api",
|
||||
]
|
||||
@@ -4089,10 +4089,10 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-appservice-api"
|
||||
version = "0.8.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a641adb4287267ba9c4778ac1ee83b4ecab11e26#a641adb4287267ba9c4778ac1ee83b4ecab11e26"
|
||||
source = "git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096#201f0027d4e8be1716096c4a700eff211313c096"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-common",
|
||||
"ruma-common 0.11.3 (git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096)",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
@@ -4100,7 +4100,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-client-api"
|
||||
version = "0.16.2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a641adb4287267ba9c4778ac1ee83b4ecab11e26#a641adb4287267ba9c4778ac1ee83b4ecab11e26"
|
||||
source = "git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096#201f0027d4e8be1716096c4a700eff211313c096"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"bytes",
|
||||
@@ -4108,7 +4108,7 @@ dependencies = [
|
||||
"js_int",
|
||||
"js_option",
|
||||
"maplit",
|
||||
"ruma-common",
|
||||
"ruma-common 0.11.3 (git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096)",
|
||||
"serde",
|
||||
"serde_html_form",
|
||||
"serde_json",
|
||||
@@ -4117,7 +4117,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-common"
|
||||
version = "0.11.3"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a641adb4287267ba9c4778ac1ee83b4ecab11e26#a641adb4287267ba9c4778ac1ee83b4ecab11e26"
|
||||
source = "git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096#201f0027d4e8be1716096c4a700eff211313c096"
|
||||
dependencies = [
|
||||
"base64 0.21.2",
|
||||
"bytes",
|
||||
@@ -4135,8 +4135,8 @@ dependencies = [
|
||||
"pulldown-cmark",
|
||||
"rand 0.8.5",
|
||||
"regex",
|
||||
"ruma-identifiers-validation",
|
||||
"ruma-macros",
|
||||
"ruma-identifiers-validation 0.9.1 (git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096)",
|
||||
"ruma-macros 0.11.3 (git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096)",
|
||||
"serde",
|
||||
"serde_html_form",
|
||||
"serde_json",
|
||||
@@ -4148,16 +4148,50 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruma-federation-api"
|
||||
version = "0.7.1"
|
||||
name = "ruma-common"
|
||||
version = "0.11.3"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a641adb4287267ba9c4778ac1ee83b4ecab11e26#a641adb4287267ba9c4778ac1ee83b4ecab11e26"
|
||||
dependencies = [
|
||||
"base64 0.21.2",
|
||||
"bytes",
|
||||
"form_urlencoded",
|
||||
"indexmap 2.0.0",
|
||||
"js_int",
|
||||
"ruma-common",
|
||||
"js_option",
|
||||
"konst",
|
||||
"percent-encoding",
|
||||
"regex",
|
||||
"ruma-identifiers-validation 0.9.1 (git+https://github.com/ruma/ruma?rev=a641adb4287267ba9c4778ac1ee83b4ecab11e26)",
|
||||
"ruma-macros 0.11.3 (git+https://github.com/ruma/ruma?rev=a641adb4287267ba9c4778ac1ee83b4ecab11e26)",
|
||||
"serde",
|
||||
"serde_html_form",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"tracing",
|
||||
"url",
|
||||
"wildmatch",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruma-federation-api"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096#201f0027d4e8be1716096c4a700eff211313c096"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-common 0.11.3 (git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096)",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruma-identifiers-validation"
|
||||
version = "0.9.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096#201f0027d4e8be1716096c4a700eff211313c096"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruma-identifiers-validation"
|
||||
version = "0.9.1"
|
||||
@@ -4167,6 +4201,21 @@ dependencies = [
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruma-macros"
|
||||
version = "0.11.3"
|
||||
source = "git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096#201f0027d4e8be1716096c4a700eff211313c096"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"ruma-identifiers-validation 0.9.1 (git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096)",
|
||||
"serde",
|
||||
"syn 2.0.22",
|
||||
"toml 0.7.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruma-macros"
|
||||
version = "0.11.3"
|
||||
@@ -4176,7 +4225,7 @@ dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"ruma-identifiers-validation",
|
||||
"ruma-identifiers-validation 0.9.1 (git+https://github.com/ruma/ruma?rev=a641adb4287267ba9c4778ac1ee83b4ecab11e26)",
|
||||
"serde",
|
||||
"syn 2.0.22",
|
||||
"toml 0.7.5",
|
||||
@@ -4185,10 +4234,10 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-push-gateway-api"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=a641adb4287267ba9c4778ac1ee83b4ecab11e26#a641adb4287267ba9c4778ac1ee83b4ecab11e26"
|
||||
source = "git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096#201f0027d4e8be1716096c4a700eff211313c096"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-common",
|
||||
"ruma-common 0.11.3 (git+https://github.com/ruma/ruma?rev=201f0027d4e8be1716096c4a700eff211313c096)",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
@@ -34,7 +34,7 @@ futures-executor = "0.3.21"
|
||||
futures-util = { version = "0.3.26", default-features = false, features = ["alloc"] }
|
||||
http = "0.2.6"
|
||||
itertools = "0.11.0"
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "a641adb4287267ba9c4778ac1ee83b4ecab11e26", features = ["client-api-c", "compat-upload-signatures", "compat-user-id"] }
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "201f0027d4e8be1716096c4a700eff211313c096", features = ["client-api-c", "compat-upload-signatures", "compat-user-id"] }
|
||||
ruma-common = { git = "https://github.com/ruma/ruma", rev = "a641adb4287267ba9c4778ac1ee83b4ecab11e26" }
|
||||
once_cell = "1.16.0"
|
||||
serde = "1.0.151"
|
||||
|
||||
@@ -10,7 +10,7 @@ use ruma::{
|
||||
api::client::sync::sync_events::{v4, UnreadNotificationsCount},
|
||||
events::AnySyncStateEvent,
|
||||
serde::Raw,
|
||||
OwnedRoomId, RoomId,
|
||||
OwnedMxcUri, OwnedRoomId, RoomId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -74,6 +74,13 @@ 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()
|
||||
}
|
||||
|
||||
/// Is this a direct message?
|
||||
pub fn is_dm(&self) -> Option<bool> {
|
||||
let inner = self.inner.inner.read().unwrap();
|
||||
@@ -137,6 +144,7 @@ impl SlidingSyncRoom {
|
||||
) {
|
||||
let v4::SlidingSyncRoom {
|
||||
name,
|
||||
avatar,
|
||||
initial,
|
||||
limited,
|
||||
is_dm,
|
||||
@@ -159,6 +167,10 @@ impl SlidingSyncRoom {
|
||||
inner.name = name;
|
||||
}
|
||||
|
||||
if avatar.is_some() {
|
||||
inner.avatar = avatar;
|
||||
}
|
||||
|
||||
if initial.is_some() {
|
||||
inner.initial = initial;
|
||||
}
|
||||
@@ -307,7 +319,7 @@ mod tests {
|
||||
use matrix_sdk_base::deserialized_responses::TimelineEvent;
|
||||
use ruma::{
|
||||
api::client::sync::sync_events::v4, events::room::message::RoomMessageEventContent,
|
||||
room_id, uint, RoomId,
|
||||
mxc_uri, room_id, uint, RoomId,
|
||||
};
|
||||
use serde_json::json;
|
||||
use wiremock::MockServer;
|
||||
@@ -432,6 +444,14 @@ 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_room_is_dm {
|
||||
is_dm() = None;
|
||||
receives room_response!({"is_dm": true});
|
||||
|
||||
Reference in New Issue
Block a user