identifiers: Make UserId a DST
This commit is contained in:
parent
313124a099
commit
3ce578f384
@ -298,11 +298,10 @@ pub trait OutgoingRequestAppserviceExt: OutgoingRequest {
|
||||
self,
|
||||
base_url: &str,
|
||||
access_token: SendAccessToken<'_>,
|
||||
user_id: UserId,
|
||||
user_id: &UserId,
|
||||
) -> Result<http::Request<T>, IntoHttpError> {
|
||||
let mut http_request = self.try_into_http_request(base_url, access_token)?;
|
||||
let user_id_query =
|
||||
ruma_serde::urlencoded::to_string(&[("user_id", &user_id.into_string())])?;
|
||||
let user_id_query = ruma_serde::urlencoded::to_string(&[("user_id", user_id)])?;
|
||||
|
||||
let uri = http_request.uri().to_owned();
|
||||
let mut parts = uri.into_parts();
|
||||
|
@ -27,7 +27,7 @@ ruma_api! {
|
||||
#[ruma_api(path)]
|
||||
pub bar: String,
|
||||
#[ruma_api(path)]
|
||||
pub user: UserId,
|
||||
pub user: Box<UserId>,
|
||||
}
|
||||
|
||||
response: {
|
||||
@ -47,7 +47,7 @@ fn request_serde() {
|
||||
q1: "query_param_special_chars %/&@!".to_owned(),
|
||||
q2: 55,
|
||||
bar: "barVal".to_owned(),
|
||||
user: user_id!("@bazme:ruma.io"),
|
||||
user: user_id!("@bazme:ruma.io").to_owned(),
|
||||
};
|
||||
|
||||
let http_req = req
|
||||
@ -72,7 +72,7 @@ fn invalid_uri_should_not_panic() {
|
||||
q1: "query_param_special_chars %/&@!".to_owned(),
|
||||
q2: 55,
|
||||
bar: "barVal".to_owned(),
|
||||
user: user_id!("@bazme:ruma.io"),
|
||||
user: user_id!("@bazme:ruma.io").to_owned(),
|
||||
};
|
||||
|
||||
let result = req.try_into_http_request::<Vec<u8>>("invalid uri", SendAccessToken::None);
|
||||
@ -87,7 +87,7 @@ fn request_with_user_id_serde() {
|
||||
q1: "query_param_special_chars %/&@!".to_owned(),
|
||||
q2: 55,
|
||||
bar: "barVal".to_owned(),
|
||||
user: user_id!("@bazme:ruma.io"),
|
||||
user: user_id!("@bazme:ruma.io").to_owned(),
|
||||
};
|
||||
|
||||
let user_id = user_id!("@_virtual_:ruma.io");
|
||||
@ -127,7 +127,7 @@ mod without_query {
|
||||
#[ruma_api(path)]
|
||||
pub bar: String,
|
||||
#[ruma_api(path)]
|
||||
pub user: UserId,
|
||||
pub user: Box<UserId>,
|
||||
}
|
||||
|
||||
response: {
|
||||
@ -145,7 +145,7 @@ mod without_query {
|
||||
hello: "hi".to_owned(),
|
||||
world: "test".to_owned(),
|
||||
bar: "barVal".to_owned(),
|
||||
user: user_id!("@bazme:ruma.io"),
|
||||
user: user_id!("@bazme:ruma.io").to_owned(),
|
||||
};
|
||||
|
||||
let user_id = user_id!("@_virtual_:ruma.io");
|
||||
|
@ -39,7 +39,7 @@ pub mod some_endpoint {
|
||||
// This value will be inserted into the request's URL in place of the
|
||||
// ":user" path component.
|
||||
#[ruma_api(path)]
|
||||
pub user: UserId,
|
||||
pub user: Box<UserId>,
|
||||
}
|
||||
|
||||
response: {
|
||||
|
@ -26,7 +26,7 @@ mod newtype_body {
|
||||
pub bar: String,
|
||||
|
||||
#[ruma_api(query)]
|
||||
pub baz: UserId,
|
||||
pub baz: Box<UserId>,
|
||||
|
||||
#[ruma_api(header = CONTENT_TYPE)]
|
||||
pub world: String,
|
||||
@ -64,7 +64,7 @@ mod raw_body {
|
||||
pub bar: String,
|
||||
|
||||
#[ruma_api(query)]
|
||||
pub baz: UserId,
|
||||
pub baz: Box<UserId>,
|
||||
|
||||
#[ruma_api(header = CONTENT_TYPE)]
|
||||
pub world: String,
|
||||
@ -103,7 +103,7 @@ mod plain {
|
||||
pub bar: String,
|
||||
|
||||
#[ruma_api(query)]
|
||||
pub baz: UserId,
|
||||
pub baz: Box<UserId>,
|
||||
|
||||
#[ruma_api(header = CONTENT_TYPE)]
|
||||
pub world: String,
|
||||
|
@ -83,7 +83,7 @@ ruma_api! {
|
||||
pub access_token: Option<String>,
|
||||
|
||||
/// The fully-qualified Matrix ID that has been registered.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
|
||||
/// ID of the registered device.
|
||||
///
|
||||
@ -103,7 +103,7 @@ impl Request<'_> {
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given user ID.
|
||||
pub fn new(user_id: UserId) -> Self {
|
||||
pub fn new(user_id: Box<UserId>) -> Self {
|
||||
Self { access_token: None, user_id, device_id: None }
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ ruma_api! {
|
||||
|
||||
response: {
|
||||
/// The id of the user that owns the access token.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
@ -33,7 +33,7 @@ impl Request {
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given user ID.
|
||||
pub fn new(user_id: UserId) -> Self {
|
||||
pub fn new(user_id: Box<UserId>) -> Self {
|
||||
Self { user_id }
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ pub enum BackupAlgorithm {
|
||||
public_key: String,
|
||||
|
||||
/// Signatures of the auth_data as Signed JSON.
|
||||
signatures: BTreeMap<UserId, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
signatures: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -80,13 +80,13 @@ pub struct RoomEventFilter<'a> {
|
||||
/// If this list is absent then no senders are excluded. A matching sender will be excluded
|
||||
/// even if it is listed in the 'senders' filter.
|
||||
#[serde(default, skip_serializing_if = "<[_]>::is_empty")]
|
||||
pub not_senders: &'a [UserId],
|
||||
pub not_senders: &'a [Box<UserId>],
|
||||
|
||||
/// A list of senders IDs to include.
|
||||
///
|
||||
/// If this list is absent then all senders are included.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub senders: Option<&'a [UserId]>,
|
||||
pub senders: Option<&'a [Box<UserId>]>,
|
||||
|
||||
/// A list of event types to include.
|
||||
///
|
||||
@ -255,7 +255,7 @@ pub struct Filter<'a> {
|
||||
///
|
||||
/// If this list is absent then all senders are included.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub senders: Option<&'a [UserId]>,
|
||||
pub senders: Option<&'a [Box<UserId>]>,
|
||||
|
||||
/// A list of event types to include.
|
||||
///
|
||||
@ -269,7 +269,7 @@ pub struct Filter<'a> {
|
||||
/// If this list is absent then no senders are excluded. A matching sender will be excluded
|
||||
/// even if it is listed in the 'senders' filter.
|
||||
#[serde(default, skip_serializing_if = "<[_]>::is_empty")]
|
||||
pub not_senders: &'a [UserId],
|
||||
pub not_senders: &'a [Box<UserId>],
|
||||
}
|
||||
|
||||
impl<'a> Filter<'a> {
|
||||
|
@ -82,7 +82,7 @@ mod tests {
|
||||
use crate::r0::filter::FilterDefinition;
|
||||
|
||||
assert_matches!(
|
||||
super::Request::new(&user_id!("@foo:bar.com"), FilterDefinition::default())
|
||||
super::Request::new(user_id!("@foo:bar.com"), FilterDefinition::default())
|
||||
.try_into_http_request::<Vec<u8>>(
|
||||
"https://matrix.org",
|
||||
SendAccessToken::IfRequired("tok"),
|
||||
|
@ -28,7 +28,7 @@ ruma_api! {
|
||||
pub timeout: Option<Duration>,
|
||||
|
||||
/// The keys to be claimed.
|
||||
pub one_time_keys: BTreeMap<UserId, BTreeMap<Box<DeviceId>, DeviceKeyAlgorithm>>,
|
||||
pub one_time_keys: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, DeviceKeyAlgorithm>>,
|
||||
}
|
||||
|
||||
response: {
|
||||
@ -37,7 +37,7 @@ ruma_api! {
|
||||
pub failures: BTreeMap<String, JsonValue>,
|
||||
|
||||
/// One-time keys for the queried devices.
|
||||
pub one_time_keys: BTreeMap<UserId, OneTimeKeys>,
|
||||
pub one_time_keys: BTreeMap<Box<UserId>, OneTimeKeys>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
@ -46,7 +46,7 @@ ruma_api! {
|
||||
impl Request {
|
||||
/// Creates a new `Request` with the given key claims and the recommended 10 second timeout.
|
||||
pub fn new(
|
||||
one_time_keys: BTreeMap<UserId, BTreeMap<Box<DeviceId>, DeviceKeyAlgorithm>>,
|
||||
one_time_keys: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, DeviceKeyAlgorithm>>,
|
||||
) -> Self {
|
||||
Self { timeout: Some(Duration::from_secs(10)), one_time_keys }
|
||||
}
|
||||
@ -54,7 +54,7 @@ impl Request {
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given keys and no failures.
|
||||
pub fn new(one_time_keys: BTreeMap<UserId, OneTimeKeys>) -> Self {
|
||||
pub fn new(one_time_keys: BTreeMap<Box<UserId>, OneTimeKeys>) -> Self {
|
||||
Self { failures: BTreeMap::new(), one_time_keys }
|
||||
}
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ ruma_api! {
|
||||
|
||||
response: {
|
||||
/// The Matrix User IDs of all users who updated their device identity keys.
|
||||
pub changed: Vec<UserId>,
|
||||
pub changed: Vec<Box<UserId>>,
|
||||
|
||||
/// The Matrix User IDs of all users who may have left all the end-to-end
|
||||
/// encrypted rooms they previously shared with the user.
|
||||
pub left: Vec<UserId>,
|
||||
pub left: Vec<Box<UserId>>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
@ -49,7 +49,7 @@ impl<'a> Request<'a> {
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given changed and left user ID lists.
|
||||
pub fn new(changed: Vec<UserId>, left: Vec<UserId>) -> Self {
|
||||
pub fn new(changed: Vec<Box<UserId>>, left: Vec<Box<UserId>>) -> Self {
|
||||
Self { changed, left }
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ ruma_api! {
|
||||
/// The keys to be downloaded.
|
||||
///
|
||||
/// An empty list indicates all devices for the corresponding user.
|
||||
pub device_keys: BTreeMap<UserId, Vec<Box<DeviceId>>>,
|
||||
pub device_keys: BTreeMap<Box<UserId>, Vec<Box<DeviceId>>>,
|
||||
|
||||
/// If the client is fetching keys as a result of a device update received in a sync
|
||||
/// request, this should be the 'since' token of that sync request, or any later sync token.
|
||||
@ -56,22 +56,22 @@ ruma_api! {
|
||||
|
||||
/// Information on the queried devices.
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub device_keys: BTreeMap<UserId, BTreeMap<Box<DeviceId>, DeviceKeys>>,
|
||||
pub device_keys: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, DeviceKeys>>,
|
||||
|
||||
/// Information on the master cross-signing keys of the queried users.
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub master_keys: BTreeMap<UserId, CrossSigningKey>,
|
||||
pub master_keys: BTreeMap<Box<UserId>, CrossSigningKey>,
|
||||
|
||||
/// Information on the self-signing keys of the queried users.
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub self_signing_keys: BTreeMap<UserId, CrossSigningKey>,
|
||||
pub self_signing_keys: BTreeMap<Box<UserId>, CrossSigningKey>,
|
||||
|
||||
/// Information on the user-signing keys of the queried users.
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub user_signing_keys: BTreeMap<UserId, CrossSigningKey>,
|
||||
pub user_signing_keys: BTreeMap<Box<UserId>, CrossSigningKey>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
|
@ -21,7 +21,7 @@ ruma_api! {
|
||||
request: {
|
||||
/// Signed keys.
|
||||
#[ruma_api(body)]
|
||||
pub signed_keys: BTreeMap<UserId, BTreeMap<String, JsonValue>>,
|
||||
pub signed_keys: BTreeMap<Box<UserId>, BTreeMap<String, JsonValue>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@ -32,7 +32,7 @@ ruma_api! {
|
||||
|
||||
impl Request {
|
||||
/// Creates a new `Request` with the given signed keys.
|
||||
pub fn new(signed_keys: BTreeMap<UserId, BTreeMap<String, JsonValue>>) -> Self {
|
||||
pub fn new(signed_keys: BTreeMap<Box<UserId>, BTreeMap<String, JsonValue>>) -> Self {
|
||||
Self { signed_keys }
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ mod tests {
|
||||
json!({ "user_id": "@carl:example.org" }),
|
||||
)
|
||||
.unwrap();
|
||||
let user_id = user_id!("@carl:example.org");
|
||||
let user_id = user_id!("@carl:example.org").to_owned();
|
||||
let recipient = IncomingInvitationRecipient::UserId { user_id };
|
||||
assert_eq!(incoming, recipient);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ ruma_api! {
|
||||
response: {
|
||||
/// A list of the rooms the user is in, i.e.
|
||||
/// the ID of each room in which the user has joined membership.
|
||||
pub joined: BTreeMap<UserId, RoomMember>,
|
||||
pub joined: BTreeMap<Box<UserId>, RoomMember>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
@ -40,7 +40,7 @@ impl<'a> Request<'a> {
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given joined rooms.
|
||||
pub fn new(joined: BTreeMap<UserId, RoomMember>) -> Self {
|
||||
pub fn new(joined: BTreeMap<Box<UserId>, RoomMember>) -> Self {
|
||||
Self { joined }
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ ruma_api! {
|
||||
///
|
||||
/// This will tell the server to invite everyone in the list to the newly created room.
|
||||
#[serde(default, skip_serializing_if = "<[_]>::is_empty")]
|
||||
pub invite: &'a [UserId],
|
||||
pub invite: &'a [Box<UserId>],
|
||||
|
||||
/// List of third party IDs of users to invite.
|
||||
#[serde(default, skip_serializing_if = "<[_]>::is_empty")]
|
||||
@ -156,7 +156,7 @@ impl CreationContent {
|
||||
/// a `RoomCreateEventContent`.
|
||||
pub fn into_event_content(
|
||||
self,
|
||||
creator: UserId,
|
||||
creator: Box<UserId>,
|
||||
room_version: RoomVersionId,
|
||||
) -> RoomCreateEventContent {
|
||||
#[allow(unused_mut)]
|
||||
|
@ -194,7 +194,7 @@ pub struct EventContextResult {
|
||||
|
||||
/// The historic profile information of the users that sent the events returned.
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub profile_info: BTreeMap<UserId, UserProfile>,
|
||||
pub profile_info: BTreeMap<Box<UserId>, UserProfile>,
|
||||
|
||||
/// Pagination token for the start of the chunk.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -501,5 +501,5 @@ pub enum RoomIdOrUserId {
|
||||
RoomId(Box<RoomId>),
|
||||
|
||||
/// Represents a user ID.
|
||||
UserId(UserId),
|
||||
UserId(Box<UserId>),
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ ruma_api! {
|
||||
response: {
|
||||
/// The Matrix user ID of the user.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub user_id: Option<UserId>,
|
||||
pub user_id: Option<Box<UserId>>,
|
||||
|
||||
/// A map of the user's device identifiers to information about that device.
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
|
@ -39,7 +39,7 @@ ruma_api! {
|
||||
|
||||
response: {
|
||||
/// The fully-qualified Matrix ID that has been registered.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
|
||||
/// An access token for the account.
|
||||
pub access_token: String,
|
||||
@ -76,7 +76,7 @@ impl<'a> Request<'a> {
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given user ID, access token and device ID.
|
||||
pub fn new(user_id: UserId, access_token: String, device_id: Box<DeviceId>) -> Self {
|
||||
pub fn new(user_id: Box<UserId>, access_token: String, device_id: Box<DeviceId>) -> Self {
|
||||
Self { user_id, access_token, home_server: None, device_id, well_known: None }
|
||||
}
|
||||
}
|
||||
|
@ -556,12 +556,12 @@ pub struct DeviceLists {
|
||||
/// List of users who have updated their device identity keys or who now
|
||||
/// share an encrypted room with the client since the previous sync
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub changed: Vec<UserId>,
|
||||
pub changed: Vec<Box<UserId>>,
|
||||
|
||||
/// List of users who no longer share encrypted rooms since the previous sync
|
||||
/// response.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub left: Vec<UserId>,
|
||||
pub left: Vec<Box<UserId>>,
|
||||
}
|
||||
|
||||
impl DeviceLists {
|
||||
|
@ -57,4 +57,5 @@ impl Response {
|
||||
/// Messages to send in a send-to-device request.
|
||||
///
|
||||
/// Represented as a map of `{ user-ids => { device-ids => message-content } }`.
|
||||
pub type Messages = BTreeMap<UserId, BTreeMap<DeviceIdOrAllDevices, Raw<AnyToDeviceEventContent>>>;
|
||||
pub type Messages =
|
||||
BTreeMap<Box<UserId>, BTreeMap<DeviceIdOrAllDevices, Raw<AnyToDeviceEventContent>>>;
|
||||
|
@ -72,7 +72,7 @@ fn is_default_limit(limit: &UInt) -> bool {
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct User {
|
||||
/// The user's matrix user ID.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
|
||||
/// The display name of the user, if one exists.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -92,7 +92,7 @@ pub struct User {
|
||||
|
||||
impl User {
|
||||
/// Create a new `User` with the given `UserId`.
|
||||
pub fn new(user_id: UserId) -> Self {
|
||||
pub fn new(user_id: Box<UserId>) -> Self {
|
||||
Self { user_id, display_name: None, avatar_url: None }
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ pub struct DeviceKeys {
|
||||
/// The ID of the user the device belongs to.
|
||||
///
|
||||
/// Must match the user ID used when logging in.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
|
||||
/// The ID of the device these keys belong to.
|
||||
///
|
||||
@ -28,7 +28,7 @@ pub struct DeviceKeys {
|
||||
pub keys: BTreeMap<Box<DeviceKeyId>, String>,
|
||||
|
||||
/// Signatures for the device key object.
|
||||
pub signatures: BTreeMap<UserId, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
pub signatures: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
|
||||
/// Additional data added to the device key information by intermediate servers, and
|
||||
/// not covered by the signatures.
|
||||
@ -40,11 +40,11 @@ impl DeviceKeys {
|
||||
/// Creates a new `DeviceKeys` from the given user id, device id, algorithms, keys and
|
||||
/// signatures.
|
||||
pub fn new(
|
||||
user_id: UserId,
|
||||
user_id: Box<UserId>,
|
||||
device_id: Box<DeviceId>,
|
||||
algorithms: Vec<EventEncryptionAlgorithm>,
|
||||
keys: BTreeMap<Box<DeviceKeyId>, String>,
|
||||
signatures: BTreeMap<UserId, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
signatures: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
) -> Self {
|
||||
Self { user_id, device_id, algorithms, keys, signatures, unsigned: Default::default() }
|
||||
}
|
||||
@ -72,7 +72,7 @@ impl UnsignedDeviceInfo {
|
||||
}
|
||||
|
||||
/// Signatures for a `SignedKey` object.
|
||||
pub type SignedKeySignatures = BTreeMap<UserId, BTreeMap<Box<DeviceKeyId>, String>>;
|
||||
pub type SignedKeySignatures = BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>;
|
||||
|
||||
/// A key for the SignedCurve25519 algorithm
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@ -105,14 +105,14 @@ pub enum OneTimeKey {
|
||||
}
|
||||
|
||||
/// Signatures for a `CrossSigningKey` object.
|
||||
pub type CrossSigningKeySignatures = BTreeMap<UserId, BTreeMap<String, String>>;
|
||||
pub type CrossSigningKeySignatures = BTreeMap<Box<UserId>, BTreeMap<String, String>>;
|
||||
|
||||
/// A cross signing key.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct CrossSigningKey {
|
||||
/// The ID of the user the key belongs to.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
|
||||
/// What the key is used for.
|
||||
pub usage: Vec<KeyUsage>,
|
||||
@ -132,7 +132,7 @@ pub struct CrossSigningKey {
|
||||
impl CrossSigningKey {
|
||||
/// Creates a new `CrossSigningKey` with the given user ID, usage, keys and signatures.
|
||||
pub fn new(
|
||||
user_id: UserId,
|
||||
user_id: Box<UserId>,
|
||||
usage: Vec<KeyUsage>,
|
||||
keys: BTreeMap<String, String>,
|
||||
signatures: CrossSigningKeySignatures,
|
||||
|
@ -963,7 +963,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn default_ruleset_applies() {
|
||||
let set = Ruleset::server_default(&user_id!("@jolly_jumper:server.name"));
|
||||
let set = Ruleset::server_default(user_id!("@jolly_jumper:server.name"));
|
||||
|
||||
let context_one_to_one = &PushConditionRoomCtx {
|
||||
room_id: room_id!("!dm:server.name").to_owned(),
|
||||
|
@ -90,7 +90,7 @@ impl PushCondition {
|
||||
Self::RoomMemberCount { is } => is.contains(&context.member_count),
|
||||
Self::SenderNotificationPermission { key } => {
|
||||
let sender_id = match event.get("sender") {
|
||||
Some(v) => match UserId::try_from(v) {
|
||||
Some(v) => match <&UserId>::try_from(v) {
|
||||
Ok(u) => u,
|
||||
Err(_) => return false,
|
||||
},
|
||||
@ -99,7 +99,7 @@ impl PushCondition {
|
||||
|
||||
let sender_level = context
|
||||
.users_power_levels
|
||||
.get(&sender_id)
|
||||
.get(sender_id)
|
||||
.unwrap_or(&context.default_power_level);
|
||||
|
||||
match context.notification_power_levels.get(key) {
|
||||
@ -125,7 +125,7 @@ pub struct PushConditionRoomCtx {
|
||||
pub user_display_name: String,
|
||||
|
||||
/// The power levels of the users of the room.
|
||||
pub users_power_levels: BTreeMap<UserId, Int>,
|
||||
pub users_power_levels: BTreeMap<Box<UserId>, Int>,
|
||||
|
||||
/// The default power level of the users of the room.
|
||||
pub default_power_level: Int,
|
||||
@ -478,7 +478,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn conditions_apply_to_events() {
|
||||
let first_sender = user_id!("@worthy_whale:server.name");
|
||||
let first_sender = user_id!("@worthy_whale:server.name").to_owned();
|
||||
|
||||
let mut users_power_levels = BTreeMap::new();
|
||||
users_power_levels.insert(first_sender, 25.into());
|
||||
|
@ -198,7 +198,7 @@ impl Location {
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct User {
|
||||
/// A matrix user ID representing a third party user.
|
||||
pub userid: UserId,
|
||||
pub userid: Box<UserId>,
|
||||
|
||||
/// The protocol ID that the third party user is a part of.
|
||||
pub protocol: String,
|
||||
@ -209,7 +209,7 @@ pub struct User {
|
||||
|
||||
impl User {
|
||||
/// Creates a new `User` with the given userid, protocol and fields.
|
||||
pub fn new(userid: UserId, protocol: String, fields: BTreeMap<String, String>) -> Self {
|
||||
pub fn new(userid: Box<UserId>, protocol: String, fields: BTreeMap<String, String>) -> Self {
|
||||
Self { userid, protocol, fields }
|
||||
}
|
||||
}
|
||||
|
@ -18,10 +18,10 @@ use serde::{Deserialize, Serialize};
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||
#[allow(clippy::exhaustive_structs)]
|
||||
#[ruma_event(type = "m.direct", kind = GlobalAccountData)]
|
||||
pub struct DirectEventContent(pub BTreeMap<UserId, Vec<Box<RoomId>>>);
|
||||
pub struct DirectEventContent(pub BTreeMap<Box<UserId>, Vec<Box<RoomId>>>);
|
||||
|
||||
impl Deref for DirectEventContent {
|
||||
type Target = BTreeMap<UserId, Vec<Box<RoomId>>>;
|
||||
type Target = BTreeMap<Box<UserId>, Vec<Box<RoomId>>>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
|
@ -55,7 +55,7 @@ pub struct MessageEvent<C: MessageEventContent> {
|
||||
pub event_id: Box<EventId>,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
@ -80,7 +80,7 @@ pub struct SyncMessageEvent<C: MessageEventContent> {
|
||||
pub event_id: Box<EventId>,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
@ -102,7 +102,7 @@ pub struct RedactedMessageEvent<C: RedactedMessageEventContent> {
|
||||
pub event_id: Box<EventId>,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
@ -127,7 +127,7 @@ pub struct RedactedSyncMessageEvent<C: RedactedMessageEventContent> {
|
||||
pub event_id: Box<EventId>,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
@ -149,7 +149,7 @@ pub struct StateEvent<C: StateEventContent> {
|
||||
pub event_id: Box<EventId>,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
@ -183,7 +183,7 @@ pub struct SyncStateEvent<C: StateEventContent> {
|
||||
pub event_id: Box<EventId>,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
@ -208,7 +208,7 @@ pub struct StrippedStateEvent<C: StateEventContent> {
|
||||
pub content: C,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// A unique key which defines the overwriting semantics for this piece of room state.
|
||||
///
|
||||
@ -246,7 +246,7 @@ pub struct RedactedStateEvent<C: RedactedStateEventContent> {
|
||||
pub event_id: Box<EventId>,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
@ -277,7 +277,7 @@ pub struct RedactedSyncStateEvent<C: RedactedStateEventContent> {
|
||||
pub event_id: Box<EventId>,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
@ -299,7 +299,7 @@ pub struct ToDeviceEvent<C: ToDeviceEventContent> {
|
||||
pub content: C,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
}
|
||||
|
||||
/// The decrypted payload of an `m.olm.v1.curve25519-aes-sha2` event.
|
||||
@ -309,10 +309,10 @@ pub struct DecryptedOlmV1Event<C: MessageEventContent> {
|
||||
pub content: C,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// The fully-qualified ID of the intended recipient this event.
|
||||
pub recipient: UserId,
|
||||
pub recipient: Box<UserId>,
|
||||
|
||||
/// The recipient's ed25519 key.
|
||||
pub recipient_keys: OlmV1Keys,
|
||||
|
@ -13,12 +13,12 @@ use serde::{Deserialize, Serialize};
|
||||
pub struct IgnoredUserListEventContent {
|
||||
/// A list of users to ignore.
|
||||
#[serde(with = "ruma_serde::vec_as_map_of_empty")]
|
||||
pub ignored_users: Vec<UserId>,
|
||||
pub ignored_users: Vec<Box<UserId>>,
|
||||
}
|
||||
|
||||
impl IgnoredUserListEventContent {
|
||||
/// Creates a new `IgnoredUserListEventContent` from the given user IDs.
|
||||
pub fn new(ignored_users: Vec<UserId>) -> Self {
|
||||
pub fn new(ignored_users: Vec<Box<UserId>>) -> Self {
|
||||
Self { ignored_users }
|
||||
}
|
||||
}
|
||||
@ -36,7 +36,7 @@ mod tests {
|
||||
fn serialization() {
|
||||
let ignored_user_list_event = GlobalAccountDataEvent {
|
||||
content: IgnoredUserListEventContent {
|
||||
ignored_users: vec![user_id!("@carl:example.com")],
|
||||
ignored_users: vec![user_id!("@carl:example.com").to_owned()],
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -195,7 +195,7 @@ mod tests {
|
||||
}),
|
||||
};
|
||||
|
||||
let sender = user_id!("@example:localhost");
|
||||
let sender = user_id!("@example:localhost").to_owned();
|
||||
|
||||
let json_data = json!({
|
||||
"content": {
|
||||
@ -216,7 +216,7 @@ mod tests {
|
||||
|
||||
assert_eq!(to_json_value(&key_verification_accept).unwrap(), json_data);
|
||||
|
||||
let sender = user_id!("@example:localhost");
|
||||
let sender = user_id!("@example:localhost").to_owned();
|
||||
|
||||
let json_data = json!({
|
||||
"content": {
|
||||
|
@ -234,7 +234,7 @@ mod tests {
|
||||
),
|
||||
};
|
||||
|
||||
let sender = user_id!("@example:localhost");
|
||||
let sender = user_id!("@example:localhost").to_owned();
|
||||
|
||||
let json_data = json!({
|
||||
"content": {
|
||||
@ -255,7 +255,7 @@ mod tests {
|
||||
|
||||
assert_eq!(to_json_value(&key_verification_start).unwrap(), json_data);
|
||||
|
||||
let sender = user_id!("@example:localhost");
|
||||
let sender = user_id!("@example:localhost").to_owned();
|
||||
|
||||
let json_data = json!({
|
||||
"content": {
|
||||
|
@ -41,7 +41,7 @@ pub struct RoomV1Pdu {
|
||||
pub room_id: Box<RoomId>,
|
||||
|
||||
/// The user id of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
#[cfg(not(feature = "unstable-pre-spec"))]
|
||||
/// The `server_name` of the homeserver that created this event.
|
||||
@ -100,7 +100,7 @@ pub struct RoomV3Pdu {
|
||||
pub room_id: Box<RoomId>,
|
||||
|
||||
/// The user id of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
#[cfg(not(feature = "unstable-pre-spec"))]
|
||||
/// The `server_name` of the homeserver that created this event.
|
||||
|
@ -33,7 +33,7 @@ mod tests {
|
||||
fn serialization() {
|
||||
let room_event = PolicyRuleRoomEvent {
|
||||
event_id: event_id!("$143273582443PhrSn:example.org").to_owned(),
|
||||
sender: user_id!("@example:example.org"),
|
||||
sender: user_id!("@example:example.org").to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(1_432_735_824_653_u64.try_into().unwrap()),
|
||||
room_id: room_id!("!jEsUZKDJdhlrceRyVU:example.org").to_owned(),
|
||||
state_key: "rule:#*:example.org".into(),
|
||||
|
@ -18,7 +18,7 @@ pub struct PresenceEvent {
|
||||
pub content: PresenceEventContent,
|
||||
|
||||
/// Contains the fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
}
|
||||
|
||||
/// Informs the room of members presence.
|
||||
@ -99,7 +99,7 @@ mod tests {
|
||||
presence: PresenceState::Online,
|
||||
status_msg: Some("Making cupcakes".into()),
|
||||
},
|
||||
sender: user_id!("@example:localhost"),
|
||||
sender: user_id!("@example:localhost").to_owned(),
|
||||
};
|
||||
|
||||
let json = json!({
|
||||
|
@ -41,7 +41,7 @@ pub type Receipts = BTreeMap<ReceiptType, UserReceipts>;
|
||||
/// A mapping of user ID to receipt.
|
||||
///
|
||||
/// The user ID is the entity who sent this receipt.
|
||||
pub type UserReceipts = BTreeMap<UserId, Receipt>;
|
||||
pub type UserReceipts = BTreeMap<Box<UserId>, Receipt>;
|
||||
|
||||
/// An acknowledgement of an event.
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
|
@ -55,7 +55,7 @@ mod tests {
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
prev_content: None,
|
||||
room_id: room_id!("!dummy:example.com").to_owned(),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
state_key: "".into(),
|
||||
unsigned: Unsigned::default(),
|
||||
};
|
||||
|
@ -18,7 +18,7 @@ pub struct RoomCreateEventContent {
|
||||
///
|
||||
/// This is set by the homeserver.
|
||||
#[ruma_event(skip_redaction)]
|
||||
pub creator: UserId,
|
||||
pub creator: Box<UserId>,
|
||||
|
||||
/// Whether or not this room's data should be transferred to other homeservers.
|
||||
#[serde(
|
||||
@ -48,7 +48,7 @@ pub struct RoomCreateEventContent {
|
||||
|
||||
impl RoomCreateEventContent {
|
||||
/// Creates a new `RoomCreateEventContent` with the given creator.
|
||||
pub fn new(creator: UserId) -> Self {
|
||||
pub fn new(creator: Box<UserId>) -> Self {
|
||||
Self {
|
||||
creator,
|
||||
federate: true,
|
||||
@ -119,7 +119,7 @@ mod tests {
|
||||
#[test]
|
||||
fn serialization() {
|
||||
let content = RoomCreateEventContent {
|
||||
creator: user_id!("@carl:example.com"),
|
||||
creator: user_id!("@carl:example.com").to_owned(),
|
||||
federate: false,
|
||||
room_version: RoomVersionId::Version4,
|
||||
predecessor: None,
|
||||
@ -140,7 +140,7 @@ mod tests {
|
||||
#[test]
|
||||
fn space_serialization() {
|
||||
let content = RoomCreateEventContent {
|
||||
creator: user_id!("@carl:example.com"),
|
||||
creator: user_id!("@carl:example.com").to_owned(),
|
||||
federate: false,
|
||||
room_version: RoomVersionId::Version4,
|
||||
predecessor: None,
|
||||
|
@ -174,7 +174,7 @@ pub struct SignedContent {
|
||||
/// The invited Matrix user ID.
|
||||
///
|
||||
/// Must be equal to the user_id property of the event.
|
||||
pub mxid: UserId,
|
||||
pub mxid: Box<UserId>,
|
||||
|
||||
/// A single signature from the verifying server, in the format specified by the Signing Events
|
||||
/// section of the server-server API.
|
||||
@ -187,7 +187,7 @@ pub struct SignedContent {
|
||||
impl SignedContent {
|
||||
/// Creates a new `SignedContent` with the given mxid, signature and token.
|
||||
pub fn new(
|
||||
mxid: UserId,
|
||||
mxid: Box<UserId>,
|
||||
signatures: BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>>,
|
||||
token: String,
|
||||
) -> Self {
|
||||
|
@ -975,7 +975,7 @@ pub struct KeyVerificationRequestEventContent {
|
||||
/// Users should only respond to verification requests if they are named in this field. Users
|
||||
/// who are not named in this field and who did not send this event should ignore all other
|
||||
/// events that have a `m.reference` relationship with this event.
|
||||
pub to: UserId,
|
||||
pub to: Box<UserId>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
@ -986,7 +986,7 @@ impl KeyVerificationRequestEventContent {
|
||||
body: String,
|
||||
methods: Vec<VerificationMethod>,
|
||||
from_device: Box<DeviceId>,
|
||||
to: UserId,
|
||||
to: Box<UserId>,
|
||||
) -> Self {
|
||||
Self { body, methods, from_device, to }
|
||||
}
|
||||
|
@ -300,21 +300,18 @@ fn formatted_or_plain_body<'a>(formatted: &'a Option<FormattedBody>, body: &'a s
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use ruma_identifiers::{room_id, EventId, UserId};
|
||||
use ruma_identifiers::{event_id, room_id, user_id};
|
||||
|
||||
use super::RoomMessageEvent;
|
||||
use crate::room::message::RoomMessageEventContent;
|
||||
|
||||
#[test]
|
||||
fn plain_quote_fallback_multiline() {
|
||||
let sender = UserId::try_from("@alice:example.com").unwrap();
|
||||
assert_eq!(
|
||||
super::get_plain_quote_fallback(&RoomMessageEvent {
|
||||
content: RoomMessageEventContent::text_plain("multi\nline"),
|
||||
event_id: EventId::new(sender.server_name()),
|
||||
sender,
|
||||
event_id: event_id!("$1598361704261elfgc:localhost").to_owned(),
|
||||
sender: user_id!("@alice:example.com").to_owned(),
|
||||
origin_server_ts: ruma_common::MilliSecondsSinceUnixEpoch::now(),
|
||||
room_id: room_id!("!n8f893n9:example.com").to_owned(),
|
||||
unsigned: crate::Unsigned::new(),
|
||||
|
@ -45,7 +45,7 @@ mod tests {
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
prev_content: None,
|
||||
room_id: room_id!("!n8f893n9:example.com").to_owned(),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
state_key: "".into(),
|
||||
unsigned: Unsigned::default(),
|
||||
};
|
||||
@ -74,7 +74,7 @@ mod tests {
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
prev_content: Some(RoomNameEventContent { name: "The old name".try_into().ok() }),
|
||||
room_id: room_id!("!n8f893n9:example.com").to_owned(),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
state_key: "".into(),
|
||||
unsigned: Unsigned { age: Some(int!(100)), ..Unsigned::default() },
|
||||
};
|
||||
|
@ -98,7 +98,7 @@ pub struct RoomPowerLevelsEventContent {
|
||||
)]
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
#[ruma_event(skip_redaction)]
|
||||
pub users: BTreeMap<UserId, Int>,
|
||||
pub users: BTreeMap<Box<UserId>, Int>,
|
||||
|
||||
/// The default power level for every user in the room.
|
||||
///
|
||||
@ -184,7 +184,7 @@ mod tests {
|
||||
prev_content: None,
|
||||
room_id: room_id!("!n8f893n9:example.com").to_owned(),
|
||||
unsigned: Unsigned::default(),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
state_key: "".into(),
|
||||
};
|
||||
|
||||
@ -217,7 +217,7 @@ mod tests {
|
||||
redact: int!(23),
|
||||
state_default: int!(23),
|
||||
users: btreemap! {
|
||||
user.clone() => int!(23)
|
||||
user.to_owned() => int!(23)
|
||||
},
|
||||
users_default: int!(23),
|
||||
notifications: assign!(NotificationPowerLevels::new(), { room: int!(23) }),
|
||||
@ -236,14 +236,14 @@ mod tests {
|
||||
redact: int!(42),
|
||||
state_default: int!(42),
|
||||
users: btreemap! {
|
||||
user.clone() => int!(42)
|
||||
user.to_owned() => int!(42)
|
||||
},
|
||||
users_default: int!(42),
|
||||
notifications: assign!(NotificationPowerLevels::new(), { room: int!(42) }),
|
||||
}),
|
||||
room_id: room_id!("!n8f893n9:example.com").to_owned(),
|
||||
unsigned: Unsigned { age: Some(int!(100)), ..Unsigned::default() },
|
||||
sender: user,
|
||||
sender: user.to_owned(),
|
||||
state_key: "".into(),
|
||||
};
|
||||
|
||||
|
@ -21,7 +21,7 @@ pub struct RoomRedactionEvent {
|
||||
pub event_id: Box<EventId>,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
@ -68,7 +68,7 @@ pub struct RedactedRoomRedactionEvent {
|
||||
pub event_id: Box<EventId>,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
@ -94,7 +94,7 @@ pub struct SyncRoomRedactionEvent {
|
||||
pub event_id: Box<EventId>,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
@ -137,7 +137,7 @@ pub struct RedactedSyncRoomRedactionEvent {
|
||||
pub event_id: Box<EventId>,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
|
@ -56,7 +56,7 @@ mod tests {
|
||||
session_id: "SessId".into(),
|
||||
session_key: "SessKey".into(),
|
||||
},
|
||||
sender: user_id!("@user:example.org"),
|
||||
sender: user_id!("@user:example.org").to_owned(),
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
|
@ -12,12 +12,12 @@ use serde::{Deserialize, Serialize};
|
||||
#[ruma_event(type = "m.typing", kind = EphemeralRoom)]
|
||||
pub struct TypingEventContent {
|
||||
/// The list of user IDs typing in this room, if any.
|
||||
pub user_ids: Vec<UserId>,
|
||||
pub user_ids: Vec<Box<UserId>>,
|
||||
}
|
||||
|
||||
impl TypingEventContent {
|
||||
/// Creates a new `TypingEventContent` with the given user IDs.
|
||||
pub fn new(user_ids: Vec<UserId>) -> Self {
|
||||
pub fn new(user_ids: Vec<Box<UserId>>) -> Self {
|
||||
Self { user_ids }
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ fn serialize_custom_message_event() {
|
||||
event_id: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10)),
|
||||
room_id: room_id!("!room:room.com").to_owned(),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
unsigned: Unsigned::default(),
|
||||
};
|
||||
|
||||
@ -94,7 +94,7 @@ fn serialize_custom_state_event() {
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10)),
|
||||
prev_content: None,
|
||||
room_id: room_id!("!roomid:room.com").to_owned(),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
state_key: "".into(),
|
||||
unsigned: Unsigned::default(),
|
||||
};
|
||||
|
@ -205,7 +205,7 @@ fn message_event_serialization() {
|
||||
event_id: event_id!("$1234:example.com").to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(0)),
|
||||
room_id: room_id!("!roomid:example.com").to_owned(),
|
||||
sender: user_id!("@test:example.com"),
|
||||
sender: user_id!("@test:example.com").to_owned(),
|
||||
unsigned: Unsigned::default(),
|
||||
};
|
||||
|
||||
@ -286,7 +286,7 @@ fn alias_event_field_access() {
|
||||
if state_event.state_key() == ""
|
||||
&& state_event.room_id() == room_id!("!room:room.com")
|
||||
&& state_event.event_id() == event_id!("$152037280074GZeOm:localhost")
|
||||
&& state_event.sender() == &user_id!("@example:localhost")
|
||||
&& state_event.sender() == user_id!("@example:localhost")
|
||||
);
|
||||
|
||||
let deser = from_json_value::<AnyStateEvent>(json_data).unwrap();
|
||||
|
@ -14,7 +14,7 @@ use ruma_events::{
|
||||
#[test]
|
||||
fn ephemeral_serialize_typing() {
|
||||
let aliases_event = EphemeralRoomEvent {
|
||||
content: TypingEventContent::new(vec![user_id!("@carl:example.com")]),
|
||||
content: TypingEventContent::new(vec![user_id!("@carl:example.com").to_owned()]),
|
||||
room_id: room_id!("!roomid:room.com").to_owned(),
|
||||
};
|
||||
|
||||
@ -53,7 +53,7 @@ fn deserialize_ephemeral_typing() {
|
||||
#[test]
|
||||
fn ephemeral_serialize_receipt() {
|
||||
let event_id = event_id!("$h29iv0s8:example.com").to_owned();
|
||||
let user_id = user_id!("@carl:example.com");
|
||||
let user_id = user_id!("@carl:example.com").to_owned();
|
||||
|
||||
let aliases_event = EphemeralRoomEvent {
|
||||
content: ReceiptEventContent(btreemap! {
|
||||
@ -108,7 +108,7 @@ fn deserialize_ephemeral_receipt() {
|
||||
&& room_id == room_id!("!roomid:room.com")
|
||||
&& receipts
|
||||
.get(event_id)
|
||||
.map(|r| r.get(&ReceiptType::Read).unwrap().get(&user_id).unwrap())
|
||||
.map(|r| r.get(&ReceiptType::Read).unwrap().get(user_id).unwrap())
|
||||
.map(|r| r.ts)
|
||||
.unwrap()
|
||||
== Some(MilliSecondsSinceUnixEpoch(uint!(1)))
|
||||
|
@ -89,7 +89,7 @@ fn serialize_message_event() {
|
||||
event_id: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
room_id: room_id!("!roomid:room.com").to_owned(),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
unsigned: Unsigned::default(),
|
||||
});
|
||||
|
||||
|
@ -35,7 +35,7 @@ fn message_serialize_sticker() {
|
||||
event_id: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
room_id: room_id!("!roomid:room.com").to_owned(),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
unsigned: Unsigned::default(),
|
||||
};
|
||||
|
||||
|
@ -29,7 +29,7 @@ fn serialize_pdu_as_v1() {
|
||||
let v1_pdu = RoomV1Pdu {
|
||||
room_id: room_id!("!n8f893n9:example.com").to_owned(),
|
||||
event_id: event_id!("$somejoinevent:matrix.org").to_owned(),
|
||||
sender: user_id!("@sender:example.com"),
|
||||
sender: user_id!("@sender:example.com").to_owned(),
|
||||
origin: "matrix.org".into(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(1_592_050_773_658_u64.try_into().unwrap()),
|
||||
kind: EventType::RoomPowerLevels,
|
||||
@ -95,7 +95,7 @@ fn serialize_pdu_as_v3() {
|
||||
|
||||
let v3_pdu = RoomV3Pdu {
|
||||
room_id: room_id!("!n8f893n9:example.com").to_owned(),
|
||||
sender: user_id!("@sender:example.com"),
|
||||
sender: user_id!("@sender:example.com").to_owned(),
|
||||
origin: "matrix.org".into(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(1_592_050_773_658_u64.try_into().unwrap()),
|
||||
kind: EventType::RoomPowerLevels,
|
||||
|
@ -26,7 +26,7 @@ fn unsigned() -> RedactedUnsigned {
|
||||
redacts: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
event_id: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
unsigned: Unsigned::default(),
|
||||
}));
|
||||
|
||||
@ -39,7 +39,7 @@ fn redacted_message_event_serialize() {
|
||||
content: RedactedRoomMessageEventContent::new(),
|
||||
event_id: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
unsigned: RedactedUnsigned::default(),
|
||||
};
|
||||
|
||||
@ -61,7 +61,7 @@ fn redacted_aliases_event_serialize_no_content() {
|
||||
event_id: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
state_key: "".into(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
unsigned: RedactedUnsigned::default(),
|
||||
};
|
||||
|
||||
@ -84,7 +84,7 @@ fn redacted_aliases_event_serialize_with_content() {
|
||||
event_id: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
state_key: "".to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
unsigned: RedactedUnsigned::default(),
|
||||
};
|
||||
|
||||
@ -163,7 +163,7 @@ fn redacted_deserialize_any_room_sync() {
|
||||
redacts: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
event_id: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
unsigned: Unsigned::default(),
|
||||
}));
|
||||
|
||||
@ -250,7 +250,7 @@ fn redacted_custom_event_deserialize() {
|
||||
let redacted = RedactedSyncStateEvent {
|
||||
content: RedactedCustomEventContent { event_type: "m.made.up".into() },
|
||||
event_id: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
state_key: "hello there".into(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
unsigned: unsigned.clone(),
|
||||
@ -289,7 +289,7 @@ fn redact_method_properly_redacts() {
|
||||
redacts: event_id!("$143273582443PhrSn:example.com").to_owned(),
|
||||
event_id: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
unsigned: Unsigned::default(),
|
||||
};
|
||||
|
||||
|
@ -32,7 +32,7 @@ fn serialize_redaction() {
|
||||
event_id: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
room_id: room_id!("!roomid:room.com").to_owned(),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
unsigned: Unsigned::default(),
|
||||
};
|
||||
|
||||
|
@ -43,7 +43,7 @@ fn serialization() {
|
||||
event_id: event_id!("$143273582443PhrSn:example.org").to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10_000)),
|
||||
room_id: room_id!("!testroomid:example.org").to_owned(),
|
||||
sender: user_id!("@user:example.org"),
|
||||
sender: user_id!("@user:example.org").to_owned(),
|
||||
unsigned: Unsigned::default(),
|
||||
};
|
||||
|
||||
@ -335,7 +335,7 @@ fn verification_request_deserialization() {
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
fn verification_request_serialization() {
|
||||
let user_id = user_id!("@example2:localhost");
|
||||
let user_id = user_id!("@example2:localhost").to_owned();
|
||||
let device_id: Box<DeviceId> = "XOWLHHFSWM".into();
|
||||
let body = "@example:localhost is requesting to verify your key, ...".to_owned();
|
||||
|
||||
|
@ -45,7 +45,7 @@ fn serialize_aliases_with_prev_content() {
|
||||
room_alias_id!("#inner:localhost").to_owned()
|
||||
])),
|
||||
room_id: room_id!("!roomid:room.com").to_owned(),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
state_key: "".into(),
|
||||
unsigned: Unsigned::default(),
|
||||
};
|
||||
@ -66,7 +66,7 @@ fn serialize_aliases_without_prev_content() {
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
|
||||
prev_content: None,
|
||||
room_id: room_id!("!roomid:room.com").to_owned(),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
state_key: "".into(),
|
||||
unsigned: Unsigned::default(),
|
||||
};
|
||||
|
@ -13,7 +13,7 @@ fn serialize_stripped_state_event_any_content() {
|
||||
let event = StrippedStateEvent {
|
||||
content: RoomTopicEventContent::new("Testing room".into()),
|
||||
state_key: "".into(),
|
||||
sender: user_id!("@example:localhost"),
|
||||
sender: user_id!("@example:localhost").to_owned(),
|
||||
};
|
||||
|
||||
let json_data = json!({
|
||||
@ -33,7 +33,7 @@ fn serialize_stripped_state_event_any_event() {
|
||||
let event = AnyStrippedStateEvent::RoomTopic(StrippedStateEvent {
|
||||
content: RoomTopicEventContent::new("Testing room".into()),
|
||||
state_key: "".into(),
|
||||
sender: user_id!("@example:localhost"),
|
||||
sender: user_id!("@example:localhost").to_owned(),
|
||||
});
|
||||
|
||||
let json_data = json!({
|
||||
|
@ -5,7 +5,7 @@ use serde_json::{json, to_value as to_json_value};
|
||||
#[test]
|
||||
fn serialization() {
|
||||
let ev = ToDeviceEvent {
|
||||
sender: user_id!("@example:example.org"),
|
||||
sender: user_id!("@example:example.org").to_owned(),
|
||||
content: ToDeviceRoomKeyEventContent::new(
|
||||
EventEncryptionAlgorithm::MegolmV1AesSha2,
|
||||
room_id!("!testroomid:example.org").to_owned(),
|
||||
|
@ -13,7 +13,7 @@ use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
pub struct StateEvent<C: StateEventContent> {
|
||||
pub content: C,
|
||||
pub event_id: Box<EventId>,
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
pub room_id: Box<RoomId>,
|
||||
pub state_key: String,
|
||||
|
@ -26,7 +26,7 @@ ruma_api! {
|
||||
|
||||
response: {
|
||||
/// The user ID devices were requested for.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
|
||||
/// A unique ID for a given user_id which describes the version of the returned device list.
|
||||
///
|
||||
@ -50,7 +50,7 @@ impl Response {
|
||||
/// Creates a new `Response` with the given user id and stream id.
|
||||
///
|
||||
/// The device list will be empty.
|
||||
pub fn new(user_id: UserId, stream_id: UInt) -> Self {
|
||||
pub fn new(user_id: Box<UserId>, stream_id: UInt) -> Self {
|
||||
Self { user_id, stream_id, devices: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
@ -44,11 +44,11 @@ impl Response {
|
||||
}
|
||||
|
||||
/// A claim for one time keys
|
||||
pub type OneTimeKeyClaims = BTreeMap<UserId, BTreeMap<Box<DeviceId>, DeviceKeyAlgorithm>>;
|
||||
pub type OneTimeKeyClaims = BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, DeviceKeyAlgorithm>>;
|
||||
|
||||
/// One time keys for use in pre-key messages
|
||||
pub type OneTimeKeys =
|
||||
BTreeMap<UserId, BTreeMap<Box<DeviceId>, BTreeMap<Box<DeviceKeyId>, OneTimeKey>>>;
|
||||
BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, BTreeMap<Box<DeviceKeyId>, OneTimeKey>>>;
|
||||
|
||||
/// A key and its signature
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@ -58,14 +58,14 @@ pub struct KeyObject {
|
||||
pub key: String,
|
||||
|
||||
/// Signature of the key object.
|
||||
pub signatures: BTreeMap<UserId, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
pub signatures: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
}
|
||||
|
||||
impl KeyObject {
|
||||
/// Creates a new `KeyObject` with the given key and signatures.
|
||||
pub fn new(
|
||||
key: String,
|
||||
signatures: BTreeMap<UserId, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
signatures: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
) -> Self {
|
||||
Self { key, signatures }
|
||||
}
|
||||
|
@ -22,36 +22,36 @@ ruma_api! {
|
||||
/// The keys to be downloaded.
|
||||
///
|
||||
/// Gives all keys for a given user if the list of device ids is empty.
|
||||
pub device_keys: BTreeMap<UserId, Vec<Box<DeviceId>>>,
|
||||
pub device_keys: BTreeMap<Box<UserId>, Vec<Box<DeviceId>>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {
|
||||
/// Keys from the queried devices.
|
||||
pub device_keys: BTreeMap<UserId, BTreeMap<Box<DeviceId>, DeviceKeys>>,
|
||||
pub device_keys: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, DeviceKeys>>,
|
||||
|
||||
/// Information on the master cross-signing keys of the queried users.
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub master_keys: BTreeMap<UserId, CrossSigningKey>,
|
||||
pub master_keys: BTreeMap<Box<UserId>, CrossSigningKey>,
|
||||
|
||||
/// Information on the self-signing keys of the queried users.
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub self_signing_keys: BTreeMap<UserId, CrossSigningKey>,
|
||||
pub self_signing_keys: BTreeMap<Box<UserId>, CrossSigningKey>,
|
||||
}
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates a new `Request` asking for the given device keys.
|
||||
pub fn new(device_keys: BTreeMap<UserId, Vec<Box<DeviceId>>>) -> Self {
|
||||
pub fn new(device_keys: BTreeMap<Box<UserId>, Vec<Box<DeviceId>>>) -> Self {
|
||||
Self { device_keys }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given device keys.
|
||||
pub fn new(device_keys: BTreeMap<UserId, BTreeMap<Box<DeviceId>, DeviceKeys>>) -> Self {
|
||||
pub fn new(device_keys: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, DeviceKeys>>) -> Self {
|
||||
Self { device_keys, ..Default::default() }
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ ruma_api! {
|
||||
|
||||
response: {
|
||||
/// The Matrix User ID who generated the token.
|
||||
pub sub: UserId,
|
||||
pub sub: Box<UserId>,
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ impl<'a> Request<'a> {
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given user id.
|
||||
pub fn new(sub: UserId) -> Self {
|
||||
pub fn new(sub: Box<UserId>) -> Self {
|
||||
Self { sub }
|
||||
}
|
||||
}
|
||||
|
@ -68,13 +68,13 @@ pub struct ThirdPartyInvite {
|
||||
pub address: String,
|
||||
|
||||
/// The now-bound user ID that received the invite.
|
||||
pub mxid: UserId,
|
||||
pub mxid: Box<UserId>,
|
||||
|
||||
/// The room ID the invite is valid for.
|
||||
pub room_id: Box<RoomId>,
|
||||
|
||||
/// The user ID that sent the invite.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Signature from the identity server using a long-term private key.
|
||||
pub signed: BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>>,
|
||||
@ -84,9 +84,9 @@ impl ThirdPartyInvite {
|
||||
/// Creates a new third party invite with the given parameters.
|
||||
pub fn new(
|
||||
address: String,
|
||||
mxid: UserId,
|
||||
mxid: Box<UserId>,
|
||||
room_id: Box<RoomId>,
|
||||
sender: UserId,
|
||||
sender: Box<UserId>,
|
||||
signed: BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>>,
|
||||
) -> Self {
|
||||
Self { medium: Medium::Email, address, mxid, room_id, sender, signed }
|
||||
|
@ -95,7 +95,7 @@ impl PresenceContent {
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct PresenceUpdate {
|
||||
/// The user ID this presence EDU is for.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
|
||||
/// The presence of the user.
|
||||
pub presence: PresenceState,
|
||||
@ -116,7 +116,7 @@ pub struct PresenceUpdate {
|
||||
|
||||
impl PresenceUpdate {
|
||||
/// Creates a new `PresenceUpdate` with the given `user_id`, `presence` and `last_activity`.
|
||||
pub fn new(user_id: UserId, presence: PresenceState, last_activity: UInt) -> Self {
|
||||
pub fn new(user_id: Box<UserId>, presence: PresenceState, last_activity: UInt) -> Self {
|
||||
Self {
|
||||
user_id,
|
||||
presence,
|
||||
@ -149,12 +149,12 @@ impl ReceiptContent {
|
||||
pub struct ReceiptMap {
|
||||
/// Read receipts for users in the room.
|
||||
#[serde(rename = "m.read")]
|
||||
pub read: BTreeMap<UserId, ReceiptData>,
|
||||
pub read: BTreeMap<Box<UserId>, ReceiptData>,
|
||||
}
|
||||
|
||||
impl ReceiptMap {
|
||||
/// Creates a new `ReceiptMap`.
|
||||
pub fn new(read: BTreeMap<UserId, ReceiptData>) -> Self {
|
||||
pub fn new(read: BTreeMap<Box<UserId>, ReceiptData>) -> Self {
|
||||
Self { read }
|
||||
}
|
||||
}
|
||||
@ -185,7 +185,7 @@ pub struct TypingContent {
|
||||
pub room_id: Box<RoomId>,
|
||||
|
||||
/// The user ID that has had their typing status changed.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
|
||||
/// Whether the user is typing in the room or not.
|
||||
pub typing: bool,
|
||||
@ -193,7 +193,7 @@ pub struct TypingContent {
|
||||
|
||||
impl TypingContent {
|
||||
/// Creates a new `TypingContent`.
|
||||
pub fn new(room_id: Box<RoomId>, user_id: UserId, typing: bool) -> Self {
|
||||
pub fn new(room_id: Box<RoomId>, user_id: Box<UserId>, typing: bool) -> Self {
|
||||
Self { room_id, user_id, typing }
|
||||
}
|
||||
}
|
||||
@ -203,7 +203,7 @@ impl TypingContent {
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct DeviceListUpdateContent {
|
||||
/// The user ID who owns the device.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
|
||||
/// The ID of the device whose details are changing.
|
||||
pub device_id: Box<DeviceId>,
|
||||
@ -234,7 +234,7 @@ pub struct DeviceListUpdateContent {
|
||||
impl DeviceListUpdateContent {
|
||||
/// Create a new `DeviceListUpdateContent` with the given `user_id`, `device_id` and
|
||||
/// `stream_id`.
|
||||
pub fn new(user_id: UserId, device_id: Box<DeviceId>, stream_id: UInt) -> Self {
|
||||
pub fn new(user_id: Box<UserId>, device_id: Box<DeviceId>, stream_id: UInt) -> Self {
|
||||
Self {
|
||||
user_id,
|
||||
device_id,
|
||||
@ -252,7 +252,7 @@ impl DeviceListUpdateContent {
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct DirectDeviceContent {
|
||||
/// The user ID of the sender.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// Event type for the message.
|
||||
#[serde(rename = "type")]
|
||||
@ -270,7 +270,7 @@ pub struct DirectDeviceContent {
|
||||
|
||||
impl DirectDeviceContent {
|
||||
/// Creates a new `DirectDeviceContent` with the given `sender, `ev_type` and `message_id`.
|
||||
pub fn new(sender: UserId, ev_type: EventType, message_id: String) -> Self {
|
||||
pub fn new(sender: Box<UserId>, ev_type: EventType, message_id: String) -> Self {
|
||||
Self { sender, ev_type, message_id, messages: DirectDeviceMessages::new() }
|
||||
}
|
||||
}
|
||||
@ -279,7 +279,7 @@ impl DirectDeviceContent {
|
||||
///
|
||||
/// Represented as a map of `{ user-ids => { device-ids => message-content } }`.
|
||||
pub type DirectDeviceMessages =
|
||||
BTreeMap<UserId, BTreeMap<DeviceIdOrAllDevices, Raw<AnyToDeviceEventContent>>>;
|
||||
BTreeMap<Box<UserId>, BTreeMap<DeviceIdOrAllDevices, Raw<AnyToDeviceEventContent>>>;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
@ -460,7 +460,7 @@ mod test {
|
||||
}) if sender == "@john:example.com"
|
||||
&& *ev_type == EventType::RoomKeyRequest
|
||||
&& message_id == "hiezohf6Hoo7kaev"
|
||||
&& messages.get(&user_id!("@alice:example.org")).is_some()
|
||||
&& messages.get(user_id!("@alice:example.org")).is_some()
|
||||
);
|
||||
|
||||
assert_eq!(serde_json::to_value(&edu).unwrap(), json);
|
||||
|
@ -129,7 +129,7 @@ pub fn user_id(input: TokenStream) -> TokenStream {
|
||||
assert!(user_id::validate(&id.value()).is_ok(), "Invalid user_id");
|
||||
|
||||
let output = quote! {
|
||||
<#dollar_crate::UserId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap()
|
||||
<&#dollar_crate::UserId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap()
|
||||
};
|
||||
|
||||
output.into()
|
||||
|
@ -76,89 +76,6 @@ macro_rules! as_str_based_impls {
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! common_impls {
|
||||
($id:ty, $try_from:ident, $desc:literal) => {
|
||||
impl $id {
|
||||
doc_concat! {
|
||||
#[doc = concat!("Creates a string slice from this `", stringify!($id), "`")]
|
||||
pub fn as_str(&self) -> &str {
|
||||
&self.full_id
|
||||
}
|
||||
}
|
||||
|
||||
doc_concat! {
|
||||
#[doc = concat!("Creates a byte slice from this `", stringify!($id), "`")]
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
self.full_id.as_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
doc_concat! {
|
||||
#[doc = concat!("Converts this `", stringify!($id), "` into a `String`")]
|
||||
pub fn into_string(self) -> String {
|
||||
self.full_id.into()
|
||||
}
|
||||
}
|
||||
|
||||
doc_concat! {
|
||||
#[doc = concat!("Converts this `", stringify!($id), "` into a `Vec<u8>`")]
|
||||
pub fn into_bytes(self) -> Vec<u8> {
|
||||
Box::<[u8]>::from(self.full_id).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<$id> for String {
|
||||
fn from(id: $id) -> Self {
|
||||
id.into_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<$id> for Vec<u8> {
|
||||
fn from(id: $id) -> Self {
|
||||
id.into_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for $id {
|
||||
type Err = crate::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
$try_from(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::TryFrom<&str> for $id {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
||||
$try_from(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::TryFrom<String> for $id {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(s: String) -> Result<Self, Self::Error> {
|
||||
$try_from(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl<'de> serde::Deserialize<'de> for $id {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
crate::deserialize_id(deserializer, $desc)
|
||||
}
|
||||
}
|
||||
|
||||
as_str_based_impls!($id);
|
||||
partial_eq_string!($id);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! opaque_identifier_common_impls {
|
||||
($id:ty) => {
|
||||
impl $id {
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Matrix user identifiers.
|
||||
|
||||
use std::{convert::TryInto, fmt, num::NonZeroU8};
|
||||
use std::convert::TryInto;
|
||||
|
||||
use crate::{MatrixToRef, ServerName};
|
||||
|
||||
@ -13,39 +13,23 @@ use crate::{MatrixToRef, ServerName};
|
||||
/// # use std::convert::TryFrom;
|
||||
/// # use ruma_identifiers::UserId;
|
||||
/// assert_eq!(
|
||||
/// UserId::try_from("@carl:example.com").unwrap().as_ref(),
|
||||
/// <&UserId>::try_from("@carl:example.com").unwrap(),
|
||||
/// "@carl:example.com"
|
||||
/// );
|
||||
/// ```
|
||||
#[derive(Clone)]
|
||||
pub struct UserId {
|
||||
full_id: Box<str>,
|
||||
colon_idx: NonZeroU8,
|
||||
#[repr(transparent)]
|
||||
pub struct UserId(str);
|
||||
|
||||
/// Whether this user id is a historical one.
|
||||
///
|
||||
/// A historical user id is one that is not legal per the regular user id rules, but was
|
||||
/// accepted by previous versions of the spec and thus has to be supported because users with
|
||||
/// these kinds of ids still exist.
|
||||
is_historical: bool,
|
||||
}
|
||||
|
||||
impl fmt::Debug for UserId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.full_id.fmt(f)
|
||||
}
|
||||
}
|
||||
opaque_identifier_validated!(UserId, ruma_identifiers_validation::user_id::validate);
|
||||
|
||||
impl UserId {
|
||||
/// Attempts to generate a `UserId` for the given origin server with a localpart consisting of
|
||||
/// 12 random ASCII characters.
|
||||
#[cfg(feature = "rand")]
|
||||
pub fn new(server_name: &ServerName) -> Self {
|
||||
use crate::generate_localpart;
|
||||
|
||||
let full_id = format!("@{}:{}", generate_localpart(12).to_lowercase(), server_name).into();
|
||||
|
||||
Self { full_id, colon_idx: NonZeroU8::new(13).unwrap(), is_historical: false }
|
||||
pub fn new(server_name: &ServerName) -> Box<Self> {
|
||||
Self::from_owned(
|
||||
format!("@{}:{}", crate::generate_localpart(12).to_lowercase(), server_name).into(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Attempts to complete a user ID, by adding the colon + server name and `@` prefix, if not
|
||||
@ -58,30 +42,24 @@ impl UserId {
|
||||
pub fn parse_with_server_name(
|
||||
id: impl AsRef<str> + Into<Box<str>>,
|
||||
server_name: &ServerName,
|
||||
) -> Result<Self, crate::Error> {
|
||||
) -> Result<Box<Self>, crate::Error> {
|
||||
let id_str = id.as_ref();
|
||||
|
||||
if id_str.starts_with('@') {
|
||||
try_from(id.into())
|
||||
try_from(id)
|
||||
} else {
|
||||
let is_fully_conforming = localpart_is_fully_conforming(id_str)?;
|
||||
|
||||
Ok(Self {
|
||||
full_id: format!("@{}:{}", id_str, server_name).into(),
|
||||
colon_idx: NonZeroU8::new(id_str.len() as u8 + 1).unwrap(),
|
||||
is_historical: !is_fully_conforming,
|
||||
})
|
||||
Ok(Self::from_owned(format!("@{}:{}", id_str, server_name).into()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the user's localpart.
|
||||
pub fn localpart(&self) -> &str {
|
||||
&self.full_id[1..self.colon_idx.get() as usize]
|
||||
&self.as_str()[1..self.colon_idx() as usize]
|
||||
}
|
||||
|
||||
/// Returns the server name of the user ID.
|
||||
pub fn server_name(&self) -> &ServerName {
|
||||
self.full_id[self.colon_idx.get() as usize + 1..].try_into().unwrap()
|
||||
self.as_str()[self.colon_idx() as usize + 1..].try_into().unwrap()
|
||||
}
|
||||
|
||||
/// Whether this user ID is a historical one.
|
||||
@ -89,7 +67,7 @@ impl UserId {
|
||||
/// A historical user ID is one that doesn't conform to the latest specification of the user ID
|
||||
/// grammar but is still accepted because it was previously allowed.
|
||||
pub fn is_historical(&self) -> bool {
|
||||
self.is_historical
|
||||
!localpart_is_fully_conforming(self.localpart()).unwrap()
|
||||
}
|
||||
|
||||
/// Create a `matrix.to` reference for this user ID.
|
||||
@ -105,23 +83,13 @@ impl UserId {
|
||||
/// );
|
||||
/// ```
|
||||
pub fn matrix_to_url(&self) -> MatrixToRef<'_> {
|
||||
MatrixToRef::new(&self.full_id, Vec::new())
|
||||
}
|
||||
MatrixToRef::new(self.as_str(), Vec::new())
|
||||
}
|
||||
|
||||
/// Attempts to create a new Matrix user ID from a string representation.
|
||||
///
|
||||
/// The string must include the leading @ sigil, the localpart, a literal colon, and a server name.
|
||||
fn try_from<S>(user_id: S) -> Result<UserId, crate::Error>
|
||||
where
|
||||
S: AsRef<str> + Into<Box<str>>,
|
||||
{
|
||||
let (colon_idx, is_historical) =
|
||||
ruma_identifiers_validation::user_id::validate(user_id.as_ref())?;
|
||||
Ok(UserId { full_id: user_id.into(), colon_idx, is_historical: !is_historical })
|
||||
fn colon_idx(&self) -> usize {
|
||||
self.as_str().find(':').unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
common_impls!(UserId, try_from, "a Matrix user ID");
|
||||
|
||||
pub use ruma_identifiers_validation::user_id::localpart_is_fully_conforming;
|
||||
|
||||
@ -134,8 +102,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn valid_user_id_from_str() {
|
||||
let user_id = UserId::try_from("@carl:example.com").expect("Failed to create UserId.");
|
||||
assert_eq!(user_id.as_ref(), "@carl:example.com");
|
||||
let user_id = <&UserId>::try_from("@carl:example.com").expect("Failed to create UserId.");
|
||||
assert_eq!(user_id.as_str(), "@carl:example.com");
|
||||
assert_eq!(user_id.localpart(), "carl");
|
||||
assert_eq!(user_id.server_name(), "example.com");
|
||||
assert!(!user_id.is_historical());
|
||||
@ -146,7 +114,7 @@ mod tests {
|
||||
let server_name = server_name!("example.com");
|
||||
let user_id = UserId::parse_with_server_name("@carl:example.com", &server_name)
|
||||
.expect("Failed to create UserId.");
|
||||
assert_eq!(user_id.as_ref(), "@carl:example.com");
|
||||
assert_eq!(user_id.as_str(), "@carl:example.com");
|
||||
assert_eq!(user_id.localpart(), "carl");
|
||||
assert_eq!(user_id.server_name(), "example.com");
|
||||
assert!(!user_id.is_historical());
|
||||
@ -157,7 +125,7 @@ mod tests {
|
||||
let server_name = server_name!("example.com");
|
||||
let user_id =
|
||||
UserId::parse_with_server_name("carl", &server_name).expect("Failed to create UserId.");
|
||||
assert_eq!(user_id.as_ref(), "@carl:example.com");
|
||||
assert_eq!(user_id.as_str(), "@carl:example.com");
|
||||
assert_eq!(user_id.localpart(), "carl");
|
||||
assert_eq!(user_id.server_name(), "example.com");
|
||||
assert!(!user_id.is_historical());
|
||||
@ -165,8 +133,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn valid_historical_user_id() {
|
||||
let user_id = UserId::try_from("@a%b[irc]:example.com").expect("Failed to create UserId.");
|
||||
assert_eq!(user_id.as_ref(), "@a%b[irc]:example.com");
|
||||
let user_id =
|
||||
<&UserId>::try_from("@a%b[irc]:example.com").expect("Failed to create UserId.");
|
||||
assert_eq!(user_id.as_str(), "@a%b[irc]:example.com");
|
||||
assert_eq!(user_id.localpart(), "a%b[irc]");
|
||||
assert_eq!(user_id.server_name(), "example.com");
|
||||
assert!(user_id.is_historical());
|
||||
@ -177,7 +146,7 @@ mod tests {
|
||||
let server_name = server_name!("example.com");
|
||||
let user_id = UserId::parse_with_server_name("@a%b[irc]:example.com", &server_name)
|
||||
.expect("Failed to create UserId.");
|
||||
assert_eq!(user_id.as_ref(), "@a%b[irc]:example.com");
|
||||
assert_eq!(user_id.as_str(), "@a%b[irc]:example.com");
|
||||
assert_eq!(user_id.localpart(), "a%b[irc]");
|
||||
assert_eq!(user_id.server_name(), "example.com");
|
||||
assert!(user_id.is_historical());
|
||||
@ -188,7 +157,7 @@ mod tests {
|
||||
let server_name = server_name!("example.com");
|
||||
let user_id = UserId::parse_with_server_name("a%b[irc]", &server_name)
|
||||
.expect("Failed to create UserId.");
|
||||
assert_eq!(user_id.as_ref(), "@a%b[irc]:example.com");
|
||||
assert_eq!(user_id.as_str(), "@a%b[irc]:example.com");
|
||||
assert_eq!(user_id.localpart(), "a%b[irc]");
|
||||
assert_eq!(user_id.server_name(), "example.com");
|
||||
assert!(user_id.is_historical());
|
||||
@ -196,8 +165,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn uppercase_user_id() {
|
||||
let user_id = UserId::try_from("@CARL:example.com").expect("Failed to create UserId.");
|
||||
assert_eq!(user_id.as_ref(), "@CARL:example.com");
|
||||
let user_id = <&UserId>::try_from("@CARL:example.com").expect("Failed to create UserId.");
|
||||
assert_eq!(user_id.as_str(), "@CARL:example.com");
|
||||
assert!(user_id.is_historical());
|
||||
}
|
||||
|
||||
@ -220,7 +189,7 @@ mod tests {
|
||||
fn serialize_valid_user_id() {
|
||||
assert_eq!(
|
||||
serde_json::to_string(
|
||||
&UserId::try_from("@carl:example.com").expect("Failed to create UserId.")
|
||||
<&UserId>::try_from("@carl:example.com").expect("Failed to create UserId.")
|
||||
)
|
||||
.expect("Failed to convert UserId to JSON."),
|
||||
r#""@carl:example.com""#
|
||||
@ -231,52 +200,61 @@ mod tests {
|
||||
#[test]
|
||||
fn deserialize_valid_user_id() {
|
||||
assert_eq!(
|
||||
serde_json::from_str::<UserId>(r#""@carl:example.com""#)
|
||||
serde_json::from_str::<Box<UserId>>(r#""@carl:example.com""#)
|
||||
.expect("Failed to convert JSON to UserId"),
|
||||
UserId::try_from("@carl:example.com").expect("Failed to create UserId.")
|
||||
<&UserId>::try_from("@carl:example.com").expect("Failed to create UserId.")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_user_id_with_explicit_standard_port() {
|
||||
assert_eq!(
|
||||
UserId::try_from("@carl:example.com:443").expect("Failed to create UserId.").as_ref(),
|
||||
<&UserId>::try_from("@carl:example.com:443")
|
||||
.expect("Failed to create UserId.")
|
||||
.as_ref(),
|
||||
"@carl:example.com:443"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_user_id_with_non_standard_port() {
|
||||
let user_id = UserId::try_from("@carl:example.com:5000").expect("Failed to create UserId.");
|
||||
assert_eq!(user_id.as_ref(), "@carl:example.com:5000");
|
||||
let user_id =
|
||||
<&UserId>::try_from("@carl:example.com:5000").expect("Failed to create UserId.");
|
||||
assert_eq!(user_id.as_str(), "@carl:example.com:5000");
|
||||
assert!(!user_id.is_historical());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "compat"))]
|
||||
fn invalid_characters_in_user_id_localpart() {
|
||||
assert_eq!(UserId::try_from("@te\nst:example.com").unwrap_err(), Error::InvalidCharacters);
|
||||
assert_eq!(
|
||||
<&UserId>::try_from("@te\nst:example.com").unwrap_err(),
|
||||
Error::InvalidCharacters
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_user_id_sigil() {
|
||||
assert_eq!(UserId::try_from("carl:example.com").unwrap_err(), Error::MissingLeadingSigil);
|
||||
assert_eq!(
|
||||
<&UserId>::try_from("carl:example.com").unwrap_err(),
|
||||
Error::MissingLeadingSigil
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_user_id_delimiter() {
|
||||
assert_eq!(UserId::try_from("@carl").unwrap_err(), Error::MissingDelimiter);
|
||||
assert_eq!(<&UserId>::try_from("@carl").unwrap_err(), Error::MissingDelimiter);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_user_id_host() {
|
||||
assert_eq!(UserId::try_from("@carl:/").unwrap_err(), Error::InvalidServerName);
|
||||
assert_eq!(<&UserId>::try_from("@carl:/").unwrap_err(), Error::InvalidServerName);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_user_id_port() {
|
||||
assert_eq!(
|
||||
UserId::try_from("@carl:example.com:notaport").unwrap_err(),
|
||||
<&UserId>::try_from("@carl:example.com:notaport").unwrap_err(),
|
||||
Error::InvalidServerName
|
||||
);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ ruma_api! {
|
||||
pub medium: Medium,
|
||||
|
||||
/// The Matrix user ID associated with the 3PID.
|
||||
pub mxid: UserId,
|
||||
pub mxid: Box<UserId>,
|
||||
|
||||
/// A UNIX timestamp before which the association is not known to be valid.
|
||||
pub not_before: MilliSecondsSinceUnixEpoch,
|
||||
@ -63,7 +63,7 @@ impl Response {
|
||||
pub fn new(
|
||||
address: String,
|
||||
medium: Medium,
|
||||
mxid: UserId,
|
||||
mxid: Box<UserId>,
|
||||
not_before: MilliSecondsSinceUnixEpoch,
|
||||
not_after: MilliSecondsSinceUnixEpoch,
|
||||
ts: MilliSecondsSinceUnixEpoch,
|
||||
|
@ -18,7 +18,7 @@ ruma_api! {
|
||||
|
||||
response: {
|
||||
/// The user ID which registered the token.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ impl Request {
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given `UserId`.
|
||||
pub fn new(user_id: UserId) -> Self {
|
||||
pub fn new(user_id: Box<UserId>) -> Self {
|
||||
Self { user_id }
|
||||
}
|
||||
}
|
||||
|
@ -26,10 +26,10 @@ ruma_api! {
|
||||
|
||||
response: {
|
||||
/// The Matrix user ID of the user accepting the invitation.
|
||||
pub mxid: UserId,
|
||||
pub mxid: Box<UserId>,
|
||||
|
||||
/// The Matrix user ID of the user who sent the invitation.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
|
||||
/// The signature of the mxid, sender and token.
|
||||
pub signatures: ServerSignatures,
|
||||
@ -48,7 +48,12 @@ impl<'a> Request<'a> {
|
||||
|
||||
impl Response {
|
||||
/// Creates a `Response` with the given Matrix user ID, sender user ID, signatures and token.
|
||||
pub fn new(mxid: UserId, sender: UserId, signatures: ServerSignatures, token: String) -> Self {
|
||||
pub fn new(
|
||||
mxid: Box<UserId>,
|
||||
sender: Box<UserId>,
|
||||
signatures: ServerSignatures,
|
||||
token: String,
|
||||
) -> Self {
|
||||
Self { mxid, sender, signatures, token }
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ ruma_api! {
|
||||
///
|
||||
/// Addresses which do not have associations will not be included, which can make this
|
||||
/// property be an empty object.
|
||||
pub mappings: BTreeMap<String, UserId>,
|
||||
pub mappings: BTreeMap<String, Box<UserId>>,
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ impl<'a> Request<'a> {
|
||||
impl Response {
|
||||
/// Create a `Response` with the BTreeMap which map addresses from the request which were
|
||||
/// found to their corresponding User IDs.
|
||||
pub fn new(mappings: BTreeMap<String, UserId>) -> Self {
|
||||
pub fn new(mappings: BTreeMap<String, Box<UserId>>) -> Self {
|
||||
Self { mappings }
|
||||
}
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ mod tests {
|
||||
event_id: Some(eid),
|
||||
room_id: Some(rid),
|
||||
event_type: Some(&EventType::RoomMessage),
|
||||
sender: Some(&uid),
|
||||
sender: Some(uid),
|
||||
sender_display_name: Some("Major Tom"),
|
||||
room_alias: Some(alias),
|
||||
content: Some(serde_json::from_str("{}").unwrap()),
|
||||
|
@ -271,6 +271,7 @@ fn strip_lifetimes(field_type: &mut Type) -> bool {
|
||||
|| last_seg.ident == "RoomId"
|
||||
|| last_seg.ident == "RoomIdOrAliasId"
|
||||
|| last_seg.ident == "RoomName"
|
||||
|| last_seg.ident == "UserId"
|
||||
{
|
||||
// The identifiers that need to be boxed `Box<T>` since they are DST's.
|
||||
Some(parse_quote! { ::std::boxed::Box<#path> })
|
||||
|
@ -55,8 +55,8 @@ mod user {
|
||||
|
||||
const CARL: &str = "@carl:example.com";
|
||||
|
||||
fn carl() -> UserId {
|
||||
user_id!("@carl:example.com")
|
||||
fn carl() -> Box<UserId> {
|
||||
user_id!("@carl:example.com").to_owned()
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
@ -66,7 +66,7 @@ mod user {
|
||||
deserialize_with = "ruma_serde::empty_string_as_none",
|
||||
serialize_with = "ruma_serde::none_as_empty_string"
|
||||
)]
|
||||
x: Option<UserId>,
|
||||
x: Option<Box<UserId>>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3,8 +3,8 @@
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
convert::TryFrom,
|
||||
mem,
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use base64::{decode_config, encode_config, Config, STANDARD_NO_PAD, URL_SAFE_NO_PAD};
|
||||
@ -780,8 +780,8 @@ fn servers_to_check_signatures(
|
||||
if !is_third_party_invite(object)? {
|
||||
match object.get("sender") {
|
||||
Some(CanonicalJsonValue::String(raw_sender)) => {
|
||||
let user_id =
|
||||
UserId::from_str(raw_sender).map_err(|e| Error::from(ParseError::UserId(e)))?;
|
||||
let user_id = <&UserId>::try_from(raw_sender.as_str())
|
||||
.map_err(|e| Error::from(ParseError::UserId(e)))?;
|
||||
|
||||
servers_to_check.insert(user_id.server_name().to_owned());
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
convert::{TryFrom, TryInto},
|
||||
convert::TryInto,
|
||||
sync::{
|
||||
atomic::{AtomicU64, Ordering::SeqCst},
|
||||
Arc,
|
||||
@ -29,7 +29,7 @@ use ruma_events::{
|
||||
},
|
||||
EventType,
|
||||
};
|
||||
use ruma_identifiers::{room_id, EventId, RoomId, RoomVersionId, UserId};
|
||||
use ruma_identifiers::{room_id, user_id, EventId, RoomId, RoomVersionId, UserId};
|
||||
use ruma_state_res::{self as state_res, Error, Event, Result, StateMap};
|
||||
use serde_json::{
|
||||
json,
|
||||
@ -339,20 +339,20 @@ fn event_id(id: &str) -> Box<EventId> {
|
||||
format!("${}:foo", id).try_into().unwrap()
|
||||
}
|
||||
|
||||
fn alice() -> UserId {
|
||||
UserId::try_from("@alice:foo").unwrap()
|
||||
fn alice() -> Box<UserId> {
|
||||
user_id!("@alice:foo").to_owned()
|
||||
}
|
||||
|
||||
fn bob() -> UserId {
|
||||
UserId::try_from("@bob:foo").unwrap()
|
||||
fn bob() -> Box<UserId> {
|
||||
user_id!("@bob:foo").to_owned()
|
||||
}
|
||||
|
||||
fn charlie() -> UserId {
|
||||
UserId::try_from("@charlie:foo").unwrap()
|
||||
fn charlie() -> Box<UserId> {
|
||||
user_id!("@charlie:foo").to_owned()
|
||||
}
|
||||
|
||||
fn ella() -> UserId {
|
||||
UserId::try_from("@ella:foo").unwrap()
|
||||
fn ella() -> Box<UserId> {
|
||||
user_id!("@ella:foo").to_owned()
|
||||
}
|
||||
|
||||
fn room_id() -> &'static RoomId {
|
||||
@ -369,7 +369,7 @@ fn member_content_join() -> Box<RawJsonValue> {
|
||||
|
||||
fn to_pdu_event<S>(
|
||||
id: &str,
|
||||
sender: UserId,
|
||||
sender: Box<UserId>,
|
||||
ev_type: EventType,
|
||||
state_key: Option<&str>,
|
||||
content: Box<RawJsonValue>,
|
||||
|
@ -227,10 +227,10 @@ pub fn auth_check<E: Event>(
|
||||
}
|
||||
|
||||
let target_user =
|
||||
UserId::try_from(state_key).map_err(|e| Error::InvalidPdu(format!("{}", e)))?;
|
||||
<&UserId>::try_from(state_key).map_err(|e| Error::InvalidPdu(format!("{}", e)))?;
|
||||
|
||||
if !valid_membership_change(
|
||||
&target_user,
|
||||
target_user,
|
||||
fetch_state(&EventType::RoomMember, target_user.as_str()).as_ref(),
|
||||
sender,
|
||||
sender_member_event.as_ref(),
|
||||
|
@ -325,7 +325,7 @@ struct PowerLevelsContentFields {
|
||||
serde(deserialize_with = "ruma_serde::btreemap_int_or_string_to_int_values")
|
||||
)]
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
users: BTreeMap<UserId, Int>,
|
||||
users: BTreeMap<Box<UserId>, Int>,
|
||||
|
||||
#[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))]
|
||||
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
|
||||
|
@ -153,7 +153,7 @@ pub fn do_check(
|
||||
let ev_id = e.event_id();
|
||||
let event = to_pdu_event(
|
||||
e.event_id().as_str(),
|
||||
e.sender().clone(),
|
||||
e.sender().to_owned(),
|
||||
e.event_type().clone(),
|
||||
e.state_key(),
|
||||
e.content().to_owned(),
|
||||
@ -347,24 +347,24 @@ pub fn event_id(id: &str) -> Box<EventId> {
|
||||
format!("${}:foo", id).try_into().unwrap()
|
||||
}
|
||||
|
||||
pub fn alice() -> UserId {
|
||||
user_id!("@alice:foo")
|
||||
pub fn alice() -> Box<UserId> {
|
||||
user_id!("@alice:foo").to_owned()
|
||||
}
|
||||
|
||||
pub fn bob() -> UserId {
|
||||
user_id!("@bob:foo")
|
||||
pub fn bob() -> Box<UserId> {
|
||||
user_id!("@bob:foo").to_owned()
|
||||
}
|
||||
|
||||
pub fn charlie() -> UserId {
|
||||
user_id!("@charlie:foo")
|
||||
pub fn charlie() -> Box<UserId> {
|
||||
user_id!("@charlie:foo").to_owned()
|
||||
}
|
||||
|
||||
pub fn ella() -> UserId {
|
||||
user_id!("@ella:foo")
|
||||
pub fn ella() -> Box<UserId> {
|
||||
user_id!("@ella:foo").to_owned()
|
||||
}
|
||||
|
||||
pub fn zara() -> UserId {
|
||||
user_id!("@zara:foo")
|
||||
pub fn zara() -> Box<UserId> {
|
||||
user_id!("@zara:foo").to_owned()
|
||||
}
|
||||
|
||||
pub fn room_id() -> &'static RoomId {
|
||||
@ -381,7 +381,7 @@ pub fn member_content_join() -> Box<RawJsonValue> {
|
||||
|
||||
pub fn to_init_pdu_event(
|
||||
id: &str,
|
||||
sender: UserId,
|
||||
sender: Box<UserId>,
|
||||
ev_type: EventType,
|
||||
state_key: Option<&str>,
|
||||
content: Box<RawJsonValue>,
|
||||
@ -414,7 +414,7 @@ pub fn to_init_pdu_event(
|
||||
|
||||
pub fn to_pdu_event<S>(
|
||||
id: &str,
|
||||
sender: UserId,
|
||||
sender: Box<UserId>,
|
||||
ev_type: EventType,
|
||||
state_key: Option<&str>,
|
||||
content: Box<RawJsonValue>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user