client-api: Stabilize MSC3316

This commit is contained in:
Kévin Commaille 2022-06-20 17:26:01 +02:00 committed by Kévin Commaille
parent 80a8dcf28a
commit fdb45296c5
5 changed files with 13 additions and 50 deletions

View File

@ -10,7 +10,7 @@ Improvements:
* Add support for refresh tokens (MSC2918)
* Add `ErrorKind::{UnableToAuthorizeJoin, UnableToGrantJoin}` encountered for restricted rooms
* Add unstable support for timestamp massaging (MSC3316)
* Add support for timestamp massaging (MSC3316)
* Add support for querying relating events (MSC2675)
* Move `filter::RelationType` to `ruma_common::events::relations`
* Add unstable support for discovering an OpenID Connect server (MSC2965)

View File

@ -25,7 +25,6 @@ unstable-msc2654 = []
unstable-msc2676 = []
unstable-msc2677 = []
unstable-msc2965 = []
unstable-msc3316 = []
unstable-msc3440 = []
unstable-msc3488 = []
client = []

View File

@ -5,13 +5,11 @@ pub mod v3 {
//!
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidsendeventtypetxnid
#[cfg(feature = "unstable-msc3316")]
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_common::{
api::ruma_api,
events::{AnyMessageLikeEventContent, MessageLikeEventContent, MessageLikeEventType},
serde::Raw,
OwnedEventId, RoomId, TransactionId,
MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, TransactionId,
};
use serde_json::value::to_raw_value as to_raw_json_value;
@ -54,8 +52,7 @@ pub mod v3 {
///
/// Note that this does not change the position of the event in the timeline.
///
/// [timestamp massaging]: https://github.com/matrix-org/matrix-spec-proposals/pull/3316
#[cfg(feature = "unstable-msc3316")]
/// [timestamp massaging]: https://spec.matrix.org/v1.3/application-service-api/#timestamp-massaging
#[ruma_api(query)]
#[serde(skip_serializing_if = "Option::is_none", rename = "ts")]
pub timestamp: Option<MilliSecondsSinceUnixEpoch>,
@ -89,7 +86,6 @@ pub mod v3 {
txn_id,
event_type: content.event_type(),
body: Raw::from_json(to_raw_json_value(content)?),
#[cfg(feature = "unstable-msc3316")]
timestamp: None,
})
}
@ -102,14 +98,7 @@ pub mod v3 {
event_type: MessageLikeEventType,
body: Raw<AnyMessageLikeEventContent>,
) -> Self {
Self {
room_id,
event_type,
txn_id,
body,
#[cfg(feature = "unstable-msc3316")]
timestamp: None,
}
Self { room_id, event_type, txn_id, body, timestamp: None }
}
}

View File

@ -5,13 +5,11 @@ pub mod v3 {
//!
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidstateeventtypestatekey
#[cfg(feature = "unstable-msc3316")]
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_common::{
api::ruma_api,
events::{AnyStateEventContent, StateEventContent, StateEventType},
serde::{Incoming, Raw},
OwnedEventId, RoomId,
MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId,
};
use serde_json::value::to_raw_value as to_raw_json_value;
@ -60,8 +58,7 @@ pub mod v3 {
///
/// Note that this does not change the position of the event in the timeline.
///
/// [timestamp massaging]: https://github.com/matrix-org/matrix-spec-proposals/pull/3316
#[cfg(feature = "unstable-msc3316")]
/// [timestamp massaging]: https://spec.matrix.org/v1.3/application-service-api/#timestamp-massaging
pub timestamp: Option<MilliSecondsSinceUnixEpoch>,
}
@ -85,7 +82,6 @@ pub mod v3 {
state_key,
event_type: content.event_type(),
body: Raw::from_json(to_raw_json_value(content)?),
#[cfg(feature = "unstable-msc3316")]
timestamp: None,
})
}
@ -98,14 +94,7 @@ pub mod v3 {
state_key: &'a str,
body: Raw<AnyStateEventContent>,
) -> Self {
Self {
room_id,
event_type,
state_key,
body,
#[cfg(feature = "unstable-msc3316")]
timestamp: None,
}
Self { room_id, event_type, state_key, body, timestamp: None }
}
}
@ -160,12 +149,9 @@ pub mod v3 {
url.push_str(&Cow::from(utf8_percent_encode(self.state_key, NON_ALPHANUMERIC)));
}
#[cfg(feature = "unstable-msc3316")]
{
let request_query = RequestQuery { timestamp: self.timestamp };
url.push('?');
url.push_str(&ruma_common::serde::urlencoded::to_string(request_query)?);
}
let http_request = http::Request::builder()
.method(http::Method::PUT)
@ -225,33 +211,24 @@ pub mod v3 {
(a, b, "".into())
};
#[cfg(feature = "unstable-msc3316")]
let request_query: RequestQuery =
ruma_common::serde::urlencoded::from_str(request.uri().query().unwrap_or(""))?;
let body = serde_json::from_slice(request.body().as_ref())?;
Ok(Self {
room_id,
event_type,
state_key,
body,
#[cfg(feature = "unstable-msc3316")]
timestamp: request_query.timestamp,
})
Ok(Self { room_id, event_type, state_key, body, timestamp: request_query.timestamp })
}
}
/// Data in the request's query string.
#[cfg(feature = "unstable-msc3316")]
#[derive(Debug)]
#[cfg_attr(feature = "client", derive(serde::Serialize))]
#[cfg_attr(feature = "server", derive(serde::Deserialize))]
struct RequestQuery {
/// Timestamp to use for the `origin_server_ts` of the event.
#[serde(
rename = "org.matrix.msc3316.ts",
alias = "ts",
alias = "org.matrix.msc3316.ts",
rename = "ts",
skip_serializing_if = "Option::is_none"
)]
pub timestamp: Option<MilliSecondsSinceUnixEpoch>,

View File

@ -137,7 +137,6 @@ unstable-msc2746 = ["ruma-common/unstable-msc2746"]
unstable-msc2870 = ["ruma-signatures?/unstable-msc2870"]
unstable-msc3245 = ["ruma-common/unstable-msc3245"]
unstable-msc3246 = ["ruma-common/unstable-msc3246"]
unstable-msc3316 = ["ruma-client-api?/unstable-msc3316"]
unstable-msc3381 = ["ruma-common/unstable-msc3381"]
unstable-msc3440 = [
"ruma-client-api?/unstable-msc3440",
@ -168,7 +167,6 @@ __ci = [
"unstable-msc2870",
"unstable-msc3245",
"unstable-msc3246",
"unstable-msc3316",
"unstable-msc3381",
"unstable-msc3440",
"unstable-msc3488",