diff --git a/CHANGELOG.md b/CHANGELOG.md index cd03b19b..02c074b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Breaking changes: request. * Add `M_USER_DEACTIVATED` to `error::ErrorKind` * Make `display_name` field of `r0::membership::joined_events::RoomMember` optional +* Update `r0::search::search_events` to r0.6.0 Improvements: diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index 525c6bbf..ee0bb836 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -4,7 +4,10 @@ use std::collections::BTreeMap; use js_int::UInt; use ruma_api::ruma_api; -use ruma_events::{collections::all::Event, EventJson}; +use ruma_events::{ + collections::all::{Event, StateEvent}, + EventJson, +}; use ruma_identifiers::{EventId, RoomId, UserId}; use serde::{Deserialize, Serialize}; @@ -53,8 +56,6 @@ pub struct Criteria { #[serde(skip_serializing_if = "Option::is_none")] pub event_context: Option, /// A `Filter` to apply to the search. - // TODO: "timeline" key might need to be included. - // See https://github.com/matrix-org/matrix-doc/issues/598. #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option, /// Requests that the server partitions the result set based on the provided list of keys. @@ -77,9 +78,11 @@ pub struct Criteria { #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct EventContext { /// How many events after the result are returned. - pub after_limit: UInt, + #[serde(skip_serializing_if = "Option::is_none")] + pub after_limit: Option, /// How many events before the result are returned. - pub before_limit: UInt, + #[serde(skip_serializing_if = "Option::is_none")] + pub before_limit: Option, /// Requests that the server returns the historic profile information for the users that /// sent the events that were returned. pub include_profile: bool, @@ -89,26 +92,27 @@ pub struct EventContext { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct EventContextResult { /// Pagination token for the end of the chunk. - pub end: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub end: Option, /// Events just after the result. - #[serde(skip_serializing_if = "Option::is_none")] - pub events_after: Option>>, + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub events_after: Vec>, /// Events just before the result. - #[serde(skip_serializing_if = "Option::is_none")] - pub events_before: Option>>, + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub events_before: Vec>, /// The historic profile information of the users that sent the events returned. - // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 #[serde(skip_serializing_if = "Option::is_none")] pub profile_info: Option>, /// Pagination token for the start of the chunk. - pub start: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub start: Option, } /// A grouping for partioning the result set. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct Grouping { /// The key within events to use for this grouping. - pub key: GroupingKey, + pub key: Option, } /// The key within events to use for this grouping. @@ -125,6 +129,7 @@ pub enum GroupingKey { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Groupings { /// List of groups to request. + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub group_by: Vec, } @@ -167,8 +172,7 @@ pub struct RoomEventJsons { /// An approximate count of the total number of results found. pub count: UInt, /// Any groups that were requested. - // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 - pub groups: BTreeMap>, + pub groups: BTreeMap>, /// Token that can be used to get the next batch of results, by passing as the `next_batch` /// parameter to the next call. If this field is absent, there are no more results. #[serde(skip_serializing_if = "Option::is_none")] @@ -177,9 +181,12 @@ pub struct RoomEventJsons { pub results: Vec, /// The current state for every room in the results. This is included if the request had the /// `include_state` key set with a value of `true`. - #[serde(skip_serializing_if = "Option::is_none")] - // TODO: Major WTF here. https://github.com/matrix-org/matrix-doc/issues/773 - pub state: Option<()>, + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub state: BTreeMap>>, + /// List of words which should be highlighted, useful for stemming which may + /// change the query terms. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub highlights: Vec, } /// A grouping of results, if requested. @@ -203,9 +210,11 @@ pub struct SearchResult { #[serde(skip_serializing_if = "Option::is_none")] pub context: Option, /// A number that describes how closely this result matches the search. Higher is closer. - pub rank: f64, + #[serde(skip_serializing_if = "Option::is_none")] + pub rank: Option, /// The event that matched. - pub result: EventJson, + #[serde(skip_serializing_if = "Option::is_none")] + pub result: Option>, } /// A user profile. @@ -218,3 +227,12 @@ pub struct UserProfile { #[serde(skip_serializing_if = "Option::is_none")] pub displayname: Option, } + +/// Represents either a room or user ID for returning grouped search results. +#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] +pub enum RoomIdOrUserId { + /// Represents a room ID. + RoomId(RoomId), + /// Represents a user ID. + UserId(UserId), +}