Upgrade Ruma after report_content breaking change

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
Kévin Commaille
2026-03-06 15:42:07 +01:00
committed by Andy Balaam
parent 23a312ed68
commit 698ffba88e
7 changed files with 27 additions and 225 deletions
Generated
+9 -9
View File
@@ -4743,7 +4743,7 @@ dependencies = [
[[package]]
name = "ruma"
version = "0.14.1"
source = "git+https://github.com/ruma/ruma?rev=c2924025a67cf62085bbf611dea21317ad3f4a85#c2924025a67cf62085bbf611dea21317ad3f4a85"
source = "git+https://github.com/ruma/ruma?rev=b5a521948df97620162ccb99f8d50625df037e8e#b5a521948df97620162ccb99f8d50625df037e8e"
dependencies = [
"assign",
"js_int",
@@ -4761,7 +4761,7 @@ dependencies = [
[[package]]
name = "ruma-client-api"
version = "0.22.1"
source = "git+https://github.com/ruma/ruma?rev=c2924025a67cf62085bbf611dea21317ad3f4a85#c2924025a67cf62085bbf611dea21317ad3f4a85"
source = "git+https://github.com/ruma/ruma?rev=b5a521948df97620162ccb99f8d50625df037e8e#b5a521948df97620162ccb99f8d50625df037e8e"
dependencies = [
"as_variant",
"assign",
@@ -4784,7 +4784,7 @@ dependencies = [
[[package]]
name = "ruma-common"
version = "0.17.1"
source = "git+https://github.com/ruma/ruma?rev=c2924025a67cf62085bbf611dea21317ad3f4a85#c2924025a67cf62085bbf611dea21317ad3f4a85"
source = "git+https://github.com/ruma/ruma?rev=b5a521948df97620162ccb99f8d50625df037e8e#b5a521948df97620162ccb99f8d50625df037e8e"
dependencies = [
"as_variant",
"base64",
@@ -4817,7 +4817,7 @@ dependencies = [
[[package]]
name = "ruma-events"
version = "0.32.1"
source = "git+https://github.com/ruma/ruma?rev=c2924025a67cf62085bbf611dea21317ad3f4a85#c2924025a67cf62085bbf611dea21317ad3f4a85"
source = "git+https://github.com/ruma/ruma?rev=b5a521948df97620162ccb99f8d50625df037e8e#b5a521948df97620162ccb99f8d50625df037e8e"
dependencies = [
"as_variant",
"indexmap",
@@ -4844,7 +4844,7 @@ dependencies = [
[[package]]
name = "ruma-federation-api"
version = "0.13.1"
source = "git+https://github.com/ruma/ruma?rev=c2924025a67cf62085bbf611dea21317ad3f4a85#c2924025a67cf62085bbf611dea21317ad3f4a85"
source = "git+https://github.com/ruma/ruma?rev=b5a521948df97620162ccb99f8d50625df037e8e#b5a521948df97620162ccb99f8d50625df037e8e"
dependencies = [
"headers",
"http",
@@ -4865,7 +4865,7 @@ dependencies = [
[[package]]
name = "ruma-html"
version = "0.6.0"
source = "git+https://github.com/ruma/ruma?rev=c2924025a67cf62085bbf611dea21317ad3f4a85#c2924025a67cf62085bbf611dea21317ad3f4a85"
source = "git+https://github.com/ruma/ruma?rev=b5a521948df97620162ccb99f8d50625df037e8e#b5a521948df97620162ccb99f8d50625df037e8e"
dependencies = [
"as_variant",
"html5ever",
@@ -4876,7 +4876,7 @@ dependencies = [
[[package]]
name = "ruma-identifiers-validation"
version = "0.12.0"
source = "git+https://github.com/ruma/ruma?rev=c2924025a67cf62085bbf611dea21317ad3f4a85#c2924025a67cf62085bbf611dea21317ad3f4a85"
source = "git+https://github.com/ruma/ruma?rev=b5a521948df97620162ccb99f8d50625df037e8e#b5a521948df97620162ccb99f8d50625df037e8e"
dependencies = [
"js_int",
"thiserror 2.0.17",
@@ -4885,7 +4885,7 @@ dependencies = [
[[package]]
name = "ruma-macros"
version = "0.17.1"
source = "git+https://github.com/ruma/ruma?rev=c2924025a67cf62085bbf611dea21317ad3f4a85#c2924025a67cf62085bbf611dea21317ad3f4a85"
source = "git+https://github.com/ruma/ruma?rev=b5a521948df97620162ccb99f8d50625df037e8e#b5a521948df97620162ccb99f8d50625df037e8e"
dependencies = [
"as_variant",
"cfg-if",
@@ -4901,7 +4901,7 @@ dependencies = [
[[package]]
name = "ruma-signatures"
version = "0.19.0"
source = "git+https://github.com/ruma/ruma?rev=c2924025a67cf62085bbf611dea21317ad3f4a85#c2924025a67cf62085bbf611dea21317ad3f4a85"
source = "git+https://github.com/ruma/ruma?rev=b5a521948df97620162ccb99f8d50625df037e8e#b5a521948df97620162ccb99f8d50625df037e8e"
dependencies = [
"base64",
"ed25519-dalek",
+1 -1
View File
@@ -70,7 +70,7 @@ rand = { version = "0.8.5", default-features = false, features = ["std", "std_rn
regex = { version = "1.12.2", default-features = false }
reqwest = { version = "0.12.24", default-features = false }
rmp-serde = { version = "1.3.0", default-features = false }
ruma = { git = "https://github.com/ruma/ruma", rev = "c2924025a67cf62085bbf611dea21317ad3f4a85", features = [
ruma = { git = "https://github.com/ruma/ruma", rev = "b5a521948df97620162ccb99f8d50625df037e8e", features = [
"client-api-c",
"compat-unset-avatar",
"compat-upload-signatures",
+3
View File
@@ -94,6 +94,9 @@ All notable changes to this project will be documented in this file.
### Refactor
- [**breaking**] `Room::report_content()` no longer takes a `score` argument, because it was
removed from the Matrix specification.
([#6256](https://github.com/matrix-org/matrix-rust-sdk/pull/6256))
- [**breaking**] The `current_version` field of `ErrorKind::WrongRoomKeysVersion`
is no longer optional.
([#6241](https://github.com/matrix-org/matrix-rust-sdk/pull/6241))
+1 -11
View File
@@ -21,7 +21,6 @@ use matrix_sdk::{
room::{
edit::EditedContent, power_levels::RoomPowerLevelChanges,
ListThreadsOptions as SdkListThreadsOptions, Room as SdkRoom, RoomMemberRole,
TryFromReportedContentScoreError,
},
send_queue::RoomSendQueueUpdate as SdkRoomSendQueueUpdate,
ComposerDraft as SdkComposerDraft, ComposerDraftType as SdkComposerDraftType,
@@ -484,18 +483,9 @@ impl Room {
pub async fn report_content(
&self,
event_id: String,
score: Option<i32>,
reason: Option<String>,
) -> Result<(), ClientError> {
self.inner
.report_content(
EventId::parse(event_id)?,
score.map(TryFrom::try_from).transpose().map_err(
|error: TryFromReportedContentScoreError| ClientError::from_err(error),
)?,
reason,
)
.await?;
self.inner.report_content(EventId::parse(event_id)?, reason).await?;
Ok(())
}
+3 -1
View File
@@ -91,10 +91,12 @@ All notable changes to this project will be documented in this file.
### Refactor
- [**breaking**] `Room::report_content()` no longer takes a `score` argument, because it was
removed from the Matrix specification. The `ReportedContentScore` type was removed too.
([#6256](https://github.com/matrix-org/matrix-rust-sdk/pull/6256))
- [**breaking**] `Client::enabled_thread_subscriptions()` is now async and fallible, as it will
check for both static enablement of the thread subscription feature as well as dynamically
checking that the user's homeserver supports it.
([#6245](https://github.com/matrix-org/matrix-rust-sdk/pull/6245))
- [**breaking**] `SessionChange::UnknownToken` is now a tuple variant containing
an `UnknownTokenErrorData`.
([#6241](https://github.com/matrix-org/matrix-rust-sdk/pull/6241))
+8 -198
View File
@@ -3841,7 +3841,6 @@ impl Room {
pub async fn report_content(
&self,
event_id: OwnedEventId,
score: Option<ReportedContentScore>,
reason: Option<String>,
) -> Result<report_content::v3::Response> {
let state = self.state();
@@ -3849,11 +3848,13 @@ impl Room {
return Err(Error::WrongRoomState(Box::new(WrongRoomState::new("Joined", state))));
}
let request = report_content::v3::Request::new(
self.inner.room_id().to_owned(),
event_id,
score.map(Into::into),
reason,
let request = assign!(
report_content::v3::Request::new(
self.inner.room_id().to_owned(),
event_id,
), {
reason: reason
}
);
Ok(self.client.send(request).await?)
}
@@ -4733,134 +4734,6 @@ pub enum ParentSpace {
Unverifiable(OwnedRoomId),
}
/// The score to rate an inappropriate content.
///
/// Must be a value between `0`, inoffensive, and `-100`, very offensive.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct ReportedContentScore(i8);
impl ReportedContentScore {
/// The smallest value that can be represented by this type.
///
/// This is for very offensive content.
pub const MIN: Self = Self(-100);
/// The largest value that can be represented by this type.
///
/// This is for inoffensive content.
pub const MAX: Self = Self(0);
/// Try to create a `ReportedContentScore` from the provided `i8`.
///
/// Returns `None` if it is smaller than [`ReportedContentScore::MIN`] or
/// larger than [`ReportedContentScore::MAX`] .
///
/// This is the same as the `TryFrom<i8>` implementation for
/// `ReportedContentScore`, except that it returns an `Option` instead
/// of a `Result`.
pub fn new(value: i8) -> Option<Self> {
value.try_into().ok()
}
/// Create a `ReportedContentScore` from the provided `i8` clamped to the
/// acceptable interval.
///
/// The given value gets clamped into the closed interval between
/// [`ReportedContentScore::MIN`] and [`ReportedContentScore::MAX`].
pub fn new_saturating(value: i8) -> Self {
if value > Self::MAX {
Self::MAX
} else if value < Self::MIN {
Self::MIN
} else {
Self(value)
}
}
/// The value of this score.
pub fn value(&self) -> i8 {
self.0
}
}
impl PartialEq<i8> for ReportedContentScore {
fn eq(&self, other: &i8) -> bool {
self.0.eq(other)
}
}
impl PartialEq<ReportedContentScore> for i8 {
fn eq(&self, other: &ReportedContentScore) -> bool {
self.eq(&other.0)
}
}
impl PartialOrd<i8> for ReportedContentScore {
fn partial_cmp(&self, other: &i8) -> Option<std::cmp::Ordering> {
self.0.partial_cmp(other)
}
}
impl PartialOrd<ReportedContentScore> for i8 {
fn partial_cmp(&self, other: &ReportedContentScore) -> Option<std::cmp::Ordering> {
self.partial_cmp(&other.0)
}
}
impl From<ReportedContentScore> for Int {
fn from(value: ReportedContentScore) -> Self {
value.0.into()
}
}
impl TryFrom<i8> for ReportedContentScore {
type Error = TryFromReportedContentScoreError;
fn try_from(value: i8) -> std::prelude::v1::Result<Self, Self::Error> {
if value > Self::MAX || value < Self::MIN {
Err(TryFromReportedContentScoreError(()))
} else {
Ok(Self(value))
}
}
}
impl TryFrom<i16> for ReportedContentScore {
type Error = TryFromReportedContentScoreError;
fn try_from(value: i16) -> std::prelude::v1::Result<Self, Self::Error> {
let value = i8::try_from(value).map_err(|_| TryFromReportedContentScoreError(()))?;
value.try_into()
}
}
impl TryFrom<i32> for ReportedContentScore {
type Error = TryFromReportedContentScoreError;
fn try_from(value: i32) -> std::prelude::v1::Result<Self, Self::Error> {
let value = i8::try_from(value).map_err(|_| TryFromReportedContentScoreError(()))?;
value.try_into()
}
}
impl TryFrom<i64> for ReportedContentScore {
type Error = TryFromReportedContentScoreError;
fn try_from(value: i64) -> std::prelude::v1::Result<Self, Self::Error> {
let value = i8::try_from(value).map_err(|_| TryFromReportedContentScoreError(()))?;
value.try_into()
}
}
impl TryFrom<Int> for ReportedContentScore {
type Error = TryFromReportedContentScoreError;
fn try_from(value: Int) -> std::prelude::v1::Result<Self, Self::Error> {
let value = i8::try_from(value).map_err(|_| TryFromReportedContentScoreError(()))?;
value.try_into()
}
}
trait EventSource {
fn get_event(
&self,
@@ -4874,12 +4747,6 @@ impl EventSource for &Room {
}
}
/// The error type returned when a checked `ReportedContentScore` conversion
/// fails.
#[derive(Debug, Clone, Error)]
#[error("out of range conversion attempted")]
pub struct TryFromReportedContentScoreError(());
/// Contains the current user's room member info and the optional room member
/// info of the sender of the `m.room.member` event that this info represents.
#[derive(Debug)]
@@ -4902,14 +4769,13 @@ mod tests {
use ruma::{
RoomVersionId, event_id,
events::{relation::RelationType, room::member::MembershipState},
int, owned_event_id, room_id, user_id,
owned_event_id, room_id, user_id,
};
use wiremock::{
Mock, MockServer, ResponseTemplate,
matchers::{header, method, path_regex},
};
use super::ReportedContentScore;
use crate::{
Client,
config::RequestConfig,
@@ -5017,62 +4883,6 @@ mod tests {
.unwrap();
}
#[test]
fn reported_content_score() {
// i8
let score = ReportedContentScore::new(0).unwrap();
assert_eq!(score.value(), 0);
let score = ReportedContentScore::new(-50).unwrap();
assert_eq!(score.value(), -50);
let score = ReportedContentScore::new(-100).unwrap();
assert_eq!(score.value(), -100);
assert_eq!(ReportedContentScore::new(10), None);
assert_eq!(ReportedContentScore::new(-110), None);
let score = ReportedContentScore::new_saturating(0);
assert_eq!(score.value(), 0);
let score = ReportedContentScore::new_saturating(-50);
assert_eq!(score.value(), -50);
let score = ReportedContentScore::new_saturating(-100);
assert_eq!(score.value(), -100);
let score = ReportedContentScore::new_saturating(10);
assert_eq!(score, ReportedContentScore::MAX);
let score = ReportedContentScore::new_saturating(-110);
assert_eq!(score, ReportedContentScore::MIN);
// i16
let score = ReportedContentScore::try_from(0i16).unwrap();
assert_eq!(score.value(), 0);
let score = ReportedContentScore::try_from(-100i16).unwrap();
assert_eq!(score.value(), -100);
ReportedContentScore::try_from(10i16).unwrap_err();
ReportedContentScore::try_from(-110i16).unwrap_err();
// i32
let score = ReportedContentScore::try_from(0i32).unwrap();
assert_eq!(score.value(), 0);
let score = ReportedContentScore::try_from(-100i32).unwrap();
assert_eq!(score.value(), -100);
ReportedContentScore::try_from(10i32).unwrap_err();
ReportedContentScore::try_from(-110i32).unwrap_err();
// i64
let score = ReportedContentScore::try_from(0i64).unwrap();
assert_eq!(score.value(), 0);
let score = ReportedContentScore::try_from(-100i64).unwrap();
assert_eq!(score.value(), -100);
ReportedContentScore::try_from(10i64).unwrap_err();
ReportedContentScore::try_from(-110i64).unwrap_err();
// Int
let score = ReportedContentScore::try_from(int!(0)).unwrap();
assert_eq!(score.value(), 0);
let score = ReportedContentScore::try_from(int!(-100)).unwrap();
assert_eq!(score.value(), -100);
ReportedContentScore::try_from(int!(10)).unwrap_err();
ReportedContentScore::try_from(int!(-110)).unwrap_err();
}
#[async_test]
async fn test_composer_draft() {
use matrix_sdk_test::DEFAULT_TEST_ROOM_ID;
@@ -10,7 +10,7 @@ use futures_util::{future::join_all, pin_mut};
use matrix_sdk::{
assert_next_with_timeout, assert_recv_with_timeout,
config::SyncSettings,
room::{Receipts, ReportedContentScore, RoomMemberRole, edit::EditedContent},
room::{Receipts, RoomMemberRole, edit::EditedContent},
test_utils::mocks::MatrixMockServer,
};
use matrix_sdk_base::{EncryptionState, RoomMembersUpdate, RoomState};
@@ -807,13 +807,11 @@ async fn test_report_content() {
let (client, server) = logged_in_client_with_server().await;
let reason = "I am offended";
let score = int!(-80);
Mock::given(method("POST"))
.and(path_regex(r"^/_matrix/client/r0/rooms/.*/report/\$offensive_event"))
.and(body_json(json!({
"reason": reason,
"score": score,
})))
.and(header("authorization", "Bearer 1234"))
.respond_with(ResponseTemplate::new(200).set_body_json(&*test_json::EMPTY))
@@ -830,9 +828,8 @@ async fn test_report_content() {
let event_id = owned_event_id!("$offensive_event");
let reason = "I am offended".to_owned();
let score = ReportedContentScore::new(-80).unwrap();
room.report_content(event_id, Some(score), Some(reason.to_owned())).await.unwrap();
room.report_content(event_id, Some(reason.to_owned())).await.unwrap();
}
#[async_test]