[fractal] API: Use RoomId and RoomAliasId for stronger validation



commit 78eb03bf34d28720c76cd26cb72053981518283d
Author: Alejandro Domínguez <adomu net-c com>
Date:   Mon Oct 14 00:58:10 2019 +0200

    API: Use RoomId and RoomAliasId for stronger validation

 fractal-matrix-api/src/lib.rs                            | 2 ++
 fractal-matrix-api/src/model/room.rs                     | 4 ++--
 fractal-matrix-api/src/r0/directory/post_public_rooms.rs | 8 +++++---
 3 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/fractal-matrix-api/src/lib.rs b/fractal-matrix-api/src/lib.rs
index 197f6620..f5fe9cda 100644
--- a/fractal-matrix-api/src/lib.rs
+++ b/fractal-matrix-api/src/lib.rs
@@ -13,6 +13,8 @@ mod serde;
 pub mod types;
 
 pub mod prelude {
+    pub use ruma_identifiers::RoomAliasId;
+    pub use ruma_identifiers::RoomId;
     pub use ruma_identifiers::UserId;
 }
 
diff --git a/fractal-matrix-api/src/model/room.rs b/fractal-matrix-api/src/model/room.rs
index c433080e..027ad176 100644
--- a/fractal-matrix-api/src/model/room.rs
+++ b/fractal-matrix-api/src/model/room.rs
@@ -280,14 +280,14 @@ impl Room {
 impl From<PublicRoomsChunk> for Room {
     fn from(input: PublicRoomsChunk) -> Self {
         Self {
-            alias: input.canonical_alias,
+            alias: input.canonical_alias.as_ref().map(ToString::to_string),
             name: input.name,
             avatar: input.avatar_url.map(Url::into_string),
             topic: input.topic,
             n_members: input.num_joined_members,
             world_readable: input.world_readable,
             guest_can_join: input.guest_can_join,
-            ..Self::new(input.room_id, RoomMembership::None)
+            ..Self::new(input.room_id.to_string(), RoomMembership::None)
         }
     }
 }
diff --git a/fractal-matrix-api/src/r0/directory/post_public_rooms.rs 
b/fractal-matrix-api/src/r0/directory/post_public_rooms.rs
index dd0a5826..4b6cf5af 100644
--- a/fractal-matrix-api/src/r0/directory/post_public_rooms.rs
+++ b/fractal-matrix-api/src/r0/directory/post_public_rooms.rs
@@ -3,6 +3,8 @@ use crate::serde::{option_host, option_url};
 use reqwest::Client;
 use reqwest::Error;
 use reqwest::Request;
+use ruma_identifiers::RoomAliasId;
+use ruma_identifiers::RoomId;
 use serde::{Deserialize, Serialize};
 use url::Host;
 use url::Url;
@@ -61,15 +63,15 @@ pub struct Response {
 
 #[derive(Clone, Debug, Deserialize)]
 pub struct Chunk {
-    pub aliases: Option<Vec<String>>,
+    pub aliases: Option<Vec<RoomAliasId>>, // TODO: Change Vec to Set?
     #[serde(with = "option_url")]
     #[serde(default)]
     pub avatar_url: Option<Url>,
-    pub canonical_alias: Option<String>,
+    pub canonical_alias: Option<RoomAliasId>,
     pub guest_can_join: bool,
     pub name: Option<String>,
     pub num_joined_members: i32,
-    pub room_id: String,
+    pub room_id: RoomId,
     pub topic: Option<String>,
     pub world_readable: bool,
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]