chore: Upgrade Ruma

This commit is contained in:
Jonas Platte
2022-11-10 13:23:10 +01:00
committed by Jonas Platte
parent 680ef6b93a
commit 4dc0e0ef3c
23 changed files with 174 additions and 152 deletions
Generated
+48 -30
View File
@@ -388,9 +388,9 @@ dependencies = [
[[package]]
name = "base64"
version = "0.13.0"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]]
name = "base64ct"
@@ -2349,6 +2349,28 @@ dependencies = [
"serde",
]
[[package]]
name = "konst"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "330f0e13e6483b8c34885f7e6c9f19b1a7bd449c673fbb948a51c99d66ef74f4"
dependencies = [
"konst_macro_rules",
"konst_proc_macros",
]
[[package]]
name = "konst_macro_rules"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4933f3f57a8e9d9da04db23fb153356ecaf00cbd14aee46279c33dc80925c37"
[[package]]
name = "konst_proc_macros"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "984e109462d46ad18314f10e392c286c3d47bce203088a09012de1015b45b737"
[[package]]
name = "lazy-regex"
version = "2.3.0"
@@ -3889,8 +3911,7 @@ dependencies = [
[[package]]
name = "ruma"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dc348e3a4a18abc4e97fffa5e2e623f6edd50ba3a1dd5f47eb249fea713b69f"
source = "git+https://github.com/ruma/ruma?rev=ed100afddb5fb30f1ccf368d7e712a3a483e63bf#ed100afddb5fb30f1ccf368d7e712a3a483e63bf"
dependencies = [
"assign",
"js_int",
@@ -3904,9 +3925,9 @@ dependencies = [
[[package]]
name = "ruma-appservice-api"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4f8cecdd4e2729656fc4126b6b5b218834d4025e0ed0e5063087a0231098a5c"
source = "git+https://github.com/ruma/ruma?rev=ed100afddb5fb30f1ccf368d7e712a3a483e63bf#ed100afddb5fb30f1ccf368d7e712a3a483e63bf"
dependencies = [
"js_int",
"ruma-common",
"serde",
"serde_json",
@@ -3915,13 +3936,13 @@ dependencies = [
[[package]]
name = "ruma-client-api"
version = "0.15.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1e72bc731b4dc8b569aa83915f13e419144b67110d858c65bb74aa05e2dc4b7"
source = "git+https://github.com/ruma/ruma?rev=ed100afddb5fb30f1ccf368d7e712a3a483e63bf#ed100afddb5fb30f1ccf368d7e712a3a483e63bf"
dependencies = [
"assign",
"bytes",
"http",
"js_int",
"js_option",
"maplit",
"percent-encoding",
"ruma-common",
@@ -3932,8 +3953,7 @@ dependencies = [
[[package]]
name = "ruma-common"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "716889595f4edc3cfeb94d9f122e413f73e37d7d80ea1c14196e1004241a3889"
source = "git+https://github.com/ruma/ruma?rev=ed100afddb5fb30f1ccf368d7e712a3a483e63bf#ed100afddb5fb30f1ccf368d7e712a3a483e63bf"
dependencies = [
"base64",
"bytes",
@@ -3945,6 +3965,7 @@ dependencies = [
"js-sys",
"js_int",
"js_option",
"konst",
"percent-encoding",
"pulldown-cmark",
"rand 0.8.5",
@@ -3963,8 +3984,7 @@ dependencies = [
[[package]]
name = "ruma-federation-api"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f905d12f6144c7a754bd0339fa6893698c03d03a908abb20cc6eeb4ec7f9466"
source = "git+https://github.com/ruma/ruma?rev=ed100afddb5fb30f1ccf368d7e712a3a483e63bf#ed100afddb5fb30f1ccf368d7e712a3a483e63bf"
dependencies = [
"js_int",
"ruma-common",
@@ -3975,8 +3995,7 @@ dependencies = [
[[package]]
name = "ruma-identifiers-validation"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eabac62d16465a87435579c779d74dceabb93b09e44c766af6085050f3cc4275"
source = "git+https://github.com/ruma/ruma?rev=ed100afddb5fb30f1ccf368d7e712a3a483e63bf#ed100afddb5fb30f1ccf368d7e712a3a483e63bf"
dependencies = [
"js_int",
"thiserror",
@@ -3985,8 +4004,7 @@ dependencies = [
[[package]]
name = "ruma-macros"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f82e91eb61cd86d9287303133ee55b54618eccb75a522cc22a42c15f5bda340"
source = "git+https://github.com/ruma/ruma?rev=ed100afddb5fb30f1ccf368d7e712a3a483e63bf#ed100afddb5fb30f1ccf368d7e712a3a483e63bf"
dependencies = [
"once_cell",
"proc-macro-crate",
@@ -4189,9 +4207,9 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.144"
version = "1.0.147"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860"
checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965"
dependencies = [
"serde_derive",
]
@@ -4207,9 +4225,9 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.144"
version = "1.0.147"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00"
checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852"
dependencies = [
"proc-macro2",
"quote",
@@ -4218,9 +4236,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.85"
version = "1.0.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44"
checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45"
dependencies = [
"itoa 1.0.3",
"ryu",
@@ -4600,18 +4618,18 @@ checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16"
[[package]]
name = "thiserror"
version = "1.0.33"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d0a539a918745651435ac7db7a18761589a94cd7e94cd56999f828bf73c8a57"
checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.33"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c251e90f708e16c49a16f4917dc2131e75222b72edfa9cb7f7c58ae56aae0c09"
checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
dependencies = [
"proc-macro2",
"quote",
@@ -4852,9 +4870,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
[[package]]
name = "tracing"
version = "0.1.36"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307"
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
dependencies = [
"cfg-if",
"log",
@@ -4865,9 +4883,9 @@ dependencies = [
[[package]]
name = "tracing-attributes"
version = "0.1.22"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2"
checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
dependencies = [
"proc-macro2",
"quote",
+2 -1
View File
@@ -16,7 +16,8 @@ default-members = ["benchmarks", "crates/*"]
resolver = "2"
[workspace.dependencies]
ruma = { version = "0.7.4", features = ["client-api-c"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "ed100afddb5fb30f1ccf368d7e712a3a483e63bf", features = ["client-api-c"] }
ruma-common = { git = "https://github.com/ruma/ruma", rev = "ed100afddb5fb30f1ccf368d7e712a3a483e63bf" }
tracing = { version = "0.1.36", default-features = false, features = ["std"] }
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "779e955f21a70e4aba43a7408f1841dcdf728b32" }
uniffi_macros = { git = "https://github.com/mozilla/uniffi-rs", rev = "779e955f21a70e4aba43a7408f1841dcdf728b32" }
@@ -25,7 +25,7 @@ use ruma::{
upload_signatures::v3::Response as SignatureUploadResponse,
},
message::send_message_event::v3::Response as RoomMessageResponse,
sync::sync_events::v3::{DeviceLists as RumaDeviceLists, ToDevice},
sync::sync_events::{v3::ToDevice, DeviceLists as RumaDeviceLists},
to_device::send_event_to_device::v3::Response as ToDeviceResponse,
},
IncomingResponse,
+1 -1
View File
@@ -39,7 +39,7 @@ matrix-sdk-common = { version = "0.6.0", path = "../../crates/matrix-sdk-common"
matrix-sdk-crypto = { version = "0.6.0", path = "../../crates/matrix-sdk-crypto", features = ["js"] }
matrix-sdk-indexeddb = { version = "0.2.0", path = "../../crates/matrix-sdk-indexeddb", features = ["experimental-nodejs"] }
matrix-sdk-qrcode = { version = "0.4.0", path = "../../crates/matrix-sdk-qrcode", optional = true }
ruma = { workspace = true, features = ["js", "rand", "unstable-msc2676", "unstable-msc2677"] }
ruma = { workspace = true, features = ["js", "rand", "unstable-msc2677"] }
vodozemac = { workspace = true, features = ["js"] }
wasm-bindgen = "0.2.83"
wasm-bindgen-futures = "0.4.33"
+1 -1
View File
@@ -26,7 +26,7 @@ tracing = ["dep:tracing-subscriber"]
matrix-sdk-crypto = { version = "0.6.0", path = "../../crates/matrix-sdk-crypto", features = ["js"] }
matrix-sdk-common = { version = "0.6.0", path = "../../crates/matrix-sdk-common", features = ["js"] }
matrix-sdk-sled = { version = "0.2.0", path = "../../crates/matrix-sdk-sled", default-features = false, features = ["crypto-store"] }
ruma = { workspace = true, features = ["rand", "unstable-msc2676", "unstable-msc2677"] }
ruma = { workspace = true, features = ["rand", "unstable-msc2677"] }
napi = { version = "2.9.1", default-features = false, features = ["napi6", "tokio_rt"] }
napi-derive = "2.9.1"
serde_json = "1.0.79"
+7 -9
View File
@@ -17,7 +17,7 @@ use matrix_sdk::{
serde::Raw,
TransactionId, UInt,
},
Client as MatrixClient, Error, LoopCtrl, RumaApiError,
Client as MatrixClient, Error, LoopCtrl,
};
use super::{
@@ -297,15 +297,13 @@ impl Client {
/// Process a sync error and return loop control accordingly
pub(crate) fn process_sync_error(&self, sync_error: Error) -> LoopCtrl {
if let Some(RumaApiError::ClientApi(error)) = sync_error.as_ruma_api_error() {
if let ErrorKind::UnknownToken { soft_logout } = error.kind {
self.state.write().unwrap().is_soft_logout = soft_logout;
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_update_restore_token();
delegate.did_receive_auth_error(soft_logout);
}
return LoopCtrl::Break;
if let Some(ErrorKind::UnknownToken { soft_logout }) = sync_error.client_api_error_kind() {
self.state.write().unwrap().is_soft_logout = *soft_logout;
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_update_restore_token();
delegate.did_receive_auth_error(*soft_logout);
}
return LoopCtrl::Break;
}
tracing::warn!("Ignoring sync error: {:?}", sync_error);
+7 -4
View File
@@ -11,7 +11,10 @@ use matrix_sdk::{
Room as SdkRoom,
},
ruma::{
events::room::message::{Relation, Replacement, RoomMessageEvent, RoomMessageEventContent},
events::room::message::{
ForwardThread, MessageType, Relation, Replacement, RoomMessageEvent,
RoomMessageEventContent,
},
EventId, UserId,
},
};
@@ -191,8 +194,8 @@ impl Room {
let original_message =
event_content.as_original().context("Couldn't retrieve original message.")?;
let reply_content =
RoomMessageEventContent::text_markdown(msg).make_reply_to(original_message);
let reply_content = RoomMessageEventContent::text_markdown(msg)
.make_reply_to(original_message, ForwardThread::Yes);
timeline.send(reply_content.into(), txn_id.as_deref().map(Into::into)).await?;
@@ -233,7 +236,7 @@ impl Room {
let replacement = Replacement::new(
event_id.to_owned(),
Box::new(RoomMessageEventContent::text_markdown(new_msg.to_owned())),
MessageType::text_markdown(new_msg.to_owned()),
);
let mut edited_content = RoomMessageEventContent::text_markdown(new_msg);
+1 -1
View File
@@ -44,7 +44,7 @@ matrix-sdk-common = { version = "0.6.0", path = "../matrix-sdk-common" }
olm-rs = { version = "2.2.0", features = ["serde"], optional = true }
pbkdf2 = { version = "0.11.0", default-features = false }
rand = "0.8.5"
ruma = { workspace = true, features = ["rand", "canonical-json", "unstable-msc2676", "unstable-msc2677"] }
ruma = { workspace = true, features = ["rand", "canonical-json", "unstable-msc2677"] }
serde = { version = "1.0.136", features = ["derive", "rc"] }
serde_json = "1.0.79"
sha2 = "0.10.2"
+1 -1
View File
@@ -21,7 +21,7 @@ use std::collections::BTreeMap;
use matrix_sdk_crypto::{OlmMachine, OlmError};
use ruma::{
api::client::sync::sync_events::v3::{ToDevice, DeviceLists},
api::client::sync::sync_events::{v3::ToDevice, DeviceLists},
device_id, user_id,
};
+1 -1
View File
@@ -1584,7 +1584,7 @@ pub(crate) mod tests {
api::{
client::{
keys::{claim_keys, get_keys, upload_keys},
sync::sync_events::v3::DeviceLists,
sync::sync_events::DeviceLists,
to_device::send_event_to_device::v3::Response as ToDeviceResponse,
},
IncomingResponse,
+1 -1
View File
@@ -19,7 +19,7 @@ rustdoc-args = ["--cfg", "docsrs"]
base64 = "0.13.0"
byteorder = "1.4.3"
qrcode = { version = "0.12.0", default-features = false }
ruma-common = "0.10.0"
ruma-common = { workspace = true }
thiserror = "1.0.30"
vodozemac = { workspace = true }
+1 -1
View File
@@ -43,7 +43,7 @@ image-proc = ["dep:image"]
image-rayon = ["image-proc", "image?/jpeg_rayon"]
experimental-room-preview = []
experimental-timeline = ["ruma/unstable-msc2676", "ruma/unstable-msc2677"]
experimental-timeline = ["ruma/unstable-msc2677"]
sliding-sync = [
"matrix-sdk-base/sliding-sync",
+6 -3
View File
@@ -645,7 +645,7 @@ impl Account {
/// if let Some(raw_content) = maybe_content {
/// let content = raw_content.deserialize()?;
/// println!("Ignored users:");
/// for user_id in content.ignored_users {
/// for user_id in content.ignored_users.keys() {
/// println!("- {user_id}");
/// }
/// }
@@ -676,7 +676,8 @@ impl Account {
/// # let client = Client::new("http://localhost:8080".parse()?).await?;
/// # let account = client.account();
/// use matrix_sdk::ruma::{
/// events::ignored_user_list::IgnoredUserListEventContent, user_id,
/// events::ignored_user_list::{IgnoredUser, IgnoredUserListEventContent},
/// user_id,
/// };
///
/// let mut content = account
@@ -685,7 +686,9 @@ impl Account {
/// .map(|c| c.deserialize())
/// .transpose()?
/// .unwrap_or_default();
/// content.ignored_users.push(user_id!("@foo:bar.com").to_owned());
/// content
/// .ignored_users
/// .insert(user_id!("@foo:bar.com").to_owned(), IgnoredUser::new());
/// account.set_account_data(content).await?;
/// # anyhow::Ok(()) };
/// ```
+25 -41
View File
@@ -1699,26 +1699,21 @@ impl Client {
// If this is an `M_UNKNOWN_TOKEN` error and refresh token handling is active,
// try to refresh the token and retry the request.
if self.inner.handle_refresh_tokens {
// FIXME: Use if-let chain once available
if let Err(Some(RumaApiError::ClientApi(error))) =
res.as_ref().map_err(HttpError::as_ruma_api_error)
if let Err(Some(ErrorKind::UnknownToken { .. })) =
res.as_ref().map_err(HttpError::client_api_error_kind)
{
if matches!(error.kind, ErrorKind::UnknownToken { .. }) {
let refresh_res = self.refresh_access_token().await;
if let Err(refresh_error) = refresh_res {
match &refresh_error {
HttpError::RefreshToken(RefreshTokenError::RefreshTokenRequired) => {
// Refreshing access tokens is not supported by
// this `Session`, ignore.
}
_ => {
return Err(refresh_error);
}
if let Err(refresh_error) = self.refresh_access_token().await {
match &refresh_error {
HttpError::RefreshToken(RefreshTokenError::RefreshTokenRequired) => {
// Refreshing access tokens is not supported by
// this `Session`, ignore.
}
_ => {
return Err(refresh_error);
}
} else {
return self.send_inner(request, config, None).await;
}
} else {
return self.send_inner(request, config, None).await;
}
}
}
@@ -1744,26 +1739,21 @@ impl Client {
// If this is an `M_UNKNOWN_TOKEN` error and refresh token handling is active,
// try to refresh the token and retry the request.
if self.inner.handle_refresh_tokens {
// FIXME: Use if-let chain once available
if let Err(Some(RumaApiError::ClientApi(error))) =
res.as_ref().map_err(HttpError::as_ruma_api_error)
if let Err(Some(ErrorKind::UnknownToken { .. })) =
res.as_ref().map_err(HttpError::client_api_error_kind)
{
if matches!(error.kind, ErrorKind::UnknownToken { .. }) {
let refresh_res = self.refresh_access_token().await;
if let Err(refresh_error) = refresh_res {
match &refresh_error {
HttpError::RefreshToken(RefreshTokenError::RefreshTokenRequired) => {
// Refreshing access tokens is not supported by
// this `Session`, ignore.
}
_ => {
return Err(refresh_error);
}
if let Err(refresh_error) = self.refresh_access_token().await {
match &refresh_error {
HttpError::RefreshToken(RefreshTokenError::RefreshTokenRequired) => {
// Refreshing access tokens is not supported by
// this `Session`, ignore.
}
_ => {
return Err(refresh_error);
}
} else {
return self.send_inner(request, config, homeserver).await;
}
} else {
return self.send_inner(request, config, homeserver).await;
}
}
}
@@ -1876,13 +1866,7 @@ impl Client {
///
/// ```no_run
/// # use matrix_sdk::{
/// # ruma::{
/// # api::{
/// # client::uiaa,
/// # error::{FromHttpResponseError, ServerError},
/// # },
/// # device_id,
/// # },
/// # ruma::{api::client::uiaa, device_id},
/// # Client, Error, config::SyncSettings,
/// # };
/// # use futures::executor::block_on;
+25 -7
View File
@@ -28,7 +28,7 @@ use reqwest::Error as ReqwestError;
use ruma::{
api::{
client::uiaa::{UiaaInfo, UiaaResponse},
error::{FromHttpResponseError, IntoHttpError, ServerError},
error::{FromHttpResponseError, IntoHttpError},
},
events::tag::InvalidUserTagName,
IdParseError,
@@ -119,13 +119,13 @@ pub enum HttpError {
#[rustfmt::skip] // stop rustfmt breaking the `<code>` in docs across multiple lines
impl HttpError {
/// If `self` is
/// <code>[Api](Self::Api)([Server](FromHttpResponseError::Server)([Known](ServerError::Known)(e)))</code>,
/// <code>[Api](Self::Api)([Server](FromHttpResponseError::Server)(e))</code>,
/// returns `Some(e)`.
///
/// Otherwise, returns `None`.
pub fn as_ruma_api_error(&self) -> Option<&RumaApiError> {
match self {
Self::Api(FromHttpResponseError::Server(ServerError::Known(e))) => Some(e),
Self::Api(FromHttpResponseError::Server(e)) => Some(e),
_ => None,
}
}
@@ -136,6 +136,15 @@ impl HttpError {
self.as_ruma_api_error().and_then(RumaApiError::as_client_api_error)
}
/// If `self` is a server error in the `errcode` + `error` format expected
/// for client-API endpoints, returns the error kind (`errcode`).
pub fn client_api_error_kind(&self) -> Option<&ruma::api::client::error::ErrorKind> {
self.as_client_api_error().and_then(|e| match &e.body {
ruma::api::client::error::ErrorBody::Standard { kind, .. } => Some(kind),
_ => None,
})
}
/// Try to destructure the error into an universal interactive auth info.
///
/// Some requests require universal interactive auth, doing such a request
@@ -248,7 +257,7 @@ pub enum Error {
#[rustfmt::skip] // stop rustfmt breaking the `<code>` in docs across multiple lines
impl Error {
/// If `self` is
/// <code>[Http](Self::Http)([Api](HttpError::Api)([Server](FromHttpResponseError::Server)([Known](ServerError::Known)(e))))</code>,
/// <code>[Http](Self::Http)([Api](HttpError::Api)([Server](FromHttpResponseError::Server)(e)))</code>,
/// returns `Some(e)`.
///
/// Otherwise, returns `None`.
@@ -265,6 +274,15 @@ impl Error {
self.as_ruma_api_error().and_then(RumaApiError::as_client_api_error)
}
/// If `self` is a server error in the `errcode` + `error` format expected
/// for client-API endpoints, returns the error kind (`errcode`).
pub fn client_api_error_kind(&self) -> Option<&ruma::api::client::error::ErrorKind> {
self.as_client_api_error().and_then(|e| match &e.body {
ruma::api::client::error::ErrorBody::Standard { kind, .. } => Some(kind),
_ => None,
})
}
/// Try to destructure the error into an universal interactive auth info.
///
/// Some requests require universal interactive auth, doing such a request
@@ -314,19 +332,19 @@ pub enum RoomKeyImportError {
impl From<FromHttpResponseError<ruma::api::client::Error>> for HttpError {
fn from(err: FromHttpResponseError<ruma::api::client::Error>) -> Self {
Self::Api(err.map(|e| e.map(RumaApiError::ClientApi)))
Self::Api(err.map(RumaApiError::ClientApi))
}
}
impl From<FromHttpResponseError<UiaaResponse>> for HttpError {
fn from(err: FromHttpResponseError<UiaaResponse>) -> Self {
Self::Api(err.map(|e| e.map(RumaApiError::Uiaa)))
Self::Api(err.map(RumaApiError::Uiaa))
}
}
impl From<FromHttpResponseError<ruma::api::error::MatrixError>> for HttpError {
fn from(err: FromHttpResponseError<ruma::api::error::MatrixError>) -> Self {
Self::Api(err.map(|e| e.map(RumaApiError::Other)))
Self::Api(err.map(RumaApiError::Other))
}
}
+2 -2
View File
@@ -295,8 +295,8 @@ async fn send_request(
RetryError::Permanent
} else {
|err: HttpError| {
let retry_after = err.as_client_api_error().and_then(|e| match e.kind {
ClientApiErrorKind::LimitExceeded { retry_after_ms } => retry_after_ms,
let retry_after = err.client_api_error_kind().and_then(|kind| match kind {
ClientApiErrorKind::LimitExceeded { retry_after_ms } => *retry_after_ms,
_ => None,
});
RetryError::Transient { err, retry_after }
+2 -1
View File
@@ -15,9 +15,10 @@ use ruma::{
config::set_global_account_data,
filter::RoomEventFilter,
membership::{get_member_events, join_room_by_id, leave_room},
message::get_message_events::{self, v3::Direction},
message::get_message_events,
room::get_room_event,
tag::{create_tag, delete_tag},
Direction,
},
assign,
events::{
+4 -4
View File
@@ -250,10 +250,10 @@ impl Joined {
fully_read: &EventId,
read_receipt: Option<&EventId>,
) -> Result<()> {
let request =
assign!(set_read_marker::v3::Request::new(self.inner.room_id(), fully_read), {
read_receipt
});
let request = assign!(set_read_marker::v3::Request::new(self.inner.room_id()), {
fully_read: Some(fully_read),
read_receipt,
});
self.client.send(request, None).await?;
Ok(())
@@ -22,7 +22,7 @@ use ruma::{
reaction::ReactionEventContent,
room::{
encrypted::{self, RoomEncryptedEventContent},
message::{self, Replacement, RoomMessageEventContent},
message::{self, MessageType, Replacement, RoomMessageEventContent},
redaction::{
OriginalSyncRoomRedactionEvent, RoomRedactionEventContent, SyncRoomRedactionEvent,
},
@@ -304,7 +304,7 @@ impl<'a> TimelineEventHandler<'a> {
}
}
fn handle_room_message_edit(&mut self, replacement: Replacement) {
fn handle_room_message_edit(&mut self, replacement: Replacement<MessageType>) {
let event_id = &replacement.event_id;
self.maybe_update_timeline_item(event_id, "edit", |item| {
@@ -335,7 +335,7 @@ impl<'a> TimelineEventHandler<'a> {
};
let content = TimelineItemContent::Message(Message {
msgtype: replacement.new_content.msgtype,
msgtype: replacement.new_content,
in_reply_to: msg.in_reply_to.clone(),
edited: true,
});
+3 -3
View File
@@ -33,7 +33,7 @@ use ruma::{
encrypted::{
EncryptedEventScheme, MegolmV1AesSha2ContentInit, RoomEncryptedEventContent,
},
message::{self, Replacement, RoomMessageEventContent},
message::{self, MessageType, Replacement, RoomMessageEventContent},
redaction::OriginalSyncRoomRedactionEvent,
},
MessageLikeEventContent, OriginalSyncMessageLikeEvent,
@@ -94,7 +94,7 @@ async fn invalid_edit() {
let edit = assign!(RoomMessageEventContent::text_plain(" * fake"), {
relates_to: Some(message::Relation::Replacement(Replacement::new(
msg_event_id.to_owned(),
Box::new(RoomMessageEventContent::text_plain("fake")),
MessageType::text_plain("fake"),
))),
});
// Edit is from a different user than the previous event
@@ -135,7 +135,7 @@ async fn edit_redacted() {
let edit = assign!(RoomMessageEventContent::text_plain(" * test"), {
relates_to: Some(message::Relation::Replacement(Replacement::new(
redacted_event_id.to_owned(),
Box::new(RoomMessageEventContent::text_plain("test")),
MessageType::text_plain("test"),
))),
});
timeline.handle_live_message_event(&ALICE, edit);
+21 -13
View File
@@ -185,15 +185,20 @@ async fn login_error() {
.await;
if let Err(err) = client.login_username("example", "wordpass").send().await {
if let Some(RumaApiError::ClientApi(client_api::Error { kind, message, status_code })) =
if let Some(RumaApiError::ClientApi(client_api::Error { status_code, body })) =
err.as_ruma_api_error()
{
if *kind != client_api::error::ErrorKind::Forbidden {
panic!("found the wrong `ErrorKind` {kind:?}, expected `Forbidden");
}
assert_eq!(message, "Invalid password");
assert_eq!(*status_code, http::StatusCode::from_u16(403).unwrap());
if let client_api::error::ErrorBody::Standard { kind, message } = body {
if *kind != client_api::error::ErrorKind::Forbidden {
panic!("found the wrong `ErrorKind` {kind:?}, expected `Forbidden");
}
assert_eq!(message, "Invalid password");
} else {
panic!("non-standard error body")
}
} else {
panic!("found the wrong `Error` type {err:?}, expected `Error::RumaResponse");
}
@@ -225,17 +230,20 @@ async fn register_error() {
if let Err(err) = client.register(user).await {
if let Some(RumaApiError::Uiaa(UiaaResponse::MatrixError(client_api::Error {
kind,
message,
status_code,
body,
}))) = err.as_ruma_api_error()
{
if *kind != client_api::error::ErrorKind::Forbidden {
panic!("found the wrong `ErrorKind` {kind:?}, expected `Forbidden");
}
assert_eq!(message, "Invalid password");
assert_eq!(*status_code, http::StatusCode::from_u16(403).unwrap());
if let client_api::error::ErrorBody::Standard { kind, message } = body {
if *kind != client_api::error::ErrorKind::Forbidden {
panic!("found the wrong `ErrorKind` {kind:?}, expected `Forbidden");
}
assert_eq!(message, "Invalid password");
} else {
panic!("non-standard error body")
}
} else {
panic!("found the wrong `Error` type {err:#?}, expected `UiaaResponse`");
}
@@ -6,13 +6,11 @@ use futures::{
};
use futures_signals::signal::SignalExt;
use matches::assert_matches;
use matrix_sdk::{
config::RequestConfig, executor::spawn, HttpError, RefreshTokenError, RumaApiError, Session,
};
use matrix_sdk::{config::RequestConfig, executor::spawn, HttpError, RefreshTokenError, Session};
use matrix_sdk_test::{async_test, test_json};
use ruma::{
api::{
client::{account::register, error::ErrorKind, Error as ClientApiError},
client::{account::register, error::ErrorKind},
MatrixVersion,
},
assign, device_id, user_id,
@@ -229,10 +227,7 @@ async fn refresh_token_not_handled() {
.await;
let res = client.whoami().await.unwrap_err();
assert_matches!(
res.as_ruma_api_error(),
Some(RumaApiError::ClientApi(ClientApiError { kind: ErrorKind::UnknownToken { .. }, .. }))
);
assert_matches!(res.client_api_error_kind(), Some(ErrorKind::UnknownToken { .. }));
}
#[async_test]
@@ -360,10 +355,7 @@ async fn refresh_token_handled_failure() {
.await;
let res = client.whoami().await.unwrap_err();
assert_matches!(
res.as_ruma_api_error(),
Some(RumaApiError::ClientApi(ClientApiError { kind: ErrorKind::UnknownToken { .. }, .. }))
)
assert_matches!(res.client_api_error_kind(), Some(ErrorKind::UnknownToken { .. }))
}
#[async_test]
+7 -11
View File
@@ -8,9 +8,8 @@ use matrix_sdk_appservice::{
events::room::member::{MembershipState, OriginalSyncRoomMemberEvent},
UserId,
},
RumaApiError,
},
ruma::api::client::{error::ErrorKind, uiaa::UiaaResponse},
ruma::api::client::error::ErrorKind,
AppService, AppServiceBuilder, AppServiceRegistration, Result,
};
use tracing::trace;
@@ -39,15 +38,12 @@ pub fn error_if_user_not_in_use(error: matrix_sdk_appservice::Error) -> Result<(
// FIXME: Use if-let chain once available
match &error {
// If user is already in use that's OK.
matrix_sdk_appservice::Error::Matrix(err) => match err.as_ruma_api_error() {
Some(RumaApiError::Uiaa(UiaaResponse::MatrixError(error)))
if matches!(error.kind, ErrorKind::UserInUse) =>
{
Ok(())
}
// In all other cases return with an error.
_ => Err(error),
},
matrix_sdk_appservice::Error::Matrix(err)
if err.client_api_error_kind() == Some(&ErrorKind::UserInUse) =>
{
Ok(())
}
// In all other cases return with an error.
_ => Err(error),
}
}