From 9011423eeaf276be6d913ea6ecde90fb65cd8794 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Mon, 3 Jun 2019 12:11:57 -0700 Subject: [PATCH] Consistently use localpart instead of opaque_id and use homeserver_host instead of server_name. --- src/event_id.rs | 6 +++--- src/room_id.rs | 26 +++++++++++++------------- src/room_id_or_room_alias_id.rs | 8 ++++---- src/user_id.rs | 10 +++++++--- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/event_id.rs b/src/event_id.rs index 551d502c..606e68c2 100644 --- a/src/event_id.rs +++ b/src/event_id.rs @@ -83,9 +83,9 @@ impl EventId { /// of 18 random ASCII characters. This should only be used for events in the original format /// as used by Matrix room versions 1 and 2. /// - /// Fails if the given origin server name cannot be parsed as a valid host. - pub fn new(server_name: &str) -> Result { - let event_id = format!("${}:{}", generate_localpart(18), server_name); + /// Fails if the homeserver cannot be parsed as a valid host. + pub fn new(homeserver_host: &str) -> Result { + let event_id = format!("${}:{}", generate_localpart(18), homeserver_host); let (localpart, host, port) = parse_id('$', &event_id)?; Ok(Self(Format::Original(Original { diff --git a/src/room_id.rs b/src/room_id.rs index 6c66c883..8aec0959 100644 --- a/src/room_id.rs +++ b/src/room_id.rs @@ -35,7 +35,7 @@ pub struct RoomId { /// The hostname of the homeserver. hostname: Host, /// The room's unique ID. - opaque_id: String, + localpart: String, /// The network port of the homeserver. port: u16, } @@ -47,14 +47,14 @@ impl RoomId { /// Attempts to generate a `RoomId` for the given origin server with a localpart consisting of /// 18 random ASCII characters. /// - /// Fails if the given origin server name cannot be parsed as a valid host. - pub fn new(server_name: &str) -> Result { - let room_id = format!("!{}:{}", generate_localpart(18), server_name); - let (opaque_id, host, port) = parse_id('!', &room_id)?; + /// Fails if the given homeserver cannot be parsed as a valid host. + pub fn new(homeserver_host: &str) -> Result { + let room_id = format!("!{}:{}", generate_localpart(18), homeserver_host); + let (localpart, host, port) = parse_id('!', &room_id)?; Ok(Self { hostname: host, - opaque_id: opaque_id.to_string(), + localpart: localpart.to_string(), port, }) } @@ -67,9 +67,9 @@ impl RoomId { &self.hostname } - /// Returns the event's opaque ID. - pub fn opaque_id(&self) -> &str { - &self.opaque_id + /// Returns the rooms's unique ID. + pub fn localpart(&self) -> &str { + &self.localpart } /// Returns the port the originating homeserver can be accessed on. @@ -80,7 +80,7 @@ impl RoomId { impl Display for RoomId { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { - display(f, '!', &self.opaque_id, &self.hostname, self.port) + display(f, '!', &self.localpart, &self.hostname, self.port) } } @@ -107,14 +107,14 @@ impl<'a> TryFrom<&'a str> for RoomId { /// Attempts to create a new Matrix room ID from a string representation. /// - /// The string must include the leading ! sigil, the opaque ID, a literal colon, and a valid + /// The string must include the leading ! sigil, the localpart, a literal colon, and a valid /// server name. fn try_from(room_id: &'a str) -> Result { - let (opaque_id, host, port) = parse_id('!', room_id)?; + let (localpart, host, port) = parse_id('!', room_id)?; Ok(Self { hostname: host, - opaque_id: opaque_id.to_owned(), + localpart: localpart.to_owned(), port, }) } diff --git a/src/room_id_or_room_alias_id.rs b/src/room_id_or_room_alias_id.rs index 8ddb85c0..3a2d7563 100644 --- a/src/room_id_or_room_alias_id.rs +++ b/src/room_id_or_room_alias_id.rs @@ -59,7 +59,7 @@ impl Display for RoomIdOrAliasId { RoomIdOrAliasId::RoomId(ref room_id) => display( f, '!', - room_id.opaque_id(), + room_id.localpart(), room_id.hostname(), room_id.port(), ), @@ -95,9 +95,9 @@ impl<'a> TryFrom<&'a str> for RoomIdOrAliasId { /// Attempts to create a new Matrix room ID or a room alias ID from a string representation. /// - /// The string must either - /// include the leading ! sigil, the opaque ID, a literal colon, and a valid server name or - /// include the leading # sigil, the alias, a literal colon, and a valid server name. + /// The string must either include the leading ! sigil, the localpart, a literal colon, and a + /// valid homeserver host or include the leading # sigil, the alias, a literal colon, and a + /// valid homeserver host. fn try_from(room_id_or_alias_id: &'a str) -> Result { validate_id(room_id_or_alias_id)?; diff --git a/src/user_id.rs b/src/user_id.rs index 81b1ef15..140341ce 100644 --- a/src/user_id.rs +++ b/src/user_id.rs @@ -54,9 +54,13 @@ impl UserId { /// Attempts to generate a `UserId` for the given origin server with a localpart consisting of /// 12 random ASCII characters. /// - /// Fails if the given origin server name cannot be parsed as a valid host. - pub fn new(server_name: &str) -> Result { - let user_id = format!("@{}:{}", generate_localpart(12).to_lowercase(), server_name); + /// Fails if the given homeserver cannot be parsed as a valid host. + pub fn new(homeserver_host: &str) -> Result { + let user_id = format!( + "@{}:{}", + generate_localpart(12).to_lowercase(), + homeserver_host + ); let (localpart, host, port) = parse_id('@', &user_id)?; Ok(Self {