Use new owned ID macros throught the codebase

This commit is contained in:
Jonas Platte 2023-06-20 11:47:50 +02:00
parent e71c224308
commit c5782ab8aa
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C
37 changed files with 172 additions and 182 deletions

View File

@ -87,15 +87,13 @@ pub mod v3 {
fn serialize_request() { fn serialize_request() {
use ruma_common::{ use ruma_common::{
api::{MatrixVersion, OutgoingRequest, SendAccessToken}, api::{MatrixVersion, OutgoingRequest, SendAccessToken},
user_id, owned_user_id,
}; };
use crate::filter::FilterDefinition; use crate::filter::FilterDefinition;
let req = super::Request::new( let req =
user_id!("@foo:bar.com").to_owned(), super::Request::new(owned_user_id!("@foo:bar.com"), FilterDefinition::default())
FilterDefinition::default(),
)
.try_into_http_request::<Vec<u8>>( .try_into_http_request::<Vec<u8>>(
"https://matrix.org", "https://matrix.org",
SendAccessToken::IfRequired("tok"), SendAccessToken::IfRequired("tok"),

View File

@ -120,7 +120,7 @@ pub mod v3 {
/// ///
/// ```rust /// ```rust
/// # use ruma_client_api::message::get_message_events; /// # use ruma_client_api::message::get_message_events;
/// # let room_id = ruma_common::room_id!("!a:example.org").to_owned(); /// # let room_id = ruma_common::owned_room_id!("!a:example.org");
/// # let token = "prev_batch token".to_owned(); /// # let token = "prev_batch token".to_owned();
/// let request = get_message_events::v3::Request::backward(room_id).from(token); /// let request = get_message_events::v3::Request::backward(room_id).from(token);
/// ``` /// ```
@ -137,7 +137,7 @@ pub mod v3 {
/// ///
/// ```rust /// ```rust
/// # use ruma_client_api::message::get_message_events; /// # use ruma_client_api::message::get_message_events;
/// # let room_id = ruma_common::room_id!("!a:example.org").to_owned(); /// # let room_id = ruma_common::owned_room_id!("!a:example.org");
/// # let token = "end token".to_owned(); /// # let token = "end token".to_owned();
/// let request = get_message_events::v3::Request::forward(room_id).from(token); /// let request = get_message_events::v3::Request::forward(room_id).from(token);
/// ``` /// ```
@ -175,7 +175,7 @@ pub mod v3 {
use js_int::uint; use js_int::uint;
use ruma_common::{ use ruma_common::{
api::{Direction, MatrixVersion, OutgoingRequest, SendAccessToken}, api::{Direction, MatrixVersion, OutgoingRequest, SendAccessToken},
room_id, owned_room_id,
}; };
use super::Request; use super::Request;
@ -183,15 +183,15 @@ pub mod v3 {
#[test] #[test]
fn serialize_some_room_event_filter() { fn serialize_some_room_event_filter() {
let room_id = room_id!("!roomid:example.org").to_owned(); let room_id = owned_room_id!("!roomid:example.org");
let rooms = vec![room_id.to_owned()]; let rooms = vec![room_id.to_owned()];
let filter = RoomEventFilter { let filter = RoomEventFilter {
lazy_load_options: LazyLoadOptions::Enabled { include_redundant_members: true }, lazy_load_options: LazyLoadOptions::Enabled { include_redundant_members: true },
rooms: Some(rooms), rooms: Some(rooms),
not_rooms: vec![ not_rooms: vec![
room_id!("!room:example.org").to_owned(), owned_room_id!("!room:example.org"),
room_id!("!room2:example.org").to_owned(), owned_room_id!("!room2:example.org"),
room_id!("!room3:example.org").to_owned(), owned_room_id!("!room3:example.org"),
], ],
not_types: vec!["type".into()], not_types: vec!["type".into()],
..Default::default() ..Default::default()
@ -224,7 +224,7 @@ pub mod v3 {
#[test] #[test]
fn serialize_default_room_event_filter() { fn serialize_default_room_event_filter() {
let room_id = room_id!("!roomid:example.org").to_owned(); let room_id = owned_room_id!("!roomid:example.org");
let req = Request { let req = Request {
room_id, room_id,
from: Some("token".to_owned()), from: Some("token".to_owned()),

View File

@ -210,12 +210,12 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{MatrixVersion, OutgoingRequest as _, SendAccessToken}, api::{MatrixVersion, OutgoingRequest as _, SendAccessToken},
events::{room::name::RoomNameEventContent, EmptyStateKey}, events::{room::name::RoomNameEventContent, EmptyStateKey},
room_id, owned_room_id,
}; };
// This used to panic in make_endpoint_url because of a mismatch in the path parameter count // This used to panic in make_endpoint_url because of a mismatch in the path parameter count
let req = Request::new( let req = Request::new(
room_id!("!room:server.tld").to_owned(), owned_room_id!("!room:server.tld"),
&EmptyStateKey, &EmptyStateKey,
&RoomNameEventContent::new(Some("Test room".to_owned())), &RoomNameEventContent::new(Some("Test room".to_owned())),
) )

View File

@ -67,13 +67,10 @@
//! # .await?; //! # .await?;
//! //!
//! use ruma_client_api::alias::get_alias; //! use ruma_client_api::alias::get_alias;
//! use ruma_common::{api::MatrixVersion, room_alias_id, room_id}; //! use ruma_common::{api::MatrixVersion, owned_room_alias_id, room_id};
//! //!
//! let response = client //! let alias = owned_room_alias_id!("#example_room:example.com");
//! .send_request(get_alias::v3::Request::new( //! let response = client.send_request(get_alias::v3::Request::new(alias)).await?;
//! room_alias_id!("#example_room:example.com").to_owned(),
//! ))
//! .await?;
//! //!
//! assert_eq!(response.room_id, room_id!("!n8f893n9:example.com")); //! assert_eq!(response.room_id, room_id!("!n8f893n9:example.com"));
//! # Result::<(), ruma_client::Error<_, _>>::Ok(()) //! # Result::<(), ruma_client::Error<_, _>>::Ok(())

View File

@ -55,12 +55,12 @@ mod tests {
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};
use super::IgnoredUserListEventContent; use super::IgnoredUserListEventContent;
use crate::{events::AnyGlobalAccountDataEvent, user_id}; use crate::{events::AnyGlobalAccountDataEvent, owned_user_id, user_id};
#[test] #[test]
fn serialization() { fn serialization() {
let ignored_user_list = let ignored_user_list =
IgnoredUserListEventContent::users(vec![user_id!("@carl:example.com").to_owned()]); IgnoredUserListEventContent::users(vec![owned_user_id!("@carl:example.com")]);
let json = json!({ let json = json!({
"ignored_users": { "ignored_users": {

View File

@ -51,11 +51,11 @@ mod tests {
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};
use super::KeyVerificationDoneEventContent; use super::KeyVerificationDoneEventContent;
use crate::{event_id, events::relation::Reference}; use crate::{events::relation::Reference, owned_event_id};
#[test] #[test]
fn serialization() { fn serialization() {
let event_id = event_id!("$1598361704261elfgc:localhost").to_owned(); let event_id = owned_event_id!("$1598361704261elfgc:localhost");
let json_data = json!({ let json_data = json!({
"m.relates_to": { "m.relates_to": {

View File

@ -78,14 +78,13 @@ mod tests {
use super::{KeyVerificationReadyEventContent, ToDeviceKeyVerificationReadyEventContent}; use super::{KeyVerificationReadyEventContent, ToDeviceKeyVerificationReadyEventContent};
use crate::{ use crate::{
event_id,
events::{key::verification::VerificationMethod, relation::Reference}, events::{key::verification::VerificationMethod, relation::Reference},
OwnedDeviceId, owned_event_id, OwnedDeviceId,
}; };
#[test] #[test]
fn serialization() { fn serialization() {
let event_id = event_id!("$1598361704261elfgc:localhost").to_owned(); let event_id = owned_event_id!("$1598361704261elfgc:localhost");
let device: OwnedDeviceId = "123".into(); let device: OwnedDeviceId = "123".into();
let json_data = json!({ let json_data = json!({

View File

@ -40,7 +40,7 @@ mod tests {
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};
use super::ReactionEventContent; use super::ReactionEventContent;
use crate::{event_id, events::relation::Annotation}; use crate::{events::relation::Annotation, owned_event_id};
#[test] #[test]
fn deserialize() { fn deserialize() {
@ -63,7 +63,7 @@ mod tests {
#[test] #[test]
fn serialize() { fn serialize() {
let content = ReactionEventContent::new(Annotation::new( let content = ReactionEventContent::new(Annotation::new(
event_id!("$my_reaction").to_owned(), owned_event_id!("$my_reaction"),
"🏠".to_owned(), "🏠".to_owned(),
)); ));

View File

@ -215,7 +215,7 @@ mod tests {
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};
use super::{Receipt, ReceiptThread}; use super::{Receipt, ReceiptThread};
use crate::{event_id, MilliSecondsSinceUnixEpoch}; use crate::{owned_event_id, MilliSecondsSinceUnixEpoch};
#[test] #[test]
fn serialize_receipt() { fn serialize_receipt() {
@ -225,7 +225,7 @@ mod tests {
receipt.thread = ReceiptThread::Main; receipt.thread = ReceiptThread::Main;
assert_eq!(to_json_value(receipt.clone()).unwrap(), json!({ "thread_id": "main" })); assert_eq!(to_json_value(receipt.clone()).unwrap(), json!({ "thread_id": "main" }));
receipt.thread = ReceiptThread::Thread(event_id!("$abcdef76543").to_owned()); receipt.thread = ReceiptThread::Thread(owned_event_id!("$abcdef76543"));
assert_eq!(to_json_value(receipt).unwrap(), json!({ "thread_id": "$abcdef76543" })); assert_eq!(to_json_value(receipt).unwrap(), json!({ "thread_id": "$abcdef76543" }));
let mut receipt = let mut receipt =

View File

@ -42,12 +42,12 @@ mod tests {
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};
use super::RoomCanonicalAliasEventContent; use super::RoomCanonicalAliasEventContent;
use crate::{events::OriginalStateEvent, room_alias_id}; use crate::{events::OriginalStateEvent, owned_room_alias_id};
#[test] #[test]
fn serialization_with_optional_fields_as_none() { fn serialization_with_optional_fields_as_none() {
let content = RoomCanonicalAliasEventContent { let content = RoomCanonicalAliasEventContent {
alias: Some(room_alias_id!("#somewhere:localhost").to_owned()), alias: Some(owned_room_alias_id!("#somewhere:localhost")),
alt_aliases: Vec::new(), alt_aliases: Vec::new(),
}; };
@ -126,7 +126,7 @@ mod tests {
#[test] #[test]
fn nonempty_field_as_some() { fn nonempty_field_as_some() {
let alias = Some(room_alias_id!("#somewhere:localhost").to_owned()); let alias = Some(owned_room_alias_id!("#somewhere:localhost"));
let json_data = json!({ let json_data = json!({
"content": { "content": {
"alias": "#somewhere:localhost" "alias": "#somewhere:localhost"

View File

@ -91,12 +91,12 @@ mod tests {
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};
use super::{RoomCreateEventContent, RoomType}; use super::{RoomCreateEventContent, RoomType};
use crate::{user_id, RoomVersionId}; use crate::{owned_user_id, RoomVersionId};
#[test] #[test]
fn serialization() { fn serialization() {
let content = RoomCreateEventContent { let content = RoomCreateEventContent {
creator: user_id!("@carl:example.com").to_owned(), creator: owned_user_id!("@carl:example.com"),
federate: false, federate: false,
room_version: RoomVersionId::V4, room_version: RoomVersionId::V4,
predecessor: None, predecessor: None,
@ -115,7 +115,7 @@ mod tests {
#[test] #[test]
fn space_serialization() { fn space_serialization() {
let content = RoomCreateEventContent { let content = RoomCreateEventContent {
creator: user_id!("@carl:example.com").to_owned(), creator: owned_user_id!("@carl:example.com"),
federate: false, federate: false,
room_version: RoomVersionId::V4, room_version: RoomVersionId::V4,
predecessor: None, predecessor: None,

View File

@ -251,7 +251,7 @@ mod tests {
EncryptedEventScheme, InReplyTo, MegolmV1AesSha2ContentInit, Relation, EncryptedEventScheme, InReplyTo, MegolmV1AesSha2ContentInit, Relation,
RoomEncryptedEventContent, RoomEncryptedEventContent,
}; };
use crate::{event_id, serde::Raw}; use crate::{owned_event_id, serde::Raw};
#[test] #[test]
fn serialization() { fn serialization() {
@ -266,7 +266,7 @@ mod tests {
.into(), .into(),
), ),
relates_to: Some(Relation::Reply { relates_to: Some(Relation::Reply {
in_reply_to: InReplyTo { event_id: event_id!("$h29iv0s8:example.com").to_owned() }, in_reply_to: InReplyTo { event_id: owned_event_id!("$h29iv0s8:example.com") },
}), }),
}; };

View File

@ -248,7 +248,7 @@ mod tests {
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use super::{AllowRule, JoinRule, OriginalSyncRoomJoinRulesEvent, RoomJoinRulesEventContent}; use super::{AllowRule, JoinRule, OriginalSyncRoomJoinRulesEvent, RoomJoinRulesEventContent};
use crate::room_id; use crate::owned_room_id;
#[test] #[test]
fn deserialize() { fn deserialize() {
@ -277,8 +277,8 @@ mod tests {
JoinRule::Restricted(restricted) => assert_eq!( JoinRule::Restricted(restricted) => assert_eq!(
restricted.allow, restricted.allow,
&[ &[
AllowRule::room_membership(room_id!("!mods:example.org").to_owned()), AllowRule::room_membership(owned_room_id!("!mods:example.org")),
AllowRule::room_membership(room_id!("!users:example.org").to_owned()) AllowRule::room_membership(owned_room_id!("!users:example.org"))
] ]
), ),
rule => panic!("Deserialized to wrong variant: {rule:?}"), rule => panic!("Deserialized to wrong variant: {rule:?}"),

View File

@ -542,8 +542,8 @@ mod tests {
use super::{MembershipState, RoomMemberEventContent}; use super::{MembershipState, RoomMemberEventContent};
use crate::{ use crate::{
events::OriginalStateEvent, mxc_uri, serde::CanBeEmpty, server_name, server_signing_key_id, events::OriginalStateEvent, mxc_uri, owned_server_signing_key_id, serde::CanBeEmpty,
user_id, MilliSecondsSinceUnixEpoch, server_name, user_id, MilliSecondsSinceUnixEpoch,
}; };
#[test] #[test]
@ -667,7 +667,7 @@ mod tests {
third_party_invite.signed.signatures, third_party_invite.signed.signatures,
btreemap! { btreemap! {
server_name!("magic.forest").to_owned() => btreemap! { server_name!("magic.forest").to_owned() => btreemap! {
server_signing_key_id!("ed25519:3").to_owned() => "foobar".to_owned() owned_server_signing_key_id!("ed25519:3") => "foobar".to_owned()
} }
} }
); );
@ -737,7 +737,7 @@ mod tests {
third_party_invite.signed.signatures, third_party_invite.signed.signatures,
btreemap! { btreemap! {
server_name!("magic.forest").to_owned() => btreemap! { server_name!("magic.forest").to_owned() => btreemap! {
server_signing_key_id!("ed25519:3").to_owned() => "foobar".to_owned() owned_server_signing_key_id!("ed25519:3") => "foobar".to_owned()
} }
} }
); );

View File

@ -125,9 +125,8 @@ pub fn plain_and_formatted_reply_body(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{
event_id,
events::{room::message::RoomMessageEventContent, MessageLikeUnsigned}, events::{room::message::RoomMessageEventContent, MessageLikeUnsigned},
room_id, user_id, MilliSecondsSinceUnixEpoch, owned_event_id, owned_room_id, owned_user_id, MilliSecondsSinceUnixEpoch,
}; };
use super::OriginalRoomMessageEvent; use super::OriginalRoomMessageEvent;
@ -137,10 +136,10 @@ mod tests {
let (plain_quote, html_quote) = let (plain_quote, html_quote) =
super::get_message_quote_fallbacks(&OriginalRoomMessageEvent { super::get_message_quote_fallbacks(&OriginalRoomMessageEvent {
content: RoomMessageEventContent::text_plain("multi\nline"), content: RoomMessageEventContent::text_plain("multi\nline"),
event_id: event_id!("$1598361704261elfgc:localhost").to_owned(), event_id: owned_event_id!("$1598361704261elfgc:localhost"),
sender: user_id!("@alice:example.com").to_owned(), sender: owned_user_id!("@alice:example.com"),
origin_server_ts: MilliSecondsSinceUnixEpoch::now(), origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
room_id: room_id!("!n8f893n9:example.com").to_owned(), room_id: owned_room_id!("!n8f893n9:example.com"),
unsigned: MessageLikeUnsigned::new(), unsigned: MessageLikeUnsigned::new(),
}); });

View File

@ -44,7 +44,7 @@ impl ToDeviceRoomKeyEventContent {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{room_id, EventEncryptionAlgorithm}; use crate::{owned_room_id, EventEncryptionAlgorithm};
use serde_json::{json, to_value as to_json_value}; use serde_json::{json, to_value as to_json_value};
use super::ToDeviceRoomKeyEventContent; use super::ToDeviceRoomKeyEventContent;
@ -53,7 +53,7 @@ mod tests {
fn serialization() { fn serialization() {
let content = ToDeviceRoomKeyEventContent { let content = ToDeviceRoomKeyEventContent {
algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2, algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2,
room_id: room_id!("!testroomid:example.org").to_owned(), room_id: owned_room_id!("!testroomid:example.org"),
session_id: "SessId".into(), session_id: "SessId".into(),
session_key: "SessKey".into(), session_key: "SessKey".into(),
}; };

View File

@ -990,9 +990,9 @@ mod tests {
AnyPushRule, ConditionalPushRule, PatternedPushRule, Ruleset, SimplePushRule, AnyPushRule, ConditionalPushRule, PatternedPushRule, Ruleset, SimplePushRule,
}; };
use crate::{ use crate::{
owned_room_id, owned_user_id,
power_levels::NotificationPowerLevels, power_levels::NotificationPowerLevels,
push::{PredefinedContentRuleId, PredefinedOverrideRuleId}, push::{PredefinedContentRuleId, PredefinedOverrideRuleId},
room_id,
serde::Raw, serde::Raw,
user_id, user_id,
}; };
@ -1124,7 +1124,7 @@ mod tests {
actions: vec![Action::Notify], actions: vec![Action::Notify],
default: false, default: false,
enabled: false, enabled: false,
rule_id: room_id!("!roomid:server.name").to_owned(), rule_id: owned_room_id!("!roomid:server.name"),
}; };
let rule_value: JsonValue = to_json_value(rule).unwrap(); let rule_value: JsonValue = to_json_value(rule).unwrap();
@ -1425,9 +1425,9 @@ mod tests {
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 { let context_one_to_one = &PushConditionRoomCtx {
room_id: room_id!("!dm:server.name").to_owned(), room_id: owned_room_id!("!dm:server.name"),
member_count: uint!(2), member_count: uint!(2),
user_id: user_id!("@jj:server.name").to_owned(), user_id: owned_user_id!("@jj:server.name"),
user_display_name: "Jolly Jumper".into(), user_display_name: "Jolly Jumper".into(),
users_power_levels: BTreeMap::new(), users_power_levels: BTreeMap::new(),
default_power_level: int!(50), default_power_level: int!(50),
@ -1437,9 +1437,9 @@ mod tests {
}; };
let context_public_room = &PushConditionRoomCtx { let context_public_room = &PushConditionRoomCtx {
room_id: room_id!("!far_west:server.name").to_owned(), room_id: owned_room_id!("!far_west:server.name"),
member_count: uint!(100), member_count: uint!(100),
user_id: user_id!("@jj:server.name").to_owned(), user_id: owned_user_id!("@jj:server.name"),
user_display_name: "Jolly Jumper".into(), user_display_name: "Jolly Jumper".into(),
users_power_levels: BTreeMap::new(), users_power_levels: BTreeMap::new(),
default_power_level: int!(50), default_power_level: int!(50),
@ -1530,9 +1530,9 @@ mod tests {
#[test] #[test]
fn custom_ruleset_applies() { fn custom_ruleset_applies() {
let context_one_to_one = &PushConditionRoomCtx { let context_one_to_one = &PushConditionRoomCtx {
room_id: room_id!("!dm:server.name").to_owned(), room_id: owned_room_id!("!dm:server.name"),
member_count: uint!(2), member_count: uint!(2),
user_id: user_id!("@jj:server.name").to_owned(), user_id: owned_user_id!("@jj:server.name"),
user_display_name: "Jolly Jumper".into(), user_display_name: "Jolly Jumper".into(),
users_power_levels: BTreeMap::new(), users_power_levels: BTreeMap::new(),
default_power_level: int!(50), default_power_level: int!(50),
@ -1587,7 +1587,7 @@ mod tests {
actions: vec![Action::Notify], actions: vec![Action::Notify],
default: false, default: false,
enabled: true, enabled: true,
rule_id: user_id!("@rantanplan:server.name").to_owned(), rule_id: owned_user_id!("@rantanplan:server.name"),
}; };
set.sender.insert(sender); set.sender.insert(sender);
@ -1598,7 +1598,7 @@ mod tests {
actions: vec![Action::SetTweak(Tweak::Highlight(true))], actions: vec![Action::SetTweak(Tweak::Highlight(true))],
default: false, default: false,
enabled: true, enabled: true,
rule_id: room_id!("!dm:server.name").to_owned(), rule_id: owned_room_id!("!dm:server.name"),
}; };
set.room.insert(room); set.room.insert(room);
@ -1671,9 +1671,9 @@ mod tests {
let set = Ruleset::server_default(user_id!("@jolly_jumper:server.name")); let set = Ruleset::server_default(user_id!("@jolly_jumper:server.name"));
let context = &PushConditionRoomCtx { let context = &PushConditionRoomCtx {
room_id: room_id!("!far_west:server.name").to_owned(), room_id: owned_room_id!("!far_west:server.name"),
member_count: uint!(100), member_count: uint!(100),
user_id: user_id!("@jj:server.name").to_owned(), user_id: owned_user_id!("@jj:server.name"),
user_display_name: "Jolly Jumper".into(), user_display_name: "Jolly Jumper".into(),
users_power_levels: BTreeMap::new(), users_power_levels: BTreeMap::new(),
default_power_level: int!(50), default_power_level: int!(50),
@ -1783,9 +1783,9 @@ mod tests {
let set = Ruleset::server_default(user_id!("@jolly_jumper:server.name")); let set = Ruleset::server_default(user_id!("@jolly_jumper:server.name"));
let context = &PushConditionRoomCtx { let context = &PushConditionRoomCtx {
room_id: room_id!("!far_west:server.name").to_owned(), room_id: owned_room_id!("!far_west:server.name"),
member_count: uint!(100), member_count: uint!(100),
user_id: user_id!("@jj:server.name").to_owned(), user_id: owned_user_id!("@jj:server.name"),
user_display_name: "Jolly Jumper".into(), user_display_name: "Jolly Jumper".into(),
users_power_levels: BTreeMap::new(), users_power_levels: BTreeMap::new(),
default_power_level: int!(50), default_power_level: int!(50),

View File

@ -451,7 +451,10 @@ mod tests {
}; };
use super::{FlattenedJson, PushCondition, PushConditionRoomCtx, RoomMemberCountIs, StrExt}; use super::{FlattenedJson, PushCondition, PushConditionRoomCtx, RoomMemberCountIs, StrExt};
use crate::{power_levels::NotificationPowerLevels, room_id, serde::Raw, user_id, OwnedUserId}; use crate::{
owned_room_id, owned_user_id, power_levels::NotificationPowerLevels, serde::Raw,
OwnedUserId,
};
#[test] #[test]
fn serialize_event_match_condition() { fn serialize_event_match_condition() {
@ -639,7 +642,7 @@ mod tests {
} }
fn sender() -> OwnedUserId { fn sender() -> OwnedUserId {
user_id!("@worthy_whale:server.name").to_owned() owned_user_id!("@worthy_whale:server.name")
} }
fn push_context() -> PushConditionRoomCtx { fn push_context() -> PushConditionRoomCtx {
@ -647,9 +650,9 @@ mod tests {
users_power_levels.insert(sender(), int!(25)); users_power_levels.insert(sender(), int!(25));
PushConditionRoomCtx { PushConditionRoomCtx {
room_id: room_id!("!room:server.name").to_owned(), room_id: owned_room_id!("!room:server.name"),
member_count: uint!(3), member_count: uint!(3),
user_id: user_id!("@gorilla:server.name").to_owned(), user_id: owned_user_id!("@gorilla:server.name"),
user_display_name: "Groovy Gorilla".into(), user_display_name: "Groovy Gorilla".into(),
users_power_levels, users_power_levels,
default_power_level: int!(50), default_power_level: int!(50),
@ -768,9 +771,9 @@ mod tests {
let context_not_matching = push_context(); let context_not_matching = push_context();
let context_matching = PushConditionRoomCtx { let context_matching = PushConditionRoomCtx {
room_id: room_id!("!room:server.name").to_owned(), room_id: owned_room_id!("!room:server.name"),
member_count: uint!(3), member_count: uint!(3),
user_id: user_id!("@gorilla:server.name").to_owned(), user_id: owned_user_id!("@gorilla:server.name"),
user_display_name: "Groovy Gorilla".into(), user_display_name: "Groovy Gorilla".into(),
users_power_levels: context_not_matching.users_power_levels.clone(), users_power_levels: context_not_matching.users_power_levels.clone(),
default_power_level: int!(50), default_power_level: int!(50),

View File

@ -6,7 +6,7 @@ use ruma_common::{
request, response, IncomingRequest as _, MatrixVersion, Metadata, OutgoingRequest as _, request, response, IncomingRequest as _, MatrixVersion, Metadata, OutgoingRequest as _,
OutgoingRequestAppserviceExt, SendAccessToken, OutgoingRequestAppserviceExt, SendAccessToken,
}, },
metadata, user_id, OwnedUserId, metadata, owned_user_id, user_id, OwnedUserId,
}; };
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
@ -59,7 +59,7 @@ fn request_serde() {
q1: "query_param_special_chars %/&@!".to_owned(), q1: "query_param_special_chars %/&@!".to_owned(),
q2: 55, q2: 55,
bar: "barVal".to_owned(), bar: "barVal".to_owned(),
user: user_id!("@bazme:ruma.io").to_owned(), user: owned_user_id!("@bazme:ruma.io"),
}; };
let http_req = req let http_req = req
@ -88,7 +88,7 @@ fn invalid_uri_should_not_panic() {
q1: "query_param_special_chars %/&@!".to_owned(), q1: "query_param_special_chars %/&@!".to_owned(),
q2: 55, q2: 55,
bar: "barVal".to_owned(), bar: "barVal".to_owned(),
user: user_id!("@bazme:ruma.io").to_owned(), user: owned_user_id!("@bazme:ruma.io"),
}; };
let result = req.try_into_http_request::<Vec<u8>>( let result = req.try_into_http_request::<Vec<u8>>(
@ -107,7 +107,7 @@ fn request_with_user_id_serde() {
q1: "query_param_special_chars %/&@!".to_owned(), q1: "query_param_special_chars %/&@!".to_owned(),
q2: 55, q2: 55,
bar: "barVal".to_owned(), bar: "barVal".to_owned(),
user: user_id!("@bazme:ruma.io").to_owned(), user: owned_user_id!("@bazme:ruma.io"),
}; };
let user_id = user_id!("@_virtual_:ruma.io"); let user_id = user_id!("@_virtual_:ruma.io");
@ -135,7 +135,7 @@ mod without_query {
request, response, MatrixVersion, Metadata, OutgoingRequestAppserviceExt, request, response, MatrixVersion, Metadata, OutgoingRequestAppserviceExt,
SendAccessToken, SendAccessToken,
}, },
metadata, user_id, OwnedUserId, metadata, owned_user_id, user_id, OwnedUserId,
}; };
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
@ -180,7 +180,7 @@ mod without_query {
hello: "hi".to_owned(), hello: "hi".to_owned(),
world: "test".to_owned(), world: "test".to_owned(),
bar: "barVal".to_owned(), bar: "barVal".to_owned(),
user: user_id!("@bazme:ruma.io").to_owned(), user: owned_user_id!("@bazme:ruma.io"),
}; };
let user_id = user_id!("@_virtual_:ruma.io"); let user_id = user_id!("@_virtual_:ruma.io");

View File

@ -7,7 +7,6 @@ use js_int::uint;
#[cfg(feature = "unstable-msc3246")] #[cfg(feature = "unstable-msc3246")]
use ruma_common::events::audio::Amplitude; use ruma_common::events::audio::Amplitude;
use ruma_common::{ use ruma_common::{
event_id,
events::{ events::{
audio::{AudioDetailsContentBlock, AudioEventContent}, audio::{AudioDetailsContentBlock, AudioEventContent},
file::{EncryptedContentInit, FileContentBlock}, file::{EncryptedContentInit, FileContentBlock},
@ -16,7 +15,7 @@ use ruma_common::{
room::{message::Relation, JsonWebKeyInit}, room::{message::Relation, JsonWebKeyInit},
AnyMessageLikeEvent, MessageLikeEvent, AnyMessageLikeEvent, MessageLikeEvent,
}, },
mxc_uri, mxc_uri, owned_event_id,
serde::{Base64, CanBeEmpty}, serde::{Base64, CanBeEmpty},
MilliSecondsSinceUnixEpoch, MilliSecondsSinceUnixEpoch,
}; };
@ -122,7 +121,7 @@ fn event_serialization() {
content.file.size = Some(uint!(897_774)); content.file.size = Some(uint!(897_774));
content.audio_details = Some(AudioDetailsContentBlock::new(Duration::from_secs(123))); content.audio_details = Some(AudioDetailsContentBlock::new(Duration::from_secs(123)));
content.relates_to = Some(Relation::Reply { content.relates_to = Some(Relation::Reply {
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()), in_reply_to: InReplyTo::new(owned_event_id!("$replyevent:example.com")),
}); });
assert_eq!( assert_eq!(

View File

@ -1,6 +1,5 @@
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use ruma_common::{ use ruma_common::{
device_id, event_id,
events::{ events::{
relation::{InReplyTo, Reference, Thread}, relation::{InReplyTo, Reference, Thread},
room::encrypted::{ room::encrypted::{
@ -8,6 +7,7 @@ use ruma_common::{
RoomEncryptedEventContent, RoomEncryptedEventContent,
}, },
}, },
owned_device_id, owned_event_id,
}; };
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};
@ -22,7 +22,7 @@ fn encrypted_scheme() -> EncryptedEventScheme {
lDl5mzVO3tPnJMKZ0hn+AF" lDl5mzVO3tPnJMKZ0hn+AF"
.to_owned(), .to_owned(),
sender_key: "aV9BpqYFqJpKYmgERyGv/6QyKMcgLqxM05V0gvzg9Yk".to_owned(), sender_key: "aV9BpqYFqJpKYmgERyGv/6QyKMcgLqxM05V0gvzg9Yk".to_owned(),
device_id: device_id!("DEVICE").to_owned(), device_id: owned_device_id!("DEVICE"),
session_id: "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw".to_owned(), session_id: "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw".to_owned(),
} }
.into(), .into(),
@ -86,9 +86,7 @@ fn content_no_relation_deserialization() {
fn content_reply_serialization() { fn content_reply_serialization() {
let content = RoomEncryptedEventContent::new( let content = RoomEncryptedEventContent::new(
encrypted_scheme(), encrypted_scheme(),
Some(Relation::Reply { Some(Relation::Reply { in_reply_to: InReplyTo::new(owned_event_id!("$replied_to_event")) }),
in_reply_to: InReplyTo::new(event_id!("$replied_to_event").to_owned()),
}),
); );
assert_eq!( assert_eq!(
@ -155,7 +153,7 @@ fn content_reply_deserialization() {
fn content_replacement_serialization() { fn content_replacement_serialization() {
let content = RoomEncryptedEventContent::new( let content = RoomEncryptedEventContent::new(
encrypted_scheme(), encrypted_scheme(),
Some(Relation::Replacement(Replacement::new(event_id!("$replaced_event").to_owned()))), Some(Relation::Replacement(Replacement::new(owned_event_id!("$replaced_event")))),
); );
assert_eq!( assert_eq!(
@ -220,7 +218,7 @@ fn content_replacement_deserialization() {
fn content_reference_serialization() { fn content_reference_serialization() {
let content = RoomEncryptedEventContent::new( let content = RoomEncryptedEventContent::new(
encrypted_scheme(), encrypted_scheme(),
Some(Relation::Reference(Reference::new(event_id!("$referenced_event").to_owned()))), Some(Relation::Reference(Reference::new(owned_event_id!("$referenced_event")))),
); );
assert_eq!( assert_eq!(
@ -286,8 +284,8 @@ fn content_thread_serialization() {
let content = RoomEncryptedEventContent::new( let content = RoomEncryptedEventContent::new(
encrypted_scheme(), encrypted_scheme(),
Some(Relation::Thread(Thread::plain( Some(Relation::Thread(Thread::plain(
event_id!("$thread_root").to_owned(), owned_event_id!("$thread_root"),
event_id!("$prev_event").to_owned(), owned_event_id!("$prev_event"),
))), ))),
); );
@ -365,7 +363,7 @@ fn content_annotation_serialization() {
let content = RoomEncryptedEventContent::new( let content = RoomEncryptedEventContent::new(
encrypted_scheme(), encrypted_scheme(),
Some(Relation::Annotation(Annotation::new( Some(Relation::Annotation(Annotation::new(
event_id!("$annotated_event").to_owned(), owned_event_id!("$annotated_event"),
"some_key".to_owned(), "some_key".to_owned(),
))), ))),
); );

View File

@ -1,7 +1,10 @@
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use js_int::uint; use js_int::uint;
use maplit::btreemap; use maplit::btreemap;
use ruma_common::{event_id, events::receipt::ReceiptType, user_id, MilliSecondsSinceUnixEpoch}; use ruma_common::{
event_id, events::receipt::ReceiptType, owned_event_id, owned_user_id, user_id,
MilliSecondsSinceUnixEpoch,
};
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};
use ruma_common::events::{ use ruma_common::events::{
@ -12,7 +15,7 @@ use ruma_common::events::{
#[test] #[test]
fn ephemeral_serialize_typing() { fn ephemeral_serialize_typing() {
let content = TypingEventContent::new(vec![user_id!("@carl:example.com").to_owned()]); let content = TypingEventContent::new(vec![owned_user_id!("@carl:example.com")]);
let actual = to_json_value(&content).unwrap(); let actual = to_json_value(&content).unwrap();
let expected = json!({ let expected = json!({
@ -43,8 +46,8 @@ fn deserialize_ephemeral_typing() {
#[test] #[test]
fn ephemeral_serialize_receipt() { fn ephemeral_serialize_receipt() {
let event_id = event_id!("$h29iv0s8:example.com").to_owned(); let event_id = owned_event_id!("$h29iv0s8:example.com");
let user_id = user_id!("@carl:example.com").to_owned(); let user_id = owned_user_id!("@carl:example.com");
let content = ReceiptEventContent(btreemap! { let content = ReceiptEventContent(btreemap! {
event_id => btreemap! { event_id => btreemap! {

View File

@ -3,7 +3,6 @@
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use js_int::uint; use js_int::uint;
use ruma_common::{ use ruma_common::{
event_id,
events::{ events::{
file::{EncryptedContentInit, FileEventContent}, file::{EncryptedContentInit, FileEventContent},
message::TextContentBlock, message::TextContentBlock,
@ -11,7 +10,7 @@ use ruma_common::{
room::{message::Relation, JsonWebKeyInit}, room::{message::Relation, JsonWebKeyInit},
AnyMessageLikeEvent, MessageLikeEvent, AnyMessageLikeEvent, MessageLikeEvent,
}, },
mxc_uri, mxc_uri, owned_event_id,
serde::{Base64, CanBeEmpty}, serde::{Base64, CanBeEmpty},
MilliSecondsSinceUnixEpoch, MilliSecondsSinceUnixEpoch,
}; };
@ -101,7 +100,7 @@ fn file_event_serialization() {
content.file.mimetype = Some("text/plain".to_owned()); content.file.mimetype = Some("text/plain".to_owned());
content.file.size = Some(uint!(774)); content.file.size = Some(uint!(774));
content.relates_to = Some(Relation::Reply { content.relates_to = Some(Relation::Reply {
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()), in_reply_to: InReplyTo::new(owned_event_id!("$replyevent:example.com")),
}); });
assert_eq!( assert_eq!(

View File

@ -3,7 +3,6 @@
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use js_int::uint; use js_int::uint;
use ruma_common::{ use ruma_common::{
event_id,
events::{ events::{
file::{CaptionContentBlock, EncryptedContentInit, FileContentBlock}, file::{CaptionContentBlock, EncryptedContentInit, FileContentBlock},
image::{ image::{
@ -15,7 +14,7 @@ use ruma_common::{
room::{message::Relation, JsonWebKeyInit}, room::{message::Relation, JsonWebKeyInit},
AnyMessageLikeEvent, MessageLikeEvent, AnyMessageLikeEvent, MessageLikeEvent,
}, },
mxc_uri, mxc_uri, owned_event_id,
serde::{Base64, CanBeEmpty}, serde::{Base64, CanBeEmpty},
MilliSecondsSinceUnixEpoch, MilliSecondsSinceUnixEpoch,
}; };
@ -123,7 +122,7 @@ fn image_event_serialization() {
content.thumbnail = vec![thumbnail].into(); content.thumbnail = vec![thumbnail].into();
content.caption = Some(CaptionContentBlock::plain("This is my house")); content.caption = Some(CaptionContentBlock::plain("This is my house"));
content.relates_to = Some(Relation::Reply { content.relates_to = Some(Relation::Reply {
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()), in_reply_to: InReplyTo::new(owned_event_id!("$replyevent:example.com")),
}); });
assert_eq!( assert_eq!(

View File

@ -12,7 +12,7 @@ use ruma_common::{
room::message::Relation, room::message::Relation,
AnyMessageLikeEvent, MessageLikeEvent, AnyMessageLikeEvent, MessageLikeEvent,
}, },
room_id, owned_event_id, room_id,
serde::CanBeEmpty, serde::CanBeEmpty,
user_id, MilliSecondsSinceUnixEpoch, user_id, MilliSecondsSinceUnixEpoch,
}; };
@ -57,7 +57,7 @@ fn event_serialization() {
{ {
ts: Some(MilliSecondsSinceUnixEpoch(uint!(1_636_829_458))), ts: Some(MilliSecondsSinceUnixEpoch(uint!(1_636_829_458))),
relates_to: Some(Relation::Reply { relates_to: Some(Relation::Reply {
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()), in_reply_to: InReplyTo::new(owned_event_id!("$replyevent:example.com")),
}), }),
} }
); );

View File

@ -4,7 +4,6 @@ use assert_matches2::assert_matches;
use assign::assign; use assign::assign;
use js_int::uint; use js_int::uint;
use ruma_common::{ use ruma_common::{
event_id,
events::{ events::{
emote::EmoteEventContent, emote::EmoteEventContent,
message::{MessageEventContent, TextContentBlock, TextRepresentation}, message::{MessageEventContent, TextContentBlock, TextRepresentation},
@ -12,6 +11,7 @@ use ruma_common::{
room::message::Relation, room::message::Relation,
AnyMessageLikeEvent, MessageLikeEvent, AnyMessageLikeEvent, MessageLikeEvent,
}, },
owned_event_id,
serde::CanBeEmpty, serde::CanBeEmpty,
MilliSecondsSinceUnixEpoch, MilliSecondsSinceUnixEpoch,
}; };
@ -134,7 +134,7 @@ fn relates_to_content_serialization() {
assign!(MessageEventContent::plain("> <@test:example.com> test\n\ntest reply"), { assign!(MessageEventContent::plain("> <@test:example.com> test\n\ntest reply"), {
relates_to: Some(Relation::Reply { relates_to: Some(Relation::Reply {
in_reply_to: InReplyTo::new( in_reply_to: InReplyTo::new(
event_id!("$15827405538098VGFWH:example.com").to_owned(), owned_event_id!("$15827405538098VGFWH:example.com"),
), ),
}), }),
}); });

View File

@ -9,7 +9,8 @@ use ruma_common::{
pdu::{EventHash, Pdu, RoomV1Pdu, RoomV3Pdu}, pdu::{EventHash, Pdu, RoomV1Pdu, RoomV3Pdu},
TimelineEventType, TimelineEventType,
}, },
room_id, server_name, server_signing_key_id, user_id, MilliSecondsSinceUnixEpoch, owned_event_id, owned_room_id, owned_server_signing_key_id, owned_user_id, server_name,
MilliSecondsSinceUnixEpoch,
}; };
use serde_json::{ use serde_json::{
from_value as from_json_value, json, to_value as to_json_value, from_value as from_json_value, json, to_value as to_json_value,
@ -21,7 +22,7 @@ fn serialize_pdu_as_v1() {
let mut signatures = BTreeMap::new(); let mut signatures = BTreeMap::new();
let mut inner_signature = BTreeMap::new(); let mut inner_signature = BTreeMap::new();
inner_signature.insert( inner_signature.insert(
server_signing_key_id!("ed25519:key_version").to_owned(), owned_server_signing_key_id!("ed25519:key_version"),
"86BytesOfSignatureOfTheRedactedEvent".into(), "86BytesOfSignatureOfTheRedactedEvent".into(),
); );
signatures.insert(server_name!("example.com").to_owned(), inner_signature); signatures.insert(server_name!("example.com").to_owned(), inner_signature);
@ -30,23 +31,23 @@ fn serialize_pdu_as_v1() {
unsigned.insert("somekey".into(), to_raw_json_value(&json!({ "a": 456 })).unwrap()); unsigned.insert("somekey".into(), to_raw_json_value(&json!({ "a": 456 })).unwrap());
let v1_pdu = RoomV1Pdu { let v1_pdu = RoomV1Pdu {
room_id: room_id!("!n8f893n9:example.com").to_owned(), room_id: owned_room_id!("!n8f893n9:example.com"),
event_id: event_id!("$somejoinevent:matrix.org").to_owned(), event_id: owned_event_id!("$somejoinevent:matrix.org"),
sender: user_id!("@sender:example.com").to_owned(), sender: owned_user_id!("@sender:example.com"),
origin_server_ts: MilliSecondsSinceUnixEpoch(1_592_050_773_658_u64.try_into().unwrap()), origin_server_ts: MilliSecondsSinceUnixEpoch(1_592_050_773_658_u64.try_into().unwrap()),
kind: TimelineEventType::RoomPowerLevels, kind: TimelineEventType::RoomPowerLevels,
content: to_raw_json_value(&json!({ "testing": 123 })).unwrap(), content: to_raw_json_value(&json!({ "testing": 123 })).unwrap(),
state_key: Some("state".into()), state_key: Some("state".into()),
prev_events: vec![( prev_events: vec![(
event_id!("$previousevent:matrix.org").to_owned(), owned_event_id!("$previousevent:matrix.org"),
EventHash::new("123567".into()), EventHash::new("123567".into()),
)], )],
depth: uint!(2), depth: uint!(2),
auth_events: vec![( auth_events: vec![(
event_id!("$someauthevent:matrix.org").to_owned(), owned_event_id!("$someauthevent:matrix.org"),
EventHash::new("21389CFEDABC".into()), EventHash::new("21389CFEDABC".into()),
)], )],
redacts: Some(event_id!("$9654:matrix.org").to_owned()), redacts: Some(owned_event_id!("$9654:matrix.org")),
unsigned, unsigned,
hashes: EventHash::new("1233543bABACDEF".into()), hashes: EventHash::new("1233543bABACDEF".into()),
signatures, signatures,
@ -86,7 +87,7 @@ fn serialize_pdu_as_v3() {
let mut signatures = BTreeMap::new(); let mut signatures = BTreeMap::new();
let mut inner_signature = BTreeMap::new(); let mut inner_signature = BTreeMap::new();
inner_signature.insert( inner_signature.insert(
server_signing_key_id!("ed25519:key_version").to_owned(), owned_server_signing_key_id!("ed25519:key_version"),
"86BytesOfSignatureOfTheRedactedEvent".into(), "86BytesOfSignatureOfTheRedactedEvent".into(),
); );
signatures.insert(server_name!("example.com").to_owned(), inner_signature); signatures.insert(server_name!("example.com").to_owned(), inner_signature);
@ -95,16 +96,16 @@ fn serialize_pdu_as_v3() {
unsigned.insert("somekey".into(), to_raw_json_value(&json!({ "a": 456 })).unwrap()); unsigned.insert("somekey".into(), to_raw_json_value(&json!({ "a": 456 })).unwrap());
let v3_pdu = RoomV3Pdu { let v3_pdu = RoomV3Pdu {
room_id: room_id!("!n8f893n9:example.com").to_owned(), room_id: owned_room_id!("!n8f893n9:example.com"),
sender: user_id!("@sender:example.com").to_owned(), sender: owned_user_id!("@sender:example.com"),
origin_server_ts: MilliSecondsSinceUnixEpoch(1_592_050_773_658_u64.try_into().unwrap()), origin_server_ts: MilliSecondsSinceUnixEpoch(1_592_050_773_658_u64.try_into().unwrap()),
kind: TimelineEventType::RoomPowerLevels, kind: TimelineEventType::RoomPowerLevels,
content: to_raw_json_value(&json!({ "testing": 123 })).unwrap(), content: to_raw_json_value(&json!({ "testing": 123 })).unwrap(),
state_key: Some("state".into()), state_key: Some("state".into()),
prev_events: vec![event_id!("$previousevent:matrix.org").to_owned()], prev_events: vec![owned_event_id!("$previousevent:matrix.org")],
depth: uint!(2), depth: uint!(2),
auth_events: vec![event_id!("$someauthevent:matrix.org").to_owned()], auth_events: vec![owned_event_id!("$someauthevent:matrix.org")],
redacts: Some(event_id!("$9654:matrix.org").to_owned()), redacts: Some(owned_event_id!("$9654:matrix.org")),
unsigned, unsigned,
hashes: EventHash::new("1233543bABACDEF".into()), hashes: EventHash::new("1233543bABACDEF".into()),
signatures, signatures,

View File

@ -5,7 +5,6 @@ use std::collections::BTreeMap;
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use js_int::uint; use js_int::uint;
use ruma_common::{ use ruma_common::{
event_id,
events::{ events::{
message::TextContentBlock, message::TextContentBlock,
poll::{ poll::{
@ -19,6 +18,7 @@ use ruma_common::{
relation::Reference, relation::Reference,
AnyMessageLikeEvent, MessageLikeEvent, AnyMessageLikeEvent, MessageLikeEvent,
}, },
owned_event_id,
}; };
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};
@ -197,7 +197,7 @@ fn start_event_deserialization() {
fn response_content_serialization() { fn response_content_serialization() {
let event_content = PollResponseEventContent::new( let event_content = PollResponseEventContent::new(
vec!["my-answer".to_owned()].into(), vec!["my-answer".to_owned()].into(),
event_id!("$related_event:notareal.hs").to_owned(), owned_event_id!("$related_event:notareal.hs"),
); );
assert_eq!( assert_eq!(
@ -216,7 +216,7 @@ fn response_content_serialization() {
fn response_event_serialization() { fn response_event_serialization() {
let content = PollResponseEventContent::new( let content = PollResponseEventContent::new(
vec!["first-answer".to_owned(), "second-answer".to_owned()].into(), vec!["first-answer".to_owned(), "second-answer".to_owned()].into(),
event_id!("$related_event:notareal.hs").to_owned(), owned_event_id!("$related_event:notareal.hs"),
); );
assert_eq!( assert_eq!(
@ -264,7 +264,7 @@ fn response_event_deserialization() {
fn end_content_serialization() { fn end_content_serialization() {
let event_content = PollEndEventContent::with_plain_text( let event_content = PollEndEventContent::with_plain_text(
"The poll has closed. Top answer: Amazing!", "The poll has closed. Top answer: Amazing!",
event_id!("$related_event:notareal.hs").to_owned(), owned_event_id!("$related_event:notareal.hs"),
); );
assert_eq!( assert_eq!(
@ -285,7 +285,7 @@ fn end_content_serialization() {
fn end_event_serialization() { fn end_event_serialization() {
let mut content = PollEndEventContent::with_plain_text( let mut content = PollEndEventContent::with_plain_text(
"The poll has closed. Top answer: Amazing!", "The poll has closed. Top answer: Amazing!",
event_id!("$related_event:notareal.hs").to_owned(), owned_event_id!("$related_event:notareal.hs"),
); );
content.poll_results = Some( content.poll_results = Some(
BTreeMap::from([ BTreeMap::from([

View File

@ -172,10 +172,10 @@ fn redact_method_properly_redacts() {
let redaction = OriginalSyncRoomRedactionEvent { let redaction = OriginalSyncRoomRedactionEvent {
content: RoomRedactionEventContent::with_reason("redacted because".into()), content: RoomRedactionEventContent::with_reason("redacted because".into()),
redacts: event_id!("$143273582443PhrSn:example.com").to_owned(), redacts: owned_event_id!("$143273582443PhrSn:example.com"),
event_id: event_id!("$h29iv0s8:example.com").to_owned(), event_id: owned_event_id!("$h29iv0s8:example.com"),
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
sender: user_id!("@carl:example.com").to_owned(), sender: owned_user_id!("@carl:example.com"),
unsigned: MessageLikeUnsigned::default(), unsigned: MessageLikeUnsigned::default(),
}; };

View File

@ -1,11 +1,11 @@
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use assign::assign; use assign::assign;
use ruma_common::{ use ruma_common::{
event_id,
events::{ events::{
relation::{InReplyTo, Replacement, Thread}, relation::{InReplyTo, Replacement, Thread},
room::message::{MessageType, Relation, RoomMessageEventContent}, room::message::{MessageType, Relation, RoomMessageEventContent},
}, },
owned_event_id,
}; };
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};
@ -35,7 +35,7 @@ fn reply_deserialize() {
#[test] #[test]
fn reply_serialize() { fn reply_serialize() {
let content = assign!(RoomMessageEventContent::text_plain("This is a reply"), { let content = assign!(RoomMessageEventContent::text_plain("This is a reply"), {
relates_to: Some(Relation::Reply { in_reply_to: InReplyTo::new(event_id!("$1598361704261elfgc").to_owned()) }), relates_to: Some(Relation::Reply { in_reply_to: InReplyTo::new(owned_event_id!("$1598361704261elfgc")) }),
}); });
assert_eq!( assert_eq!(
@ -59,7 +59,7 @@ fn replacement_serialize() {
{ {
relates_to: Some(Relation::Replacement( relates_to: Some(Relation::Replacement(
Replacement::new( Replacement::new(
event_id!("$1598361704261elfgc").to_owned(), owned_event_id!("$1598361704261elfgc"),
RoomMessageEventContent::text_plain("This is the new content.").into(), RoomMessageEventContent::text_plain("This is the new content.").into(),
) )
)) ))
@ -118,8 +118,8 @@ fn thread_plain_serialize() {
{ {
relates_to: Some(Relation::Thread( relates_to: Some(Relation::Thread(
Thread::plain( Thread::plain(
event_id!("$1598361704261elfgc").to_owned(), owned_event_id!("$1598361704261elfgc"),
event_id!("$latesteventid").to_owned(), owned_event_id!("$latesteventid"),
), ),
)), )),
} }
@ -149,8 +149,8 @@ fn thread_reply_serialize() {
{ {
relates_to: Some(Relation::Thread( relates_to: Some(Relation::Thread(
Thread::reply( Thread::reply(
event_id!("$1598361704261elfgc").to_owned(), owned_event_id!("$1598361704261elfgc"),
event_id!("$repliedtoeventid").to_owned(), owned_event_id!("$repliedtoeventid"),
), ),
)), )),
} }

View File

@ -3,7 +3,6 @@ use std::borrow::Cow;
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use js_int::uint; use js_int::uint;
use ruma_common::{ use ruma_common::{
event_id,
events::{ events::{
key::verification::VerificationMethod, key::verification::VerificationMethod,
room::{ room::{
@ -17,7 +16,7 @@ use ruma_common::{
}, },
MessageLikeUnsigned, MessageLikeUnsigned,
}, },
mxc_uri, room_id, mxc_uri, owned_event_id, owned_room_id, owned_user_id,
serde::Base64, serde::Base64,
user_id, MilliSecondsSinceUnixEpoch, OwnedDeviceId, user_id, MilliSecondsSinceUnixEpoch, OwnedDeviceId,
}; };
@ -224,7 +223,7 @@ fn verification_request_msgtype_deserialization() {
#[test] #[test]
fn verification_request_msgtype_serialization() { fn verification_request_msgtype_serialization() {
let user_id = user_id!("@example2:localhost").to_owned(); let user_id = owned_user_id!("@example2:localhost");
let device_id: OwnedDeviceId = "XOWLHHFSWM".into(); let device_id: OwnedDeviceId = "XOWLHHFSWM".into();
let body = "@example:localhost is requesting to verify your key, ...".to_owned(); let body = "@example:localhost is requesting to verify your key, ...".to_owned();
@ -260,10 +259,10 @@ fn content_deserialization_failure() {
fn escape_tags_in_plain_reply_body() { fn escape_tags_in_plain_reply_body() {
let first_message = OriginalRoomMessageEvent { let first_message = OriginalRoomMessageEvent {
content: RoomMessageEventContent::text_plain("Usage: cp <source> <destination>"), content: RoomMessageEventContent::text_plain("Usage: cp <source> <destination>"),
event_id: event_id!("$143273582443PhrSn:example.org").to_owned(), event_id: owned_event_id!("$143273582443PhrSn:example.org"),
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10_000)), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10_000)),
room_id: room_id!("!testroomid:example.org").to_owned(), room_id: owned_room_id!("!testroomid:example.org"),
sender: user_id!("@user:example.org").to_owned(), sender: owned_user_id!("@user:example.org"),
unsigned: MessageLikeUnsigned::default(), unsigned: MessageLikeUnsigned::default(),
}; };
let second_message = RoomMessageEventContent::text_plain("Usage: rm <path>") let second_message = RoomMessageEventContent::text_plain("Usage: rm <path>")
@ -313,10 +312,10 @@ fn reply_sanitize() {
"# This is the first message", "# This is the first message",
"<h1>This is the first message</h1>", "<h1>This is the first message</h1>",
), ),
event_id: event_id!("$143273582443PhrSn:example.org").to_owned(), event_id: owned_event_id!("$143273582443PhrSn:example.org"),
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10_000)), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10_000)),
room_id: room_id!("!testroomid:example.org").to_owned(), room_id: owned_room_id!("!testroomid:example.org"),
sender: user_id!("@user:example.org").to_owned(), sender: owned_user_id!("@user:example.org"),
unsigned: MessageLikeUnsigned::default(), unsigned: MessageLikeUnsigned::default(),
}; };
let second_message = OriginalRoomMessageEvent { let second_message = OriginalRoomMessageEvent {
@ -325,10 +324,10 @@ fn reply_sanitize() {
"This is the <em>second</em> message", "This is the <em>second</em> message",
) )
.make_reply_to(&first_message, ForwardThread::Yes), .make_reply_to(&first_message, ForwardThread::Yes),
event_id: event_id!("$143273582443PhrSn:example.org").to_owned(), event_id: owned_event_id!("$143273582443PhrSn:example.org"),
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10_000)), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10_000)),
room_id: room_id!("!testroomid:example.org").to_owned(), room_id: owned_room_id!("!testroomid:example.org"),
sender: user_id!("@user:example.org").to_owned(), sender: owned_user_id!("@user:example.org"),
unsigned: MessageLikeUnsigned::default(), unsigned: MessageLikeUnsigned::default(),
}; };
let final_reply = RoomMessageEventContent::text_html( let final_reply = RoomMessageEventContent::text_html(
@ -406,7 +405,7 @@ fn make_replacement_no_reply() {
"This is _an edited_ message.", "This is _an edited_ message.",
"This is <em>an edited</em> message.", "This is <em>an edited</em> message.",
); );
let event_id = event_id!("$143273582443PhrSn:example.org").to_owned(); let event_id = owned_event_id!("$143273582443PhrSn:example.org");
let content = content.make_replacement(event_id, None); let content = content.make_replacement(event_id, None);
@ -426,10 +425,10 @@ fn make_replacement_with_reply() {
"# This is the first message", "# This is the first message",
"<h1>This is the first message</h1>", "<h1>This is the first message</h1>",
), ),
event_id: event_id!("$143273582443PhrSn:example.org").to_owned(), event_id: owned_event_id!("$143273582443PhrSn:example.org"),
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10_000)), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10_000)),
room_id: room_id!("!testroomid:example.org").to_owned(), room_id: owned_room_id!("!testroomid:example.org"),
sender: user_id!("@user:example.org").to_owned(), sender: owned_user_id!("@user:example.org"),
unsigned: MessageLikeUnsigned::default(), unsigned: MessageLikeUnsigned::default(),
}; };
@ -437,7 +436,7 @@ fn make_replacement_with_reply() {
"This is _an edited_ reply.", "This is _an edited_ reply.",
"This is <em>an edited</em> reply.", "This is <em>an edited</em> reply.",
); );
let event_id = event_id!("$143273582443PhrSn:example.org").to_owned(); let event_id = owned_event_id!("$143273582443PhrSn:example.org");
let content = content.make_replacement(event_id, Some(&replied_to_message)); let content = content.make_replacement(event_id, Some(&replied_to_message));

View File

@ -1,5 +1,5 @@
use ruma_common::{ use ruma_common::{
events::room_key::ToDeviceRoomKeyEventContent, room_id, EventEncryptionAlgorithm, events::room_key::ToDeviceRoomKeyEventContent, owned_room_id, EventEncryptionAlgorithm,
}; };
use serde_json::{json, to_value as to_json_value}; use serde_json::{json, to_value as to_json_value};
@ -7,7 +7,7 @@ use serde_json::{json, to_value as to_json_value};
fn serialization() { fn serialization() {
let content = ToDeviceRoomKeyEventContent::new( let content = ToDeviceRoomKeyEventContent::new(
EventEncryptionAlgorithm::MegolmV1AesSha2, EventEncryptionAlgorithm::MegolmV1AesSha2,
room_id!("!testroomid:example.org").to_owned(), owned_room_id!("!testroomid:example.org"),
"SessId".into(), "SessId".into(),
"SessKey".into(), "SessKey".into(),
); );

View File

@ -5,7 +5,6 @@ use std::time::Duration;
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use js_int::uint; use js_int::uint;
use ruma_common::{ use ruma_common::{
event_id,
events::{ events::{
file::{CaptionContentBlock, EncryptedContentInit, FileContentBlock}, file::{CaptionContentBlock, EncryptedContentInit, FileContentBlock},
image::{Thumbnail, ThumbnailFileContentBlock, ThumbnailImageDetailsContentBlock}, image::{Thumbnail, ThumbnailFileContentBlock, ThumbnailImageDetailsContentBlock},
@ -15,7 +14,7 @@ use ruma_common::{
video::{VideoDetailsContentBlock, VideoEventContent}, video::{VideoDetailsContentBlock, VideoEventContent},
AnyMessageLikeEvent, MessageLikeEvent, AnyMessageLikeEvent, MessageLikeEvent,
}, },
mxc_uri, mxc_uri, owned_event_id,
serde::{Base64, CanBeEmpty}, serde::{Base64, CanBeEmpty},
MilliSecondsSinceUnixEpoch, MilliSecondsSinceUnixEpoch,
}; };
@ -128,7 +127,7 @@ fn event_serialization() {
content.thumbnail = vec![thumbnail].into(); content.thumbnail = vec![thumbnail].into();
content.caption = Some(CaptionContentBlock::plain("This is my awesome vintage lava lamp")); content.caption = Some(CaptionContentBlock::plain("This is my awesome vintage lava lamp"));
content.relates_to = Some(Relation::Reply { content.relates_to = Some(Relation::Reply {
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()), in_reply_to: InReplyTo::new(owned_event_id!("$replyevent:example.com")),
}); });
assert_eq!( assert_eq!(

View File

@ -5,7 +5,6 @@ use std::time::Duration;
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use js_int::uint; use js_int::uint;
use ruma_common::{ use ruma_common::{
event_id,
events::{ events::{
audio::Amplitude, audio::Amplitude,
file::FileContentBlock, file::FileContentBlock,
@ -14,7 +13,7 @@ use ruma_common::{
voice::{VoiceAudioDetailsContentBlock, VoiceEventContent}, voice::{VoiceAudioDetailsContentBlock, VoiceEventContent},
AnyMessageLikeEvent, MessageLikeEvent, AnyMessageLikeEvent, MessageLikeEvent,
}, },
mxc_uri, mxc_uri, owned_event_id,
serde::CanBeEmpty, serde::CanBeEmpty,
MilliSecondsSinceUnixEpoch, MilliSecondsSinceUnixEpoch,
}; };
@ -37,7 +36,7 @@ fn event_serialization() {
content.file.mimetype = Some("audio/opus".to_owned()); content.file.mimetype = Some("audio/opus".to_owned());
content.file.size = Some(uint!(897_774)); content.file.size = Some(uint!(897_774));
content.relates_to = Some(Relation::Reply { content.relates_to = Some(Relation::Reply {
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()), in_reply_to: InReplyTo::new(owned_event_id!("$replyevent:example.com")),
}); });
assert_eq!( assert_eq!(

View File

@ -1,10 +1,10 @@
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use ruma_common::{ use ruma_common::{
event_id,
events::{ events::{
relation::InReplyTo, relation::InReplyTo,
room::message::{MessageType, Relation, RoomMessageEventContent}, room::message::{MessageType, Relation, RoomMessageEventContent},
}, },
owned_event_id,
}; };
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};
@ -12,7 +12,7 @@ use serde_json::{from_value as from_json_value, json, to_value as to_json_value}
fn serialize_room_message_content_without_relation() { fn serialize_room_message_content_without_relation() {
let mut content = RoomMessageEventContent::text_plain("Hello, world!"); let mut content = RoomMessageEventContent::text_plain("Hello, world!");
content.relates_to = content.relates_to =
Some(Relation::Reply { in_reply_to: InReplyTo::new(event_id!("$eventId").to_owned()) }); Some(Relation::Reply { in_reply_to: InReplyTo::new(owned_event_id!("$eventId")) });
let without_relation = MessageType::from(content); let without_relation = MessageType::from(content);
assert_eq!( assert_eq!(
@ -39,7 +39,7 @@ fn deserialize_room_message_content_without_relation() {
fn convert_room_message_content_without_relation_to_full() { fn convert_room_message_content_without_relation_to_full() {
let mut content = RoomMessageEventContent::text_plain("Hello, world!"); let mut content = RoomMessageEventContent::text_plain("Hello, world!");
content.relates_to = content.relates_to =
Some(Relation::Reply { in_reply_to: InReplyTo::new(event_id!("$eventId").to_owned()) }); Some(Relation::Reply { in_reply_to: InReplyTo::new(owned_event_id!("$eventId")) });
let new_content = RoomMessageEventContent::from(MessageType::from(content)); let new_content = RoomMessageEventContent::from(MessageType::from(content));
assert_matches!( assert_matches!(

View File

@ -73,7 +73,7 @@ where
mod tests { mod tests {
use std::collections::BTreeMap; use std::collections::BTreeMap;
use ruma_common::{event_id, OwnedEventId}; use ruma_common::{event_id, owned_event_id, OwnedEventId};
use serde_json::{json, value::Serializer as JsonSerializer}; use serde_json::{json, value::Serializer as JsonSerializer};
use super::{deserialize, serialize}; use super::{deserialize, serialize};
@ -81,10 +81,8 @@ mod tests {
#[test] #[test]
fn serialize_error() { fn serialize_error() {
let mut response: BTreeMap<OwnedEventId, Result<(), String>> = BTreeMap::new(); let mut response: BTreeMap<OwnedEventId, Result<(), String>> = BTreeMap::new();
response.insert( response
event_id!("$someevent:matrix.org").to_owned(), .insert(owned_event_id!("$someevent:matrix.org"), Err("Some processing error.".into()));
Err("Some processing error.".into()),
);
let serialized = serialize(&response, JsonSerializer).unwrap(); let serialized = serialize(&response, JsonSerializer).unwrap();
let json = json!({ let json = json!({
@ -96,7 +94,7 @@ mod tests {
#[test] #[test]
fn serialize_ok() { fn serialize_ok() {
let mut response: BTreeMap<OwnedEventId, Result<(), String>> = BTreeMap::new(); let mut response: BTreeMap<OwnedEventId, Result<(), String>> = BTreeMap::new();
response.insert(event_id!("$someevent:matrix.org").to_owned(), Ok(())); response.insert(owned_event_id!("$someevent:matrix.org"), Ok(()));
let serialized = serialize(&response, serde_json::value::Serializer).unwrap(); let serialized = serialize(&response, serde_json::value::Serializer).unwrap();
let json = json!({ let json = json!({

View File

@ -376,8 +376,8 @@ pub mod v1 {
mod tests { mod tests {
use js_int::uint; use js_int::uint;
use ruma_common::{ use ruma_common::{
event_id, events::TimelineEventType, room_alias_id, room_id, user_id, events::TimelineEventType, owned_event_id, owned_room_alias_id, owned_room_id,
SecondsSinceUnixEpoch, owned_user_id, SecondsSinceUnixEpoch,
}; };
use serde_json::{ use serde_json::{
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue, from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
@ -413,10 +413,10 @@ pub mod v1 {
] ]
}); });
let eid = event_id!("$3957tyerfgewrf384").to_owned(); let eid = owned_event_id!("$3957tyerfgewrf384");
let rid = room_id!("!slw48wfj34rtnrf:example.com").to_owned(); let rid = owned_room_id!("!slw48wfj34rtnrf:example.com");
let uid = user_id!("@exampleuser:matrix.org").to_owned(); let uid = owned_user_id!("@exampleuser:matrix.org");
let alias = room_alias_id!("#exampleroom:matrix.org").to_owned(); let alias = owned_room_alias_id!("#exampleroom:matrix.org");
let count = NotificationCounts { unread: uint!(2), ..NotificationCounts::default() }; let count = NotificationCounts { unread: uint!(2), ..NotificationCounts::default() };