Merge remote-tracking branch 'upstream/main' into conduwuit-changes

This commit is contained in:
strawberry 2024-06-10 16:57:10 -04:00
commit fd686e7795
37 changed files with 735 additions and 71 deletions

View File

@ -8,23 +8,21 @@ exclude = [
] ]
[advisories] [advisories]
vulnerability = "deny" version = 2
unmaintained = "deny"
[licenses] [licenses]
default = "deny" version = 2
unlicensed = "deny"
allow = [ allow = [
"Apache-2.0", "Apache-2.0",
"BSD-3-Clause", "BSD-3-Clause",
"ISC", "ISC",
"MIT", "MIT",
"MPL-2.0",
"OpenSSL", "OpenSSL",
"Unicode-3.0",
"Unicode-DFS-2016", "Unicode-DFS-2016",
"Zlib", "Zlib",
] ]
# MPL-2.0 is copyleft but not "infectuous" like GPL
copyleft = "allow"
private = { ignore = true } private = { ignore = true }
[[licenses.clarify]] [[licenses.clarify]]

View File

@ -132,6 +132,9 @@ jobs:
- name: Run Tests - name: Run Tests
cmd: test-all cmd: test-all
- name: Run Compat Tests
cmd: test-compat
- name: Run Doc Tests - name: Run Doc Tests
cmd: test-doc cmd: test-doc

View File

@ -1,8 +1,27 @@
# [unreleased] # [unreleased]
Breaking changes:
- `RoomSummary::heroes` now properly contains only `UserId` instead of `String`
as before.
- Change type of `client_secret` field in `ThirdpartyIdCredentials`
from `Box<ClientSecret>` to `OwnedClientSecret`
Improvements: Improvements:
- Add support for MSC4108 OIDC sign in and E2EE set up via QR code - Add support for MSC4108 OIDC sign in and E2EE set up via QR code
- Heroes in `sync::sync_events::v4`: `SyncRequestList` and `RoomSubscription`
both have a new `include_heroes` field. `SlidingSyncRoom` has a new `heroes`
field, with a new type `SlidingSyncRoomHero`.
- Add unstable support for authenticated media endpoints, according to MSC3916.
Bug fixes:
- Rename `avatar` to `avatar_url` when (De)serializing
Bug fixes:
- `user_id` of `SlidingSyncRoomHero` is now mandatory
# 0.18.0 # 0.18.0

View File

@ -13,7 +13,6 @@ rust-version = { workspace = true }
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[features] [features]
# OutgoingRequest and IncomingResponse implementations # OutgoingRequest and IncomingResponse implementations
@ -49,6 +48,7 @@ unstable-msc3488 = []
unstable-msc3575 = [] unstable-msc3575 = []
unstable-msc3814 = [] unstable-msc3814 = []
unstable-msc3843 = [] unstable-msc3843 = []
unstable-msc3916 = []
unstable-msc3983 = [] unstable-msc3983 = []
unstable-msc4108 = [] unstable-msc4108 = []
unstable-msc4121 = [] unstable-msc4121 = []

View File

@ -1,6 +0,0 @@
fn main() {
// Prevent unnecessary rerunning of this build script
println!("cargo:rerun-if-changed=build.rs");
// Prevent nightly CI from erroring on docsrs attributes
println!("cargo:rustc-check-cfg=cfg(docsrs)");
}

View File

@ -0,0 +1,9 @@
//! Authenticated endpoints for the media repository, according to [MSC3916].
//!
//! [MSC3916]: https://github.com/matrix-org/matrix-spec-proposals/pull/3916
pub mod get_content;
pub mod get_content_as_filename;
pub mod get_content_thumbnail;
pub mod get_media_config;
pub mod get_media_preview;

View File

@ -0,0 +1,92 @@
//! `GET /_matrix/client/*/media/download/{serverName}/{mediaId}`
//!
//! Retrieve content from the media store.
pub mod unstable {
//! `/unstable/org.matrix.msc3916/` ([MSC])
//!
//! [MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/3916
use std::time::Duration;
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
use ruma_common::{
api::{request, response, Metadata},
metadata, IdParseError, MxcUri, OwnedServerName,
};
const METADATA: Metadata = metadata! {
method: GET,
rate_limited: false,
authentication: AccessToken,
history: {
unstable => "/_matrix/client/unstable/org.matrix.msc3916/media/download/:server_name/:media_id",
}
};
/// Request type for the `get_media_content` endpoint.
#[request(error = crate::Error)]
pub struct Request {
/// The server name from the mxc:// URI (the authoritory component).
#[ruma_api(path)]
pub server_name: OwnedServerName,
/// The media ID from the mxc:// URI (the path component).
#[ruma_api(path)]
pub media_id: String,
/// The maximum duration that the client is willing to wait to start receiving data, in the
/// case that the content has not yet been uploaded.
///
/// The default value is 20 seconds.
#[ruma_api(query)]
#[serde(
with = "ruma_common::serde::duration::ms",
default = "crate::media::default_download_timeout",
skip_serializing_if = "crate::media::is_default_download_timeout"
)]
pub timeout_ms: Duration,
}
/// Response type for the `get_media_content` endpoint.
#[response(error = crate::Error)]
pub struct Response {
/// The content that was previously uploaded.
#[ruma_api(raw_body)]
pub file: Vec<u8>,
/// The content type of the file that was previously uploaded.
#[ruma_api(header = CONTENT_TYPE)]
pub content_type: Option<String>,
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
/// file that was previously uploaded.
///
/// See [MDN] for the syntax.
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
#[ruma_api(header = CONTENT_DISPOSITION)]
pub content_disposition: Option<String>,
}
impl Request {
/// Creates a new `Request` with the given media ID and server name.
pub fn new(media_id: String, server_name: OwnedServerName) -> Self {
Self { media_id, server_name, timeout_ms: crate::media::default_download_timeout() }
}
/// Creates a new `Request` with the given URI.
pub fn from_uri(uri: &MxcUri) -> Result<Self, IdParseError> {
let (server_name, media_id) = uri.parts()?;
Ok(Self::new(media_id.to_owned(), server_name.to_owned()))
}
}
impl Response {
/// Creates a new `Response` with the given file contents.
pub fn new(file: Vec<u8>) -> Self {
Self { file, content_type: None, content_disposition: None }
}
}
}

View File

@ -0,0 +1,101 @@
//! `GET /_matrix/client/*/media/download/{serverName}/{mediaId}/{fileName}`
//!
//! Retrieve content from the media store, specifying a filename to return.
pub mod unstable {
//! `/unstable/org.matrix.msc3916/` ([MSC])
//!
//! [MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/3916
use std::time::Duration;
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
use ruma_common::{
api::{request, response, Metadata},
metadata, IdParseError, MxcUri, OwnedServerName,
};
const METADATA: Metadata = metadata! {
method: GET,
rate_limited: false,
authentication: AccessToken,
history: {
unstable => "/_matrix/client/unstable/org.matrix.msc3916/media/download/:server_name/:media_id/:filename",
}
};
/// Request type for the `get_media_content_as_filename` endpoint.
#[request(error = crate::Error)]
pub struct Request {
/// The server name from the mxc:// URI (the authoritory component).
#[ruma_api(path)]
pub server_name: OwnedServerName,
/// The media ID from the mxc:// URI (the path component).
#[ruma_api(path)]
pub media_id: String,
/// The filename to return in the `Content-Disposition` header.
#[ruma_api(path)]
pub filename: String,
/// The maximum duration that the client is willing to wait to start receiving data, in the
/// case that the content has not yet been uploaded.
///
/// The default value is 20 seconds.
#[ruma_api(query)]
#[serde(
with = "ruma_common::serde::duration::ms",
default = "crate::media::default_download_timeout",
skip_serializing_if = "crate::media::is_default_download_timeout"
)]
pub timeout_ms: Duration,
}
/// Response type for the `get_media_content_as_filename` endpoint.
#[response(error = crate::Error)]
pub struct Response {
/// The content that was previously uploaded.
#[ruma_api(raw_body)]
pub file: Vec<u8>,
/// The content type of the file that was previously uploaded.
#[ruma_api(header = CONTENT_TYPE)]
pub content_type: Option<String>,
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
/// file that was previously uploaded.
///
/// See [MDN] for the syntax.
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
#[ruma_api(header = CONTENT_DISPOSITION)]
pub content_disposition: Option<String>,
}
impl Request {
/// Creates a new `Request` with the given media ID, server name and filename.
pub fn new(media_id: String, server_name: OwnedServerName, filename: String) -> Self {
Self {
media_id,
server_name,
filename,
timeout_ms: crate::media::default_download_timeout(),
}
}
/// Creates a new `Request` with the given URI and filename.
pub fn from_uri(uri: &MxcUri, filename: String) -> Result<Self, IdParseError> {
let (server_name, media_id) = uri.parts()?;
Ok(Self::new(media_id.to_owned(), server_name.to_owned(), filename))
}
}
impl Response {
/// Creates a new `Response` with the given file.
pub fn new(file: Vec<u8>) -> Self {
Self { file, content_type: None, content_disposition: None }
}
}
}

View File

@ -0,0 +1,134 @@
//! `GET /_matrix/client/*/media/thumbnail/{serverName}/{mediaId}`
//!
//! Get a thumbnail of content from the media store.
pub mod unstable {
//! `/unstable/org.matrix.msc3916/` ([MSC])
//!
//! [MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/3916
use std::time::Duration;
use http::header::CONTENT_TYPE;
use js_int::UInt;
use ruma_common::{
api::{request, response, Metadata},
metadata, IdParseError, MxcUri, OwnedServerName,
};
use crate::media::get_content_thumbnail::v3::Method;
const METADATA: Metadata = metadata! {
method: GET,
rate_limited: true,
authentication: AccessToken,
history: {
unstable => "/_matrix/client/unstable/org.matrix.msc3916/media/thumbnail/:server_name/:media_id",
}
};
/// Request type for the `get_content_thumbnail` endpoint.
#[request(error = crate::Error)]
pub struct Request {
/// The server name from the mxc:// URI (the authoritory component).
#[ruma_api(path)]
pub server_name: OwnedServerName,
/// The media ID from the mxc:// URI (the path component).
#[ruma_api(path)]
pub media_id: String,
/// The desired resizing method.
#[ruma_api(query)]
#[serde(skip_serializing_if = "Option::is_none")]
pub method: Option<Method>,
/// The *desired* width of the thumbnail.
///
/// The actual thumbnail may not match the size specified.
#[ruma_api(query)]
pub width: UInt,
/// The *desired* height of the thumbnail.
///
/// The actual thumbnail may not match the size specified.
#[ruma_api(query)]
pub height: UInt,
/// The maximum duration that the client is willing to wait to start receiving data, in the
/// case that the content has not yet been uploaded.
///
/// The default value is 20 seconds.
#[ruma_api(query)]
#[serde(
with = "ruma_common::serde::duration::ms",
default = "crate::media::default_download_timeout",
skip_serializing_if = "crate::media::is_default_download_timeout"
)]
pub timeout_ms: Duration,
/// Whether the server should return an animated thumbnail.
///
/// When `true`, the server should return an animated thumbnail if possible and supported.
/// Otherwise it must not return an animated thumbnail.
///
/// Defaults to `false`.
#[cfg(feature = "unstable-msc2705")]
#[ruma_api(query)]
#[serde(
rename = "org.matrix.msc2705.animated",
default,
skip_serializing_if = "ruma_common::serde::is_default"
)]
pub animated: bool,
}
/// Response type for the `get_content_thumbnail` endpoint.
#[response(error = crate::Error)]
pub struct Response {
/// A thumbnail of the requested content.
#[ruma_api(raw_body)]
pub file: Vec<u8>,
/// The content type of the thumbnail.
#[ruma_api(header = CONTENT_TYPE)]
pub content_type: Option<String>,
}
impl Request {
/// Creates a new `Request` with the given media ID, server name, desired thumbnail width
/// and desired thumbnail height.
pub fn new(
media_id: String,
server_name: OwnedServerName,
width: UInt,
height: UInt,
) -> Self {
Self {
media_id,
server_name,
method: None,
width,
height,
timeout_ms: crate::media::default_download_timeout(),
#[cfg(feature = "unstable-msc2705")]
animated: false,
}
}
/// Creates a new `Request` with the given URI, desired thumbnail width and
/// desired thumbnail height.
pub fn from_uri(uri: &MxcUri, width: UInt, height: UInt) -> Result<Self, IdParseError> {
let (server_name, media_id) = uri.parts()?;
Ok(Self::new(media_id.to_owned(), server_name.to_owned(), width, height))
}
}
impl Response {
/// Creates a new `Response` with the given thumbnail.
pub fn new(file: Vec<u8>) -> Self {
Self { file, content_type: None }
}
}
}

View File

@ -0,0 +1,51 @@
//! `GET /_matrix/client/*/media/config`
//!
//! Gets the config for the media repository.
pub mod unstable {
//! `/unstable/org.matrix.msc3916/` ([MSC])
//!
//! [MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/3916
use js_int::UInt;
use ruma_common::{
api::{request, response, Metadata},
metadata,
};
const METADATA: Metadata = metadata! {
method: GET,
rate_limited: true,
authentication: AccessToken,
history: {
unstable => "/_matrix/client/unstable/org.matrix.msc3916/media/config",
}
};
/// Request type for the `get_media_config` endpoint.
#[request(error = crate::Error)]
#[derive(Default)]
pub struct Request {}
/// Response type for the `get_media_config` endpoint.
#[response(error = crate::Error)]
pub struct Response {
/// Maximum size of upload in bytes.
#[serde(rename = "m.upload.size")]
pub upload_size: UInt,
}
impl Request {
/// Creates an empty `Request`.
pub fn new() -> Self {
Self {}
}
}
impl Response {
/// Creates a new `Response` with the given maximum upload size.
pub fn new(upload_size: UInt) -> Self {
Self { upload_size }
}
}
}

View File

@ -0,0 +1,105 @@
//! `GET /_matrix/client/*/media/preview_url`
//!
//! Get a preview for a URL.
pub mod unstable {
//! `/unstable/org.matrix.msc3916/` ([MSC])
//!
//! [MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/3916
use ruma_common::{
api::{request, response, Metadata},
metadata, MilliSecondsSinceUnixEpoch,
};
use serde::Serialize;
use serde_json::value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue};
const METADATA: Metadata = metadata! {
method: GET,
rate_limited: true,
authentication: AccessToken,
history: {
unstable => "/_matrix/client/unstable/org.matrix.msc3916/media/preview_url",
}
};
/// Request type for the `get_media_preview` endpoint.
#[request(error = crate::Error)]
pub struct Request {
/// URL to get a preview of.
#[ruma_api(query)]
pub url: String,
/// Preferred point in time (in milliseconds) to return a preview for.
#[ruma_api(query)]
#[serde(skip_serializing_if = "Option::is_none")]
pub ts: Option<MilliSecondsSinceUnixEpoch>,
}
/// Response type for the `get_media_preview` endpoint.
#[response(error = crate::Error)]
#[derive(Default)]
pub struct Response {
/// OpenGraph-like data for the URL.
///
/// Differences from OpenGraph: the image size in bytes is added to the `matrix:image:size`
/// field, and `og:image` returns the MXC URI to the image, if any.
#[ruma_api(body)]
pub data: Option<Box<RawJsonValue>>,
}
impl Request {
/// Creates a new `Request` with the given URL.
pub fn new(url: String) -> Self {
Self { url, ts: None }
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Self { data: None }
}
/// Creates a new `Response` with the given OpenGraph data (in a
/// `serde_json::value::RawValue`).
pub fn from_raw_value(data: Box<RawJsonValue>) -> Self {
Self { data: Some(data) }
}
/// Creates a new `Response` with the given OpenGraph data (in any kind of serializable
/// object).
pub fn from_serialize<T: Serialize>(data: &T) -> serde_json::Result<Self> {
Ok(Self { data: Some(to_raw_json_value(data)?) })
}
}
#[cfg(test)]
mod tests {
use assert_matches2::assert_matches;
use serde_json::{
from_value as from_json_value, json,
value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue},
};
// Since BTreeMap<String, Box<RawJsonValue>> deserialization doesn't seem to
// work, test that Option<RawJsonValue> works
#[test]
fn raw_json_deserialize() {
type OptRawJson = Option<Box<RawJsonValue>>;
assert_matches!(from_json_value::<OptRawJson>(json!(null)).unwrap(), None);
from_json_value::<OptRawJson>(json!("test")).unwrap().unwrap();
from_json_value::<OptRawJson>(json!({ "a": "b" })).unwrap().unwrap();
}
// For completeness sake, make sure serialization works too
#[test]
fn raw_json_serialize() {
to_raw_json_value(&json!(null)).unwrap();
to_raw_json_value(&json!("string")).unwrap();
to_raw_json_value(&json!({})).unwrap();
to_raw_json_value(&json!({ "a": "b" })).unwrap();
}
}
}

View File

@ -12,6 +12,8 @@
pub mod account; pub mod account;
pub mod alias; pub mod alias;
pub mod appservice; pub mod appservice;
#[cfg(feature = "unstable-msc3916")]
pub mod authenticated_media;
pub mod backup; pub mod backup;
pub mod config; pub mod config;
pub mod context; pub mod context;

View File

@ -12,12 +12,12 @@ pub mod get_media_config;
pub mod get_media_preview; pub mod get_media_preview;
/// The default duration that the client should be willing to wait to start receiving data. /// The default duration that the client should be willing to wait to start receiving data.
fn default_download_timeout() -> Duration { pub(crate) fn default_download_timeout() -> Duration {
Duration::from_secs(20) Duration::from_secs(20)
} }
/// Whether the given duration is the default duration that the client should be willing to wait to /// Whether the given duration is the default duration that the client should be willing to wait to
/// start receiving data. /// start receiving data.
fn is_default_download_timeout(timeout: &Duration) -> bool { pub(crate) fn is_default_download_timeout(timeout: &Duration) -> bool {
timeout.as_secs() == 20 timeout.as_secs() == 20
} }

View File

@ -1,4 +1,4 @@
//! `POST /_matrix/media/*/upload/{serverName}/{mediaId}` //! `PUT /_matrix/media/*/upload/{serverName}/{mediaId}`
//! //!
//! Upload media to an MXC URI that was created with create_mxc_uri. //! Upload media to an MXC URI that was created with create_mxc_uri.

View File

@ -10,7 +10,7 @@ use ruma_common::{
metadata, metadata,
presence::PresenceState, presence::PresenceState,
serde::Raw, serde::Raw,
DeviceKeyAlgorithm, OwnedEventId, OwnedRoomId, DeviceKeyAlgorithm, OwnedEventId, OwnedRoomId, OwnedUserId,
}; };
use ruma_events::{ use ruma_events::{
presence::PresenceEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, presence::PresenceEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent,
@ -470,7 +470,7 @@ pub struct RoomSummary {
/// ///
/// Required if room name or canonical aliases are not set or empty. /// Required if room name or canonical aliases are not set or empty.
#[serde(rename = "m.heroes", default, skip_serializing_if = "Vec::is_empty")] #[serde(rename = "m.heroes", default, skip_serializing_if = "Vec::is_empty")]
pub heroes: Vec<String>, pub heroes: Vec<OwnedUserId>,
/// Number of users whose membership status is `join`. /// Number of users whose membership status is `join`.
/// Required if field has changed since last sync; otherwise, it may be /// Required if field has changed since last sync; otherwise, it may be

View File

@ -12,7 +12,7 @@ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
metadata, metadata,
serde::{deserialize_cow_str, duration::opt_ms, Raw}, serde::{deserialize_cow_str, duration::opt_ms, Raw},
DeviceKeyAlgorithm, MilliSecondsSinceUnixEpoch, OwnedMxcUri, OwnedRoomId, RoomId, DeviceKeyAlgorithm, MilliSecondsSinceUnixEpoch, OwnedMxcUri, OwnedRoomId, OwnedUserId, RoomId,
}; };
use ruma_events::{ use ruma_events::{
receipt::SyncReceiptEvent, typing::SyncTypingEvent, AnyGlobalAccountDataEvent, receipt::SyncReceiptEvent, typing::SyncTypingEvent, AnyGlobalAccountDataEvent,
@ -294,10 +294,17 @@ pub struct SyncRequestList {
#[serde(flatten)] #[serde(flatten)]
pub room_details: RoomDetailsConfig, pub room_details: RoomDetailsConfig,
/// If tombstoned rooms should be returned and if so, with what information attached /// If tombstoned rooms should be returned and if so, with what information attached.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub include_old_rooms: Option<IncludeOldRooms>, pub include_old_rooms: Option<IncludeOldRooms>,
/// Request a stripped variant of membership events for the users used to calculate the room
/// name.
///
/// Sticky.
#[serde(skip_serializing_if = "Option::is_none")]
pub include_heroes: Option<bool>,
/// Filters to apply to the list before sorting. Sticky. /// Filters to apply to the list before sorting. Sticky.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub filters: Option<SyncRequestListFilters>, pub filters: Option<SyncRequestListFilters>,
@ -362,6 +369,10 @@ pub struct RoomSubscription {
/// The maximum number of timeline events to return per room. Sticky. /// The maximum number of timeline events to return per room. Sticky.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub timeline_limit: Option<UInt>, pub timeline_limit: Option<UInt>,
/// Include the room heroes. Sticky.
#[serde(skip_serializing_if = "Option::is_none")]
pub include_heroes: Option<bool>,
} }
/// Operation applied to the specific SlidingSyncList /// Operation applied to the specific SlidingSyncList
@ -479,6 +490,10 @@ pub struct SlidingSyncRoom {
/// relying on the latest event. /// relying on the latest event.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub timestamp: Option<MilliSecondsSinceUnixEpoch>, pub timestamp: Option<MilliSecondsSinceUnixEpoch>,
/// Heroes of the room, if requested by a room subscription.
#[serde(skip_serializing_if = "Option::is_none")]
pub heroes: Option<Vec<SlidingSyncRoomHero>>,
} }
impl SlidingSyncRoom { impl SlidingSyncRoom {
@ -488,6 +503,29 @@ impl SlidingSyncRoom {
} }
} }
/// A sliding sync room hero.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct SlidingSyncRoomHero {
/// The user ID of the hero.
pub user_id: OwnedUserId,
/// The name of the hero.
#[serde(rename = "displayname", skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
/// The avatar of the hero.
#[serde(rename = "avatar_url", skip_serializing_if = "Option::is_none")]
pub avatar: Option<OwnedMxcUri>,
}
impl SlidingSyncRoomHero {
/// Creates a new `SlidingSyncRoomHero` with the given user id.
pub fn new(user_id: OwnedUserId) -> Self {
Self { user_id, name: None, avatar: None }
}
}
/// Sliding-Sync extension configuration. /// Sliding-Sync extension configuration.
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)] #[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]

View File

@ -9,7 +9,7 @@ use ruma_common::{
api::{error::IntoHttpError, EndpointError, OutgoingResponse}, api::{error::IntoHttpError, EndpointError, OutgoingResponse},
serde::{from_raw_json_value, JsonObject, StringEnum}, serde::{from_raw_json_value, JsonObject, StringEnum},
thirdparty::Medium, thirdparty::Medium,
ClientSecret, OwnedSessionId, OwnedUserId, OwnedClientSecret, OwnedSessionId, OwnedUserId,
}; };
use serde::{ use serde::{
de::{self, DeserializeOwned}, de::{self, DeserializeOwned},
@ -555,7 +555,7 @@ pub struct ThirdpartyIdCredentials {
pub sid: OwnedSessionId, pub sid: OwnedSessionId,
/// Identity server client secret. /// Identity server client secret.
pub client_secret: Box<ClientSecret>, pub client_secret: OwnedClientSecret,
/// Identity server URL. /// Identity server URL.
pub id_server: String, pub id_server: String,
@ -569,7 +569,7 @@ impl ThirdpartyIdCredentials {
/// server address and access token. /// server address and access token.
pub fn new( pub fn new(
sid: OwnedSessionId, sid: OwnedSessionId,
client_secret: Box<ClientSecret>, client_secret: OwnedClientSecret,
id_server: String, id_server: String,
id_access_token: String, id_access_token: String,
) -> Self { ) -> Self {

View File

@ -13,7 +13,6 @@ rust-version = { workspace = true }
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[features] [features]
client-api = ["dep:as_variant", "dep:ruma-client-api"] client-api = ["dep:as_variant", "dep:ruma-client-api"]

View File

@ -3,8 +3,6 @@ use std::{env, process};
fn main() { fn main() {
// Prevent unnecessary rerunning of this build script // Prevent unnecessary rerunning of this build script
println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=build.rs");
// Prevent nightly CI from erroring on docsrs attributes
println!("cargo:rustc-check-cfg=cfg(docsrs)");
let tls_features = [ let tls_features = [
("tls-native", env::var_os("CARGO_FEATURE_TLS_NATIVE").is_some()), ("tls-native", env::var_os("CARGO_FEATURE_TLS_NATIVE").is_some()),

View File

@ -12,7 +12,6 @@ rust-version = { workspace = true }
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[features] [features]
# These feature gates exist only for the tests. Disabling them results in a # These feature gates exist only for the tests. Disabling them results in a

View File

@ -1,6 +0,0 @@
fn main() {
// Prevent unnecessary rerunning of this build script
println!("cargo:rerun-if-changed=build.rs");
// Prevent nightly CI from erroring on docsrs attributes
println!("cargo:rustc-check-cfg=cfg(docsrs)");
}

View File

@ -1,5 +1,13 @@
# [unreleased] # [unreleased]
Improvements:
- Add support for encrypted stickers as sent by several bridges under the flag `compat-encrypted-stickers`
Breaking changes:
- `StickerEventContent::url` was replaced by `StickerEventContent::source` which is a `StickerMediaSource`
# 0.28.1 # 0.28.1
Improvements: Improvements:

View File

@ -12,7 +12,6 @@ rust-version = { workspace = true }
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[features] [features]
canonical-json = ["ruma-common/canonical-json"] canonical-json = ["ruma-common/canonical-json"]
@ -56,6 +55,10 @@ compat-optional = []
# Allow TagInfo to contain a stringified floating-point value for the `order` field. # Allow TagInfo to contain a stringified floating-point value for the `order` field.
compat-tag-info = [] compat-tag-info = []
# Support encrypted stickers, as sent by several bridges.
# https://github.com/matrix-org/matrix-spec/issues/1667
compat-encrypted-stickers = []
[dependencies] [dependencies]
as_variant = { workspace = true } as_variant = { workspace = true }
indexmap = { version = "2.0.0", features = ["serde"] } indexmap = { version = "2.0.0", features = ["serde"] }

View File

@ -4,9 +4,77 @@
use ruma_common::OwnedMxcUri; use ruma_common::OwnedMxcUri;
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{de, Deserialize, Serialize};
use crate::room::ImageInfo; #[cfg(feature = "compat-encrypted-stickers")]
use crate::room::EncryptedFile;
use crate::room::{ImageInfo, MediaSource};
/// The source of a sticker media file.
#[derive(Clone, Debug, Serialize)]
#[non_exhaustive]
pub enum StickerMediaSource {
/// The MXC URI to the unencrypted media file.
#[serde(rename = "url")]
Plain(OwnedMxcUri),
/// The encryption info of the encrypted media file.
#[cfg(feature = "compat-encrypted-stickers")]
#[serde(rename = "file")]
Encrypted(Box<EncryptedFile>),
}
// Custom implementation of `Deserialize`, because serde doesn't guarantee what variant will be
// deserialized for "externally tagged"¹ enums where multiple "tag" fields exist.
//
// ¹ https://serde.rs/enum-representations.html
impl<'de> Deserialize<'de> for StickerMediaSource {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(Deserialize)]
struct StickerMediaSourceJsonRepr {
url: Option<OwnedMxcUri>,
#[cfg(feature = "compat-encrypted-stickers")]
file: Option<Box<EncryptedFile>>,
}
match StickerMediaSourceJsonRepr::deserialize(deserializer)? {
StickerMediaSourceJsonRepr {
url: None,
#[cfg(feature = "compat-encrypted-stickers")]
file: None,
} => Err(de::Error::missing_field("url")),
// Prefer file if it is set
#[cfg(feature = "compat-encrypted-stickers")]
StickerMediaSourceJsonRepr { file: Some(file), .. } => {
Ok(StickerMediaSource::Encrypted(file))
}
StickerMediaSourceJsonRepr { url: Some(url), .. } => Ok(StickerMediaSource::Plain(url)),
}
}
}
impl From<StickerMediaSource> for MediaSource {
fn from(value: StickerMediaSource) -> Self {
match value {
StickerMediaSource::Plain(url) => MediaSource::Plain(url),
#[cfg(feature = "compat-encrypted-stickers")]
StickerMediaSource::Encrypted(file) => MediaSource::Encrypted(file),
}
}
}
#[cfg(feature = "compat-encrypted-stickers")]
impl From<MediaSource> for StickerMediaSource {
fn from(value: MediaSource) -> Self {
match value {
MediaSource::Plain(url) => StickerMediaSource::Plain(url),
MediaSource::Encrypted(file) => StickerMediaSource::Encrypted(file),
}
}
}
/// The content of an `m.sticker` event. /// The content of an `m.sticker` event.
/// ///
@ -24,13 +92,19 @@ pub struct StickerEventContent {
/// Metadata about the image referred to in `url` including a thumbnail representation. /// Metadata about the image referred to in `url` including a thumbnail representation.
pub info: ImageInfo, pub info: ImageInfo,
/// The URL to the sticker image. /// The media source of the sticker image.
pub url: OwnedMxcUri, #[serde(flatten)]
pub source: StickerMediaSource,
} }
impl StickerEventContent { impl StickerEventContent {
/// Creates a new `StickerEventContent` with the given body, image info and URL. /// Creates a new `StickerEventContent` with the given body, image info and URL.
pub fn new(body: String, info: ImageInfo, url: OwnedMxcUri) -> Self { pub fn new(body: String, info: ImageInfo, url: OwnedMxcUri) -> Self {
Self { body, info, url } Self { body, info, source: StickerMediaSource::Plain(url.clone()) }
}
/// Creates a new `StickerEventContent` with the given body, image info, URL, and media source.
pub fn with_source(body: String, info: ImageInfo, source: StickerMediaSource) -> Self {
Self { body, info, source }
} }
} }

View File

@ -4,7 +4,7 @@ use js_int::{uint, UInt};
use ruma_common::{mxc_uri, serde::CanBeEmpty, MilliSecondsSinceUnixEpoch}; use ruma_common::{mxc_uri, serde::CanBeEmpty, MilliSecondsSinceUnixEpoch};
use ruma_events::{ use ruma_events::{
room::{ImageInfo, MediaSource, ThumbnailInfo}, room::{ImageInfo, MediaSource, ThumbnailInfo},
sticker::StickerEventContent, sticker::{StickerEventContent, StickerMediaSource},
AnyMessageLikeEvent, MessageLikeEvent, AnyMessageLikeEvent, MessageLikeEvent,
}; };
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
@ -79,7 +79,44 @@ fn content_deserialization() {
let content = from_json_value::<StickerEventContent>(json_data).unwrap(); let content = from_json_value::<StickerEventContent>(json_data).unwrap();
assert_eq!(content.body, "Upload: my_image.jpg"); assert_eq!(content.body, "Upload: my_image.jpg");
assert_eq!(content.url, "mxc://notareal.hs/file"); assert_matches!(content.source, StickerMediaSource::Plain(sticker_url));
assert_eq!(sticker_url, "mxc://notareal.hs/file");
let encrypted_json_data = json!({
"body": "Upload: my_image.jpg",
"file": {
"url": "mxc://notareal.hs/file",
"key": {
"kty": "oct",
"key_ops": ["encrypt", "decrypt"],
"alg": "A256CTR",
"k": "TLlG_OpX807zzQuuwv4QZGJ21_u7weemFGYJFszMn9A",
"ext": true
},
"iv": "S22dq3NAX8wAAAAAAAAAAA",
"hashes": {
"sha256": "aWOHudBnDkJ9IwaR1Nd8XKoI7DOrqDTwt6xDPfVGN6Q"
},
"v": "v2",
},
"info": {},
});
#[cfg(not(feature = "compat-encrypted-stickers"))]
{
from_json_value::<StickerEventContent>(encrypted_json_data).unwrap_err();
}
#[cfg(feature = "compat-encrypted-stickers")]
{
let encrypted_content =
from_json_value::<StickerEventContent>(encrypted_json_data).unwrap();
assert_eq!(encrypted_content.body, "Upload: my_image.jpg");
assert_matches!(
encrypted_content.source,
StickerMediaSource::Encrypted(encrypted_sticker_url)
);
assert_eq!(encrypted_sticker_url.url, "mxc://notareal.hs/file");
}
} }
#[test] #[test]
@ -126,7 +163,8 @@ fn event_deserialization() {
assert_eq!(content.info.width, Some(uint!(1011))); assert_eq!(content.info.width, Some(uint!(1011)));
assert_eq!(content.info.mimetype.as_deref(), Some("image/png")); assert_eq!(content.info.mimetype.as_deref(), Some("image/png"));
assert_eq!(content.info.size, Some(uint!(84242))); assert_eq!(content.info.size, Some(uint!(84242)));
assert_eq!(content.url, "mxc://matrix.org/jxPXTKpyydzdHJkdFNZjTZrD"); assert_matches!(content.source, StickerMediaSource::Plain(sticker_url));
assert_eq!(sticker_url, "mxc://matrix.org/jxPXTKpyydzdHJkdFNZjTZrD");
assert_matches!(content.info.thumbnail_source, Some(MediaSource::Plain(thumbnail_url))); assert_matches!(content.info.thumbnail_source, Some(MediaSource::Plain(thumbnail_url)));
assert_eq!(thumbnail_url, "mxc://matrix.org/irnsNRS2879"); assert_eq!(thumbnail_url, "mxc://matrix.org/irnsNRS2879");

View File

@ -13,7 +13,6 @@ rust-version = { workspace = true }
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[features] [features]
# Allow some mandatory fields in requests / responses to be missing, defaulting # Allow some mandatory fields in requests / responses to be missing, defaulting

View File

@ -1,6 +0,0 @@
fn main() {
// Prevent unnecessary rerunning of this build script
println!("cargo:rerun-if-changed=build.rs");
// Prevent nightly CI from erroring on docsrs attributes
println!("cargo:rustc-check-cfg=cfg(docsrs)");
}

View File

@ -12,7 +12,6 @@ rust-version = { workspace = true }
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[features] [features]
matrix = ["dep:ruma-common"] matrix = ["dep:ruma-common"]

View File

@ -1,6 +0,0 @@
fn main() {
// Prevent unnecessary rerunning of this build script
println!("cargo:rerun-if-changed=build.rs");
// Prevent nightly CI from erroring on docsrs attributes
println!("cargo:rustc-check-cfg=cfg(docsrs)");
}

View File

@ -1,5 +1,10 @@
# [unreleased] # [unreleased]
Breaking changes:
- Change type of `client_secret` field in `ThreePidOwnershipProof`
from `Box<ClientSecret>` to `OwnedClientSecret`
# 0.9.0 # 0.9.0
Breaking changes: Breaking changes:

View File

@ -11,7 +11,7 @@ pub mod v2 {
api::{request, response, Metadata}, api::{request, response, Metadata},
metadata, metadata,
thirdparty::Medium, thirdparty::Medium,
ClientSecret, OwnedSessionId, OwnedUserId, OwnedClientSecret, OwnedSessionId, OwnedUserId,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -96,12 +96,12 @@ pub mod v2 {
pub sid: OwnedSessionId, pub sid: OwnedSessionId,
/// The client secret passed to the `requestToken` call. /// The client secret passed to the `requestToken` call.
pub client_secret: Box<ClientSecret>, pub client_secret: OwnedClientSecret,
} }
impl ThreePidOwnershipProof { impl ThreePidOwnershipProof {
/// Creates a new `ThreePidOwnershipProof` with the given session ID and client secret. /// Creates a new `ThreePidOwnershipProof` with the given session ID and client secret.
pub fn new(sid: OwnedSessionId, client_secret: Box<ClientSecret>) -> Self { pub fn new(sid: OwnedSessionId, client_secret: OwnedClientSecret) -> Self {
Self { sid, client_secret } Self { sid, client_secret }
} }
} }

View File

@ -1,5 +1,10 @@
# [unreleased] # [unreleased]
Breaking changes:
- The `XMatrix::new` method now takes `OwnedServerName` instead of `Option<OwnedServerName>`
for the destination, since servers must always set the destination.
# 0.3.0 # 0.3.0
Breaking changes: Breaking changes:

View File

@ -13,7 +13,6 @@ rust-version = { workspace = true }
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[dependencies] [dependencies]
headers = "0.4.0" headers = "0.4.0"

View File

@ -31,11 +31,11 @@ impl XMatrix {
/// Construct a new X-Matrix Authorization header. /// Construct a new X-Matrix Authorization header.
pub fn new( pub fn new(
origin: OwnedServerName, origin: OwnedServerName,
destination: Option<OwnedServerName>, destination: OwnedServerName,
key: OwnedServerSigningKeyId, key: OwnedServerSigningKeyId,
sig: String, sig: String,
) -> Self { ) -> Self {
Self { origin, destination, key, sig } Self { origin, destination: Some(destination), key, sig }
} }
} }
@ -259,7 +259,7 @@ mod tests {
assert_eq!(credentials.key, key); assert_eq!(credentials.key, key);
assert_eq!(credentials.sig, sig); assert_eq!(credentials.sig, sig);
let credentials = XMatrix::new(origin, None, key, sig); let credentials = XMatrix { origin, destination: None, key, sig };
assert_eq!(credentials.encode(), header); assert_eq!(credentials.encode(), header);
} }
@ -277,7 +277,7 @@ mod tests {
assert_eq!(credentials.key, key); assert_eq!(credentials.key, key);
assert_eq!(credentials.sig, sig); assert_eq!(credentials.sig, sig);
let credentials = XMatrix::new(origin, Some(destination), key, sig); let credentials = XMatrix::new(origin, destination, key, sig);
assert_eq!(credentials.encode(), header); assert_eq!(credentials.encode(), header);
} }

View File

@ -13,7 +13,6 @@ rust-version = { workspace = true }
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[features] [features]
api = ["ruma-common/api"] api = ["ruma-common/api"]
@ -191,6 +190,10 @@ compat-signature-id = ["ruma-signatures?/compat-signature-id"]
# Allow TagInfo to contain a stringified floating-point value for the `order` field. # Allow TagInfo to contain a stringified floating-point value for the `order` field.
compat-tag-info = ["ruma-events?/compat-tag-info"] compat-tag-info = ["ruma-events?/compat-tag-info"]
# Support encrypted stickers, as sent by several bridges.
# https://github.com/matrix-org/matrix-spec/issues/1667
compat-encrypted-stickers = ["ruma-events?/compat-encrypted-stickers"]
# Specific compatibility for past ring public/private key documents. # Specific compatibility for past ring public/private key documents.
ring-compat = ["dep:ruma-signatures", "ruma-signatures?/ring-compat"] ring-compat = ["dep:ruma-signatures", "ruma-signatures?/ring-compat"]
@ -255,6 +258,7 @@ unstable-msc3618 = ["ruma-federation-api?/unstable-msc3618"]
unstable-msc3723 = ["ruma-federation-api?/unstable-msc3723"] unstable-msc3723 = ["ruma-federation-api?/unstable-msc3723"]
unstable-msc3814 = ["ruma-client-api?/unstable-msc3814"] unstable-msc3814 = ["ruma-client-api?/unstable-msc3814"]
unstable-msc3843 = ["ruma-client-api?/unstable-msc3843", "ruma-federation-api?/unstable-msc3843"] unstable-msc3843 = ["ruma-client-api?/unstable-msc3843", "ruma-federation-api?/unstable-msc3843"]
unstable-msc3916 = ["ruma-client-api?/unstable-msc3916"]
unstable-msc3927 = ["ruma-events?/unstable-msc3927"] unstable-msc3927 = ["ruma-events?/unstable-msc3927"]
unstable-msc3930 = ["ruma-common/unstable-msc3930"] unstable-msc3930 = ["ruma-common/unstable-msc3930"]
unstable-msc3931 = ["ruma-common/unstable-msc3931"] unstable-msc3931 = ["ruma-common/unstable-msc3931"]
@ -309,6 +313,7 @@ __ci = [
"unstable-msc3723", "unstable-msc3723",
"unstable-msc3814", "unstable-msc3814",
"unstable-msc3843", "unstable-msc3843",
"unstable-msc3916",
"unstable-msc3927", "unstable-msc3927",
"unstable-msc3930", "unstable-msc3930",
"unstable-msc3931", "unstable-msc3931",

View File

@ -1,6 +0,0 @@
fn main() {
// Prevent unnecessary rerunning of this build script
println!("cargo:rerun-if-changed=build.rs");
// Prevent nightly CI from erroring on docsrs attributes
println!("cargo:rustc-check-cfg=cfg(docsrs)");
}

View File

@ -46,6 +46,8 @@ pub enum CiCmd {
StableCommon, StableCommon,
/// Run all tests with almost all features (stable) /// Run all tests with almost all features (stable)
TestAll, TestAll,
/// Run all tests with almost all features, including the compat features (stable)
TestCompat,
/// Run doc tests with almost all features (stable) /// Run doc tests with almost all features (stable)
TestDoc, TestDoc,
/// Run all the tasks that use the nightly version /// Run all the tasks that use the nightly version
@ -108,6 +110,7 @@ impl CiTask {
Some(CiCmd::StableClient) => self.stable_client()?, Some(CiCmd::StableClient) => self.stable_client()?,
Some(CiCmd::StableCommon) => self.stable_common()?, Some(CiCmd::StableCommon) => self.stable_common()?,
Some(CiCmd::TestAll) => self.test_all()?, Some(CiCmd::TestAll) => self.test_all()?,
Some(CiCmd::TestCompat) => self.test_compat()?,
Some(CiCmd::TestDoc) => self.test_doc()?, Some(CiCmd::TestDoc) => self.test_doc()?,
Some(CiCmd::Nightly) => self.nightly()?, Some(CiCmd::Nightly) => self.nightly()?,
Some(CiCmd::Fmt) => self.fmt()?, Some(CiCmd::Fmt) => self.fmt()?,
@ -207,6 +210,14 @@ impl CiTask {
cmd!("rustup run stable cargo test --tests --features __ci").run().map_err(Into::into) cmd!("rustup run stable cargo test --tests --features __ci").run().map_err(Into::into)
} }
/// Run tests on all crates with almost all features and the compat features with the stable
/// version.
fn test_compat(&self) -> Result<()> {
cmd!("rustup run stable cargo test --tests --features __ci,compat")
.run()
.map_err(Into::into)
}
/// Run doctests on all crates with almost all features with the stable version. /// Run doctests on all crates with almost all features with the stable version.
fn test_doc(&self) -> Result<()> { fn test_doc(&self) -> Result<()> {
cmd!("rustup run stable cargo test --doc --features __ci").run().map_err(Into::into) cmd!("rustup run stable cargo test --doc --features __ci").run().map_err(Into::into)