Change get_message_events Request limit field from Option<UInt> to UInt

This commit is contained in:
Alan Darmasaputra 2020-06-18 22:18:17 +07:00 committed by GitHub
parent 1aed6ab52b
commit 4abcc4c0bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View File

@ -47,9 +47,9 @@ ruma_api! {
/// The maximum number of events to return.
///
/// Default: 10.
#[serde(skip_serializing_if = "Option::is_none")]
#[ruma_api(query)]
pub limit: Option<UInt>,
#[serde(default = "default_limit", skip_serializing_if = "is_default_limit")]
pub limit: UInt,
/// A RoomEventFilter to filter returned events with.
#[ruma_api(query)]
@ -82,6 +82,15 @@ ruma_api! {
error: crate::Error
}
fn default_limit() -> UInt {
UInt::from(10u32)
}
#[allow(clippy::trivially_copy_pass_by_ref)]
fn is_default_limit(val: &UInt) -> bool {
*val == default_limit()
}
/// The direction to return events from.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum Direction {
@ -120,7 +129,7 @@ mod tests {
from: "token".into(),
to: Some("token2".into()),
dir: Direction::Backward,
limit: Some(UInt::from(0u32)),
limit: UInt::from(0u32),
filter: Some(filter),
};
@ -139,7 +148,7 @@ mod tests {
from: "token".into(),
to: Some("token2".into()),
dir: Direction::Backward,
limit: Some(UInt::from(0u32)),
limit: UInt::from(0u32),
filter: None,
};
@ -155,7 +164,7 @@ mod tests {
from: "token".into(),
to: Some("token2".into()),
dir: Direction::Backward,
limit: Some(UInt::from(0u32)),
limit: UInt::from(0u32),
filter: Some(RoomEventFilter::default()),
};

View File

@ -2,6 +2,7 @@
Breaking changes:
* Change `get_message_events` limit field type from `Option<UInt>` to `UInt`
* Add `alt_aliases` to `CanonicalAliasEventContent`
* Replace `format` and `formatted_body` fields in `TextMessagEventContent`,
`NoticeMessageEventContent` and `EmoteMessageEventContent` with `formatted: FormattedBody`