client-api: Make from param optional in get_message_events
… and provide some additional convenience constructors.
This commit is contained in:
parent
c32e074383
commit
3d17529d2e
@ -38,8 +38,18 @@ pub mod v3 {
|
||||
/// 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.
|
||||
///
|
||||
/// If this is `None`, the server will return messages from the start or end of the
|
||||
/// history visible to the user, depending on the value of [`dir`][Self::dir].
|
||||
///
|
||||
/// *Note: This field is marked required in v1.2 of the specification, but that is
|
||||
/// changing, most likely as part of v1.3. To frontload the breaking change, this field
|
||||
/// is optional already even though v1.2 is the latest version at the time of writing.
|
||||
/// The specification change can be found [here].*
|
||||
///
|
||||
/// [here]: https://github.com/matrix-org/matrix-spec/pull/1002
|
||||
#[ruma_api(query)]
|
||||
pub from: &'a str,
|
||||
pub from: Option<&'a str>,
|
||||
|
||||
/// The token to stop returning events at.
|
||||
///
|
||||
@ -61,7 +71,7 @@ pub mod v3 {
|
||||
#[serde(default = "default_limit", skip_serializing_if = "is_default_limit")]
|
||||
pub limit: UInt,
|
||||
|
||||
/// A `RoomEventFilter` to filter returned events with.
|
||||
/// A [`RoomEventFilter`] to filter returned events with.
|
||||
#[ruma_api(query)]
|
||||
#[serde(
|
||||
with = "ruma_common::serde::json_string",
|
||||
@ -99,7 +109,7 @@ pub mod v3 {
|
||||
pub fn new(room_id: &'a RoomId, from: &'a str, dir: Direction) -> Self {
|
||||
Self {
|
||||
room_id,
|
||||
from,
|
||||
from: Some(from),
|
||||
to: None,
|
||||
dir,
|
||||
limit: default_limit(),
|
||||
@ -118,6 +128,32 @@ pub mod v3 {
|
||||
pub fn forward(room_id: &'a RoomId, from: &'a str) -> Self {
|
||||
Self::new(room_id, from, Direction::Forward)
|
||||
}
|
||||
|
||||
/// Creates a new `Request` to fetch messages from the very start of the available history
|
||||
/// for a given room.
|
||||
pub fn from_start(room_id: &'a RoomId) -> Self {
|
||||
Self {
|
||||
room_id,
|
||||
from: None,
|
||||
to: None,
|
||||
dir: Direction::Forward,
|
||||
limit: default_limit(),
|
||||
filter: RoomEventFilter::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new `Request` to fetch messages from the very end of the available history for
|
||||
/// a given room.
|
||||
pub fn from_end(room_id: &'a RoomId) -> Self {
|
||||
Self {
|
||||
room_id,
|
||||
from: None,
|
||||
to: None,
|
||||
dir: Direction::Backward,
|
||||
limit: default_limit(),
|
||||
filter: RoomEventFilter::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
@ -177,7 +213,7 @@ pub mod v3 {
|
||||
};
|
||||
let req = Request {
|
||||
room_id,
|
||||
from: "token",
|
||||
from: Some("token"),
|
||||
to: Some("token2"),
|
||||
dir: Direction::Backward,
|
||||
limit: uint!(0),
|
||||
@ -206,7 +242,7 @@ pub mod v3 {
|
||||
let room_id = room_id!("!roomid:example.org");
|
||||
let req = Request {
|
||||
room_id,
|
||||
from: "token",
|
||||
from: Some("token"),
|
||||
to: Some("token2"),
|
||||
dir: Direction::Backward,
|
||||
limit: uint!(0),
|
||||
|
Loading…
x
Reference in New Issue
Block a user