diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index 09123910..be083ad1 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -651,7 +651,8 @@ impl Client { /// Search the homeserver's directory of public rooms. /// - /// Returns a `get_public_rooms::Response`, an empty response. + /// Sends a request to "_matrix/client/r0/publicRooms", returns + /// a `get_public_rooms::Response`. /// /// # Arguments /// @@ -673,11 +674,8 @@ impl Client { /// let mut cli = Client::new(homeserver).unwrap(); /// # use futures::executor::block_on; /// # block_on(async { - /// assert!(cli.public_rooms( - /// limit, - /// since, - /// server - /// ).await.is_ok()); + /// + /// cli.public_rooms(limit, since, server).await; /// # }); /// ``` pub async fn public_rooms( @@ -700,7 +698,8 @@ impl Client { /// Search the homeserver's directory of public rooms with a filter. /// - /// Returns a `get_public_rooms_filtered::Response`, an empty response. + /// Sends a request to "_matrix/client/r0/publicRooms", returns + /// a `get_public_rooms_filtered::Response`. /// /// # Arguments /// @@ -725,7 +724,7 @@ impl Client { /// .since(last_sync_token) /// .room_network(RoomNetwork::Matrix); /// - /// client.public_rooms_filtered(builder).await.is_err(); + /// client.public_rooms_filtered(builder).await; /// # }) /// ``` pub async fn public_rooms_filtered>( @@ -1856,7 +1855,7 @@ mod test { Matcher::Regex(r"^/_matrix/client/r0/publicRooms".to_string()), ) .with_status(200) - .with_body_from_file("../test_data/public_rooms.json") + .with_body(test_json::PUBLIC_ROOMS.to_string()) .create(); let client = Client::new(homeserver).unwrap(); @@ -1885,7 +1884,7 @@ mod test { Matcher::Regex(r"^/_matrix/client/r0/publicRooms".to_string()), ) .with_status(200) - .with_body_from_file("../test_data/public_rooms.json") + .with_body(test_json::PUBLIC_ROOMS.to_string()) .create(); let client = Client::new(homeserver).unwrap(); diff --git a/matrix_sdk/src/request_builder.rs b/matrix_sdk/src/request_builder.rs index de2cbebb..dc9cecd3 100644 --- a/matrix_sdk/src/request_builder.rs +++ b/matrix_sdk/src/request_builder.rs @@ -1,5 +1,3 @@ -use std::convert::TryFrom; - use matrix_sdk_common::{ api::r0::{ account::register::{self, RegistrationKind}, @@ -42,38 +40,17 @@ use matrix_sdk_common::{ /// ``` #[derive(Clone, Debug, Default)] pub struct RoomBuilder { - /// Extra keys to be added to the content of the `m.room.create`. creation_content: Option, - /// List of state events to send to the new room. - /// - /// Takes precedence over events set by preset, but gets overriden by - /// name and topic keys. initial_state: Vec, - /// A list of user IDs to invite to the room. - /// - /// This will tell the server to invite everyone in the list to the newly created room. invite: Vec, - /// List of third party IDs of users to invite. invite_3pid: Vec, - /// If set, this sets the `is_direct` flag on room invites. is_direct: Option, - /// If this is included, an `m.room.name` event will be sent into the room to indicate - /// the name of the room. name: Option, - /// Power level content to override in the default power level event. power_level_content_override: Option, - /// Convenience parameter for setting various default state events based on a preset. preset: Option, - /// The desired room alias local part. room_alias_name: Option, - /// Room version to set for the room. Defaults to homeserver's default if not specified. room_version: Option, - /// If this is included, an `m.room.topic` event will be sent into the room to indicate - /// the topic for the room. topic: Option, - /// A public visibility indicates that the room will be shown in the published room - /// list. A private visibility will hide the room from the published room list. Rooms - /// default to private visibility if this key is not included. visibility: Option, } @@ -92,61 +69,68 @@ impl RoomBuilder { self } - /// Set the `InitialStateEvent` vector. + /// Sets a list of state events to send to the new room. + /// + /// Takes precedence over events set by preset, but gets overriden by + /// name and topic keys. pub fn initial_state(&mut self, state: Vec) -> &mut Self { self.initial_state = state; self } - /// Set the vec of `UserId`s. + /// Sets a list of user IDs to invite to the room. + /// + /// This will tell the server to invite everyone in the list to the newly created room. pub fn invite(&mut self, invite: Vec) -> &mut Self { self.invite = invite; self } - /// Set the vec of `Invite3pid`s. + /// Sets a list of third party IDs of users to invite. pub fn invite_3pid(&mut self, invite: Vec) -> &mut Self { self.invite_3pid = invite; self } - /// Set the vec of `Invite3pid`s. + /// If set, this sets the `is_direct` flag on room invites. pub fn is_direct(&mut self, direct: bool) -> &mut Self { self.is_direct = Some(direct); self } - /// Set the room name. A `m.room.name` event will be sent to the room. + /// If this is included, an `m.room.name` event will be sent into the room to indicate + /// the name of the room. pub fn name>(&mut self, name: S) -> &mut Self { self.name = Some(name.into()); self } - /// Set the room's power levels. + /// Power level content to override in the default power level event. pub fn power_level_override(&mut self, power: PowerLevelsEventContent) -> &mut Self { self.power_level_content_override = Some(power); self } - /// Convenience for setting various default state events based on a preset. + /// Convenience parameter for setting various default state events based on a preset. pub fn preset(&mut self, preset: RoomPreset) -> &mut Self { self.preset = Some(preset); self } - /// The local part of a room alias. + /// The desired room alias local part. pub fn room_alias_name>(&mut self, alias: S) -> &mut Self { self.room_alias_name = Some(alias.into()); self } - /// Room version, defaults to homeserver's version if left unspecified. + /// Room version to set for the room. Defaults to homeserver's default if not specified. pub fn room_version>(&mut self, version: S) -> &mut Self { self.room_version = Some(version.into()); self } - /// If included, a `m.room.topic` event will be sent to the room. + /// If this is included, an `m.room.topic` event will be sent into the room to indicate + /// the topic for the room. pub fn topic>(&mut self, topic: S) -> &mut Self { self.topic = Some(topic.into()); self @@ -210,33 +194,24 @@ impl Into for RoomBuilder { /// ``` #[derive(Clone, Debug)] pub struct MessagesRequestBuilder { - /// The room to get events from. room_id: RoomId, - /// The token to start returning events from. - /// - /// This token can be obtained from a - /// prev_batch token returned for each room by the sync API, or from a start or end token - /// returned by a previous request to this endpoint. from: String, - /// The token to stop returning events at. - /// - /// This token can be obtained from a prev_batch - /// token returned for each room by the sync endpoint, or from a start or end token returned - /// by a previous request to this endpoint. to: Option, - /// The direction to return events from. direction: Option, - /// The maximum number of events to return. - /// - /// Default: 10. limit: Option, - /// A filter of the returned events with. filter: Option, } impl MessagesRequestBuilder { /// Create a `MessagesRequestBuilder` builder to make a `get_message_events::Request`. - /// The `room_id` and `from`` fields **need to be set** to create the request. + /// + /// # Arguments + /// + /// * `room_id` - The id of the room that is being requested. + /// + /// * `from` - The token to start returning events from. This token can be obtained from + /// a `prev_batch` token from a sync response, or a start or end token from a previous request + /// to this endpoint. pub fn new(room_id: RoomId, from: String) -> Self { Self { room_id, @@ -286,7 +261,7 @@ impl Into for MessagesRequestBuilder { from: self.from, to: self.to, dir: self.direction.unwrap_or(Direction::Backward), - limit: self.limit.map_or(Ok(uint!(10)), UInt::try_from).ok(), + limit: self.limit.map(UInt::from), filter: self.filter, } } @@ -485,7 +460,7 @@ impl Into for RoomListFilterBuilder { fn into(self) -> get_public_rooms_filtered::Request { get_public_rooms_filtered::Request { room_network: self.room_network.unwrap_or_default(), - limit: self.limit.map_or(Ok(uint!(0)), UInt::try_from).ok(), + limit: self.limit.map(UInt::from), server: self.server, since: self.since, filter: self.filter, diff --git a/matrix_sdk_test/src/test_json/events.rs b/matrix_sdk_test/src/test_json/events.rs index 25242015..a4ba0ced 100644 --- a/matrix_sdk_test/src/test_json/events.rs +++ b/matrix_sdk_test/src/test_json/events.rs @@ -375,6 +375,28 @@ lazy_static! { }); } +lazy_static! { + pub static ref PUBLIC_ROOMS: JsonValue = json!({ + "chunk": [ + { + "aliases": [ + "#murrays:cheese.bar" + ], + "avatar_url": "mxc://bleeker.street/CHEDDARandBRIE", + "guest_can_join": false, + "name": "CHEESE", + "num_joined_members": 37, + "room_id": "!ol19s:bleecker.street", + "topic": "Tasty tasty cheese", + "world_readable": true + } + ], + "next_batch": "p190q", + "prev_batch": "p1902", + "total_room_count_estimate": 115 + }); +} + lazy_static! { pub static ref REGISTRATION_RESPONSE_ERR: JsonValue = json!({ "errcode": "M_FORBIDDEN", diff --git a/matrix_sdk_test/src/test_json/mod.rs b/matrix_sdk_test/src/test_json/mod.rs index f5db86d9..406f2023 100644 --- a/matrix_sdk_test/src/test_json/mod.rs +++ b/matrix_sdk_test/src/test_json/mod.rs @@ -9,7 +9,7 @@ pub mod sync; pub use events::{ ALIAS, ALIASES, EVENT_ID, KEYS_QUERY, KEYS_UPLOAD, LOGIN, LOGIN_RESPONSE_ERR, LOGOUT, MEMBER, - MESSAGE_EDIT, MESSAGE_TEXT, NAME, POWER_LEVELS, PRESENCE, REACTION, REGISTRATION_RESPONSE_ERR, - ROOM_ID, ROOM_MESSAGES, TYPING, + MESSAGE_EDIT, MESSAGE_TEXT, NAME, POWER_LEVELS, PRESENCE, PUBLIC_ROOMS, REACTION, + REGISTRATION_RESPONSE_ERR, ROOM_ID, ROOM_MESSAGES, TYPING, }; pub use sync::{DEFAULT_SYNC_SUMMARY, INVITE_SYNC, LEAVE_SYNC, LEAVE_SYNC_EVENT, MORE_SYNC, SYNC}; diff --git a/test_data/public_rooms.json b/test_data/public_rooms.json deleted file mode 100644 index 2995bb3f..00000000 --- a/test_data/public_rooms.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "chunk": [ - { - "aliases": [ - "#murrays:cheese.bar" - ], - "avatar_url": "mxc://bleeker.street/CHEDDARandBRIE", - "guest_can_join": false, - "name": "CHEESE", - "num_joined_members": 37, - "room_id": "!ol19s:bleecker.street", - "topic": "Tasty tasty cheese", - "world_readable": true - } - ], - "next_batch": "p190q", - "prev_batch": "p1902", - "total_room_count_estimate": 115 -}