Allow custom values for more enums
This commit is contained in:
parent
70a12864ef
commit
d34a270919
@ -2,7 +2,6 @@
|
||||
|
||||
Breaking changes:
|
||||
|
||||
* Update strum dependency to 0.19
|
||||
* The `EndpointError` trait now requires `std::error::Error`. This allows integrating
|
||||
`EndpointError`s in the common rust error ecosystem like `thiserror` and `anyhow`.
|
||||
* The `Endpoint` trait has been replaced by two new traits that each capture a subset of its
|
||||
|
@ -24,7 +24,6 @@ ruma-identifiers = { version = "0.17.4", path = "../ruma-identifiers" }
|
||||
ruma-serde = { version = "0.2.3", path = "../ruma-serde" }
|
||||
serde = { version = "1.0.114", features = ["derive"] }
|
||||
serde_json = "1.0.57"
|
||||
strum = "0.19.2"
|
||||
thiserror = "1.0.20"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -201,10 +201,6 @@ pub enum DeserializationError {
|
||||
#[error("{0}")]
|
||||
Ident(#[from] ruma_identifiers::Error),
|
||||
|
||||
/// Path segment deserialization failed.
|
||||
#[error("{0}")]
|
||||
Strum(#[from] strum::ParseError),
|
||||
|
||||
/// Header value deserialization failed.
|
||||
#[error("{0}")]
|
||||
Header(#[from] http::header::ToStrError),
|
||||
|
@ -29,7 +29,6 @@ ruma-identifiers = { version = "0.17.4", path = "../ruma-identifiers" }
|
||||
ruma-serde = { version = "0.2.3", path = "../ruma-serde" }
|
||||
serde = { version = "1.0.114", features = ["derive"] }
|
||||
serde_json = "1.0.57"
|
||||
strum = { version = "0.19.2", features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
maplit = "1.0.2"
|
||||
|
@ -3,8 +3,8 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::StringEnum;
|
||||
use ruma_identifiers::{ServerNameBox, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -61,9 +61,11 @@ impl Response {
|
||||
}
|
||||
|
||||
/// Access token types.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[derive(Clone, Debug, StringEnum)]
|
||||
pub enum TokenType {
|
||||
/// Bearer token type
|
||||
Bearer,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
use maplit::btreemap;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::StringEnum;
|
||||
use ruma_identifiers::RoomVersionId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value as JsonValue;
|
||||
@ -150,14 +151,15 @@ impl Default for RoomVersionsCapability {
|
||||
}
|
||||
|
||||
/// The stability of a room version
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "lowercase")]
|
||||
pub enum RoomVersionStability {
|
||||
/// Support for the given version is stable.
|
||||
#[serde(rename = "stable")]
|
||||
Stable,
|
||||
|
||||
/// Support for the given version is unstable.
|
||||
#[serde(rename = "unstable")]
|
||||
Unstable,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -10,20 +10,22 @@ pub use lazy_load::LazyLoadOptions;
|
||||
pub use url::UrlFilter;
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_common::Outgoing;
|
||||
use ruma_common::{Outgoing, StringEnum};
|
||||
use ruma_identifiers::{RoomId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
/// Format to use for returned events.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum EventFormat {
|
||||
/// Client format, as described in the Client API.
|
||||
Client,
|
||||
|
||||
/// Raw events from federation.
|
||||
Federation,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
impl Default for EventFormat {
|
||||
@ -292,7 +294,7 @@ impl IncomingFilter {
|
||||
}
|
||||
|
||||
/// A filter definition
|
||||
#[derive(Clone, Copy, Debug, Default, Outgoing, Serialize)]
|
||||
#[derive(Clone, Debug, Default, Outgoing, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[incoming_derive(Clone, Default, Serialize)]
|
||||
pub struct FilterDefinition<'a> {
|
||||
|
@ -1,10 +1,9 @@
|
||||
//! [GET /_matrix/client/r0/rooms/{roomId}/members](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-members)
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::Raw;
|
||||
use ruma_common::{Raw, StringEnum};
|
||||
use ruma_events::room::member::MemberEvent;
|
||||
use ruma_identifiers::RoomId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -64,9 +63,8 @@ impl Response {
|
||||
}
|
||||
|
||||
/// The kind of membership events to filter for.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[derive(Clone, Debug, StringEnum)]
|
||||
#[ruma_enum(rename_all = "lowercase")]
|
||||
pub enum MembershipEventFilter {
|
||||
/// The user has joined.
|
||||
Join,
|
||||
@ -79,6 +77,9 @@ pub enum MembershipEventFilter {
|
||||
|
||||
/// The user has been banned.
|
||||
Ban,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -1,10 +1,7 @@
|
||||
//! Endpoints for push notifications.
|
||||
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use ruma_common::push::PusherData;
|
||||
use ruma_common::{push::PusherData, StringEnum};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
pub mod delete_pushrule;
|
||||
pub mod get_notifications;
|
||||
@ -20,12 +17,8 @@ pub mod set_pushrule_actions;
|
||||
pub mod set_pushrule_enabled;
|
||||
|
||||
/// The kinds of push rules that are available
|
||||
#[derive(
|
||||
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Display, EnumString,
|
||||
)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum RuleKind {
|
||||
/// User-configured rules that override all other kinds
|
||||
Override,
|
||||
@ -41,14 +34,9 @@ pub enum RuleKind {
|
||||
|
||||
/// Content-specific rules
|
||||
Content,
|
||||
}
|
||||
|
||||
impl TryFrom<&'_ str> for RuleKind {
|
||||
type Error = strum::ParseError;
|
||||
|
||||
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
||||
s.parse()
|
||||
}
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
/// Defines a pusher
|
||||
@ -82,12 +70,15 @@ pub struct Pusher {
|
||||
}
|
||||
|
||||
/// Which kind a pusher is
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[derive(Clone, Debug, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum PusherKind {
|
||||
/// A pusher that sends HTTP pokes.
|
||||
Http,
|
||||
|
||||
/// A pusher that emails the user with unread notifications.
|
||||
Email,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
//! [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid)
|
||||
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::{AsRefStr, DisplayAsRefStr, FromString};
|
||||
use ruma_identifiers::{EventId, RoomId};
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -51,18 +49,12 @@ impl Response {
|
||||
}
|
||||
|
||||
/// The type of receipt.
|
||||
#[derive(Clone, Copy, Debug, Display, EnumString)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[derive(Clone, Debug, AsRefStr, DisplayAsRefStr, FromString)]
|
||||
pub enum ReceiptType {
|
||||
/// m.read
|
||||
#[strum(serialize = "m.read")]
|
||||
#[ruma_enum(rename = "m.read")]
|
||||
Read,
|
||||
}
|
||||
|
||||
impl TryFrom<&'_ str> for ReceiptType {
|
||||
type Error = strum::ParseError;
|
||||
|
||||
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
||||
s.parse()
|
||||
}
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -5,18 +5,20 @@ pub mod get_room_event;
|
||||
pub mod report_content;
|
||||
pub mod upgrade_room;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ruma_common::StringEnum;
|
||||
|
||||
/// Whether or not a newly created room will be listed in the room directory.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum Visibility {
|
||||
/// Indicates that the room will be shown in the published room list.
|
||||
Public,
|
||||
|
||||
/// Indicates that the room will not be shown in the published room list.
|
||||
Private,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
impl Default for Visibility {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use assign::assign;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::Raw;
|
||||
use ruma_common::{Raw, StringEnum};
|
||||
use ruma_events::{
|
||||
room::{
|
||||
create::{CreateEventContent, PreviousRoom},
|
||||
@ -160,9 +160,8 @@ impl Default for CreationContent {
|
||||
}
|
||||
|
||||
/// A convenience parameter for setting a few default state events.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[derive(Clone, Debug, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum RoomPreset {
|
||||
/// `join_rules` is set to `invite` and `history_visibility` is set to `shared`.
|
||||
PrivateChat,
|
||||
@ -172,4 +171,7 @@ pub enum RoomPreset {
|
||||
|
||||
/// Same as `PrivateChat`, but all initial invitees get the same power level as the creator.
|
||||
TrustedPrivateChat,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use std::collections::BTreeMap;
|
||||
|
||||
use js_int::{uint, UInt};
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::{Outgoing, Raw};
|
||||
use ruma_common::{Outgoing, Raw, StringEnum};
|
||||
use ruma_events::{AnyRoomEvent, AnyStateEvent};
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -71,7 +71,7 @@ impl Categories<'_> {
|
||||
}
|
||||
|
||||
/// Criteria for searching a category of events.
|
||||
#[derive(Clone, Copy, Debug, Outgoing, Serialize)]
|
||||
#[derive(Clone, Debug, Outgoing, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct Criteria<'a> {
|
||||
/// The string to search events for.
|
||||
@ -216,7 +216,7 @@ impl EventContextResult {
|
||||
}
|
||||
|
||||
/// A grouping for partioning the result set.
|
||||
#[derive(Clone, Copy, Default, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct Grouping {
|
||||
/// The key within events to use for this grouping.
|
||||
@ -236,15 +236,17 @@ impl Grouping {
|
||||
}
|
||||
|
||||
/// The key within events to use for this grouping.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, PartialOrd, Ord, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum GroupingKey {
|
||||
/// `room_id`
|
||||
RoomId,
|
||||
|
||||
/// `sender`
|
||||
Sender,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
/// Requests that the server partitions the result set based on the provided list of keys.
|
||||
@ -270,26 +272,28 @@ impl Groupings<'_> {
|
||||
}
|
||||
|
||||
/// The keys to search for.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[derive(Clone, Debug, StringEnum)]
|
||||
pub enum SearchKeys {
|
||||
/// content.body
|
||||
#[serde(rename = "content.body")]
|
||||
#[ruma_enum(rename = "content.body")]
|
||||
ContentBody,
|
||||
|
||||
/// content.name
|
||||
#[serde(rename = "content.name")]
|
||||
#[ruma_enum(rename = "content.name")]
|
||||
ContentName,
|
||||
|
||||
/// content.topic
|
||||
#[serde(rename = "content.topic")]
|
||||
#[ruma_enum(rename = "content.topic")]
|
||||
ContentTopic,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
/// The order in which to search for results.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, StringEnum)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum OrderBy {
|
||||
/// Prioritize recent events.
|
||||
Recent,
|
||||
@ -297,6 +301,9 @@ pub enum OrderBy {
|
||||
/// Prioritize events by a numerical ranking of how closely they matched the search
|
||||
/// criteria.
|
||||
Rank,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
/// Categories of events that can be searched for.
|
||||
|
@ -78,7 +78,7 @@ impl Response {
|
||||
}
|
||||
|
||||
/// Identification information for the user.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Outgoing, Serialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Outgoing, Serialize)]
|
||||
#[serde(from = "user_serde::IncomingUserInfo", into = "user_serde::UserInfo")]
|
||||
pub enum UserInfo<'a> {
|
||||
/// Either a fully qualified Matrix user ID, or just the localpart (as part of the 'identifier'
|
||||
|
@ -29,7 +29,7 @@ ruma_api! {
|
||||
/// A filter represented either as its full JSON definition or the ID of a saved filter.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[ruma_api(query)]
|
||||
pub filter: Option<Filter<'a>>,
|
||||
pub filter: Option<&'a Filter<'a>>,
|
||||
|
||||
/// A point in time to continue a sync from.
|
||||
///
|
||||
@ -45,9 +45,11 @@ ruma_api! {
|
||||
pub full_state: bool,
|
||||
|
||||
/// Controls whether the client is automatically marked as online by polling this API.
|
||||
///
|
||||
/// Defaults to `PresenceState::Online`.
|
||||
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
|
||||
#[ruma_api(query)]
|
||||
pub set_presence: PresenceState,
|
||||
pub set_presence: &'a PresenceState,
|
||||
|
||||
/// The maximum time to poll in milliseconds before returning this request.
|
||||
#[serde(
|
||||
@ -117,7 +119,7 @@ impl Response {
|
||||
}
|
||||
|
||||
/// A filter represented either as its full JSON definition or the ID of a saved filter.
|
||||
#[derive(Clone, Copy, Debug, Outgoing, Serialize)]
|
||||
#[derive(Clone, Debug, Outgoing, Serialize)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
#[serde(untagged)]
|
||||
pub enum Filter<'a> {
|
||||
@ -539,10 +541,10 @@ mod tests {
|
||||
#[test]
|
||||
fn serialize_all_params() {
|
||||
let req: http::Request<Vec<u8>> = Request {
|
||||
filter: Some(Filter::FilterId("66696p746572")),
|
||||
filter: Some(&Filter::FilterId("66696p746572")),
|
||||
since: Some("s72594_4483_1934"),
|
||||
full_state: true,
|
||||
set_presence: PresenceState::Offline,
|
||||
set_presence: &PresenceState::Offline,
|
||||
timeout: Some(Duration::from_millis(30000)),
|
||||
}
|
||||
.try_into_http_request("https://homeserver.tld", Some("auth_tok"))
|
||||
|
@ -18,16 +18,18 @@ async fn log_messages(homeserver_url: Uri, username: &str, password: &str) -> an
|
||||
|
||||
client.log_in(username, password, None, None).await?;
|
||||
|
||||
// FIXME: Possibly promotable when replacing `.into()` if `ignore_all` is made const.
|
||||
let filter = FilterDefinition::ignore_all().into();
|
||||
let initial_sync_response = client
|
||||
.request(assign!(sync_events::Request::new(), {
|
||||
filter: Some(FilterDefinition::ignore_all().into()),
|
||||
filter: Some(&filter),
|
||||
}))
|
||||
.await?;
|
||||
|
||||
let mut sync_stream = Box::pin(client.sync(
|
||||
None,
|
||||
initial_sync_response.next_batch,
|
||||
PresenceState::Online,
|
||||
&PresenceState::Online,
|
||||
Some(Duration::from_secs(30)),
|
||||
));
|
||||
|
||||
|
@ -54,7 +54,7 @@
|
||||
//! let mut sync_stream = Box::pin(client.sync(
|
||||
//! None,
|
||||
//! next_batch_token,
|
||||
//! PresenceState::Online,
|
||||
//! &PresenceState::Online,
|
||||
//! Some(Duration::from_secs(30)),
|
||||
//! ));
|
||||
//! while let Some(response) = sync_stream.try_next().await? {
|
||||
@ -281,9 +281,9 @@ impl Client {
|
||||
/// Convenience method that represents repeated calls to the sync_events endpoint as a stream.
|
||||
pub fn sync<'a>(
|
||||
&self,
|
||||
filter: Option<SyncFilter<'a>>,
|
||||
filter: Option<&'a SyncFilter<'a>>,
|
||||
since: String,
|
||||
set_presence: ruma_common::presence::PresenceState,
|
||||
set_presence: &'a ruma_common::presence::PresenceState,
|
||||
timeout: Option<Duration>,
|
||||
) -> impl Stream<Item = Result<SyncResponse, Error<ruma_client_api::Error>>>
|
||||
+ TryStream<Ok = SyncResponse, Error = Error<ruma_client_api::Error>>
|
||||
|
@ -17,7 +17,6 @@ ruma-identifiers = { version = "0.17.4", path = "../ruma-identifiers" }
|
||||
ruma-serde = { version = "0.2.3", path = "../ruma-serde" }
|
||||
serde = { version = "1.0.114", features = ["derive"] }
|
||||
serde_json = { version = "1.0.57", features = ["raw_value"] }
|
||||
strum = { version = "0.19.2", features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
matches = "0.1.8"
|
||||
|
@ -2,14 +2,11 @@
|
||||
//!
|
||||
//! [presence]: https://matrix.org/docs/spec/client_server/r0.6.1#id62
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumString};
|
||||
use crate::StringEnum;
|
||||
|
||||
/// A description of a user's connectivity and availability for chat.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum PresenceState {
|
||||
/// Disconnected from the service.
|
||||
Offline,
|
||||
@ -19,6 +16,9 @@ pub enum PresenceState {
|
||||
|
||||
/// Connected to the service but not available for chat.
|
||||
Unavailable,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
impl Default for PresenceState {
|
||||
@ -26,3 +26,9 @@ impl Default for PresenceState {
|
||||
Self::Online
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for &'_ PresenceState {
|
||||
fn default() -> Self {
|
||||
&PresenceState::Online
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
//!
|
||||
//! [push]: https://matrix.org/docs/spec/client_server/r0.6.1#id89
|
||||
|
||||
use ruma_common::StringEnum;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
mod action;
|
||||
@ -237,10 +238,12 @@ impl PusherData {
|
||||
/// Currently, only "event_id_only" is supported as of [Push Gateway API r0.1.1][spec].
|
||||
///
|
||||
/// [spec]: https://matrix.org/docs/spec/push_gateway/r0.1.1#homeserver-behaviour
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[derive(Clone, Debug, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum PushFormat {
|
||||
/// Require the homeserver to only send a reduced set of fields in the push.
|
||||
EventIdOnly,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma_common::StringEnum;
|
||||
use ruma_identifiers::{RoomAliasId, UserId};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -190,13 +191,15 @@ impl User {
|
||||
}
|
||||
|
||||
/// The medium of a third party identifier.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "lowercase")]
|
||||
pub enum Medium {
|
||||
/// Email address identifier
|
||||
Email,
|
||||
|
||||
/// Phone number identifier
|
||||
MSISDN,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ ruma-identifiers = { version = "0.17.4", path = "../ruma-identifiers" }
|
||||
ruma-serde = { version = "0.2.3", path = "../ruma-serde" }
|
||||
serde = { version = "1.0.114", features = ["derive"] }
|
||||
serde_json = { version = "1.0.57", features = ["raw_value"] }
|
||||
strum = { version = "0.19.2", features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
maplit = "1.0.2"
|
||||
|
@ -2,8 +2,8 @@
|
||||
//!
|
||||
//! This module also contains types shared by events in its child namespaces.
|
||||
|
||||
use ruma_common::StringEnum;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
pub mod answer;
|
||||
pub mod candidates;
|
||||
@ -30,14 +30,15 @@ impl SessionDescription {
|
||||
}
|
||||
|
||||
/// The type of VoIP session description.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum SessionDescriptionType {
|
||||
/// An answer.
|
||||
Answer,
|
||||
|
||||
/// An offer.
|
||||
Offer,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
//! Types for the *m.call.hangup* event.
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_common::StringEnum;
|
||||
use ruma_events_macros::MessageEventContent;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
use crate::MessageEvent;
|
||||
|
||||
@ -31,14 +31,15 @@ pub struct HangupEventContent {
|
||||
/// This should not be provided when the user naturally ends or rejects the call. When there was an
|
||||
/// error in the call negotiation, this should be `ice_failed` for when ICE negotiation fails or
|
||||
/// `invite_timeout` for when the other party did not answer in time.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum Reason {
|
||||
/// ICE negotiation failure.
|
||||
IceFailed,
|
||||
|
||||
/// Party did not answer in time.
|
||||
InviteTimeout,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ use ruma_common::StringEnum;
|
||||
// FIXME: Add `m.foo.bar` or `m.foo_bar` as a naming scheme in StringEnum and remove most rename
|
||||
// attributes.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, StringEnum)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub enum EventType {
|
||||
/// m.call.answer
|
||||
#[ruma_enum(rename = "m.call.answer")]
|
||||
|
@ -2,8 +2,7 @@
|
||||
//!
|
||||
//! This module also contains types shared by events in its child namespaces.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumString};
|
||||
use ruma_common::StringEnum;
|
||||
|
||||
pub mod accept;
|
||||
pub mod cancel;
|
||||
@ -13,62 +12,67 @@ pub mod request;
|
||||
pub mod start;
|
||||
|
||||
/// A hash algorithm.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Serialize, Deserialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum HashAlgorithm {
|
||||
/// The SHA256 hash algorithm.
|
||||
Sha256,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
/// A key agreement protocol.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Serialize, Deserialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
#[strum(serialize_all = "kebab-case")]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "kebab-case")]
|
||||
pub enum KeyAgreementProtocol {
|
||||
/// The [Curve25519](https://cr.yp.to/ecdh.html) key agreement protocol.
|
||||
Curve25519,
|
||||
|
||||
/// The Curve25519 key agreement protocol with check for public keys.
|
||||
Curve25519HkdfSha256,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
/// A message authentication code algorithm.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Serialize, Deserialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
#[strum(serialize_all = "kebab-case")]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "kebab-case")]
|
||||
pub enum MessageAuthenticationCode {
|
||||
/// The HKDF-HMAC-SHA256 MAC.
|
||||
HkdfHmacSha256,
|
||||
|
||||
/// The HMAC-SHA256 MAC.
|
||||
HmacSha256,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
/// A Short Authentication String method.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Serialize, Deserialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum ShortAuthenticationString {
|
||||
/// The decimal method.
|
||||
Decimal,
|
||||
|
||||
/// The emoji method.
|
||||
Emoji,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
/// A Short Authentication String (SAS) verification method.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
pub enum VerificationMethod {
|
||||
/// The *m.sas.v1* verification method.
|
||||
#[serde(rename = "m.sas.v1")]
|
||||
#[strum(serialize = "m.sas.v1")]
|
||||
#[ruma_enum(rename = "m.sas.v1")]
|
||||
MSasV1,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -36,7 +36,6 @@ pub struct CancelEventContent {
|
||||
/// obtained through `.as_str()`.
|
||||
// FIXME: Add `m.foo_bar` as a naming scheme in StringEnum and remove rename attributes.
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub enum CancelCode {
|
||||
/// The user cancelled the verification.
|
||||
#[ruma_enum(rename = "m.user")]
|
||||
|
@ -1,7 +1,6 @@
|
||||
//! Modules and types for events in the *m.policy.rule* namespace.
|
||||
|
||||
use std::fmt::{Display, Formatter, Result as FmtResult};
|
||||
|
||||
use ruma_common::StringEnum;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod room;
|
||||
@ -30,31 +29,19 @@ impl PolicyRuleEventContent {
|
||||
}
|
||||
|
||||
/// Rules recommendations
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[derive(Clone, Debug, StringEnum)]
|
||||
pub enum Recommendation {
|
||||
/// Entities affected by the rule should be banned from participation where possible.
|
||||
#[serde(rename = "m.ban")]
|
||||
#[ruma_enum(rename = "m.ban")]
|
||||
Ban,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
impl Recommendation {
|
||||
/// Creates a string slice from this `Recommendation`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
match *self {
|
||||
Recommendation::Ban => "m.ban",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Recommendation {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
f.write_str(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Recommendation> for String {
|
||||
fn from(recommendation: Recommendation) -> String {
|
||||
recommendation.to_string()
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
//! Types for the *m.room.guest_access* event.
|
||||
|
||||
use ruma_common::StringEnum;
|
||||
use ruma_events_macros::StateEventContent;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
use crate::StateEvent;
|
||||
|
||||
@ -29,14 +29,15 @@ impl GuestAccessEventContent {
|
||||
}
|
||||
|
||||
/// A policy for guest user access to a room.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum GuestAccess {
|
||||
/// Guests are allowed to join the room.
|
||||
CanJoin,
|
||||
|
||||
/// Guests are not allowed to join the room.
|
||||
Forbidden,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
//! Types for the *m.room.history_visibility* event.
|
||||
|
||||
use ruma_common::StringEnum;
|
||||
use ruma_events_macros::StateEventContent;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
use crate::StateEvent;
|
||||
|
||||
@ -28,10 +28,8 @@ impl HistoryVisibilityEventContent {
|
||||
}
|
||||
|
||||
/// Who can see a room's history.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum HistoryVisibility {
|
||||
/// Previous events are accessible to newly joined members from the point they were invited
|
||||
/// onwards. Events stop being accessible when the member's state changes to something other
|
||||
@ -50,4 +48,7 @@ pub enum HistoryVisibility {
|
||||
/// All events while this is the `HistoryVisibility` value may be shared by any
|
||||
/// participating homeserver with anyone, regardless of whether they have ever joined the room.
|
||||
WorldReadable,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
//! Types for the *m.room.join_rules* event.
|
||||
|
||||
use ruma_common::StringEnum;
|
||||
use ruma_events_macros::StateEventContent;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
use crate::StateEvent;
|
||||
|
||||
@ -27,10 +27,8 @@ impl JoinRulesEventContent {
|
||||
}
|
||||
|
||||
/// The rule used for users wishing to join this room.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "lowercase")]
|
||||
pub enum JoinRule {
|
||||
/// A user who wishes to join the room must first receive an invite to the room from someone
|
||||
/// already inside of the room.
|
||||
@ -44,4 +42,7 @@ pub enum JoinRule {
|
||||
|
||||
/// Anyone can join the room without any prior action.
|
||||
Public,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma_common::StringEnum;
|
||||
use ruma_events_macros::StateEventContent;
|
||||
use ruma_identifiers::{ServerKeyId, ServerNameBox, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
use crate::{StateEvent, StrippedStateEvent, SyncStateEvent};
|
||||
|
||||
@ -64,10 +64,8 @@ pub struct MemberEventContent {
|
||||
}
|
||||
|
||||
/// The membership state of a user.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "lowercase")]
|
||||
pub enum MembershipState {
|
||||
/// The user is banned.
|
||||
Ban,
|
||||
@ -83,6 +81,9 @@ pub enum MembershipState {
|
||||
|
||||
/// The user has left.
|
||||
Leave,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
/// Information about a third party invitation.
|
||||
@ -187,7 +188,7 @@ fn membership_change(
|
||||
}
|
||||
};
|
||||
|
||||
match (prev_content.membership, &content.membership) {
|
||||
match (&prev_content.membership, &content.membership) {
|
||||
(St::Invite, St::Invite) | (St::Leave, St::Leave) | (St::Ban, St::Ban) => Ch::None,
|
||||
(St::Invite, St::Join) | (St::Leave, St::Join) => Ch::Joined,
|
||||
(St::Invite, St::Leave) => {
|
||||
@ -213,7 +214,7 @@ fn membership_change(
|
||||
(St::Join, St::Ban) => Ch::KickedAndBanned,
|
||||
(St::Leave, St::Invite) => Ch::Invited,
|
||||
(St::Ban, St::Leave) => Ch::Unbanned,
|
||||
(St::Knock, _) | (_, St::Knock) => Ch::NotImplemented,
|
||||
_ => Ch::NotImplemented,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,24 +287,28 @@ pub struct ServerNoticeMessageEventContent {
|
||||
}
|
||||
|
||||
/// Types of server notices.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[derive(Clone, Debug, StringEnum)]
|
||||
pub enum ServerNoticeType {
|
||||
/// The server has exceeded some limit which requires the server administrator to intervene.
|
||||
#[serde(rename = "m.server_notice.usage_limit_reached")]
|
||||
#[ruma_enum(rename = "m.server_notice.usage_limit_reached")]
|
||||
UsageLimitReached,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
/// Types of usage limits.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[derive(Clone, Debug, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum LimitType {
|
||||
/// The server's number of active users in the last 30 days has exceeded the maximum.
|
||||
///
|
||||
/// New connections are being refused by the server. What defines "active" is left as an
|
||||
/// implementation detail, however servers are encouraged to treat syncing users as "active".
|
||||
MonthlyActiveUser,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
/// The format for the formatted representation of a message body.
|
||||
@ -313,7 +317,6 @@ pub enum LimitType {
|
||||
/// available as a documented variant here, use its string representation,
|
||||
/// obtained through `.as_str()`.
|
||||
#[derive(Clone, Debug, StringEnum)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub enum MessageFormat {
|
||||
/// HTML.
|
||||
#[ruma_enum(rename = "org.matrix.custom.html")]
|
||||
|
@ -1,9 +1,9 @@
|
||||
//! Types for the *m.room.message.feedback* event.
|
||||
|
||||
use ruma_common::StringEnum;
|
||||
use ruma_events_macros::MessageEventContent;
|
||||
use ruma_identifiers::EventId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
use crate::MessageEvent;
|
||||
|
||||
@ -34,14 +34,15 @@ impl FeedbackEventContent {
|
||||
}
|
||||
|
||||
/// A type of feedback.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum FeedbackType {
|
||||
/// Sent when a message is received.
|
||||
Delivered,
|
||||
|
||||
/// Sent when a message has been observed by the end user.
|
||||
Read,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
//! Types for the *m.room_key_request* event.
|
||||
|
||||
use ruma_common::StringEnum;
|
||||
use ruma_events_macros::BasicEventContent;
|
||||
use ruma_identifiers::{DeviceIdBox, EventEncryptionAlgorithm, RoomId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
use crate::BasicEvent;
|
||||
|
||||
@ -35,18 +35,18 @@ pub struct RoomKeyRequestEventContent {
|
||||
}
|
||||
|
||||
/// A new key request or a cancellation of a previous request.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum Action {
|
||||
/// Request a key.
|
||||
Request,
|
||||
|
||||
/// Cancel a request for a key.
|
||||
#[serde(rename = "request_cancellation")]
|
||||
#[strum(serialize = "request_cancellation")]
|
||||
#[ruma_enum(rename = "request_cancellation")]
|
||||
CancelRequest,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
/// Information about a requested key.
|
||||
|
@ -1,8 +1,8 @@
|
||||
//! [GET /_matrix/federation/v1/query/profile](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-query-profile)
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::StringEnum;
|
||||
use ruma_identifiers::UserId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -22,7 +22,7 @@ ruma_api! {
|
||||
/// Profile field to query.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[ruma_api(query)]
|
||||
pub field: Option<ProfileField>,
|
||||
pub field: Option<&'a ProfileField>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@ -52,13 +52,16 @@ impl Response {
|
||||
}
|
||||
|
||||
/// Profile fields to specify in query.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
pub enum ProfileField {
|
||||
/// Display name of the user.
|
||||
#[serde(rename = "displayname")]
|
||||
#[ruma_enum(rename = "displayname")]
|
||||
DisplayName,
|
||||
|
||||
/// Avatar URL for the user's avatar.
|
||||
#[serde(rename = "avatar_url")]
|
||||
#[ruma_enum(rename = "avatar_url")]
|
||||
AvatarUrl,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ ruma-identifiers-validation = { version = "0.1.1", path = "../ruma-identifiers-v
|
||||
ruma-serde = { version = "0.2.3", path = "../ruma-serde" }
|
||||
# Renamed so we can have a serde feature.
|
||||
serde1 = { package = "serde", version = "1.0.114", optional = true, features = ["derive"] }
|
||||
strum = { version = "0.19.2", features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
matches = "0.1.8"
|
||||
|
@ -19,7 +19,6 @@ ruma-identifiers = { version = "0.17.4", path = "../ruma-identifiers" }
|
||||
ruma-serde = { version = "0.2.3", path = "../ruma-serde" }
|
||||
serde = { version = "1.0.114", features = ["derive"] }
|
||||
serde_json = "1.0.57"
|
||||
strum = { version = "0.19.2", features = ["derive"] }
|
||||
|
||||
[features]
|
||||
unstable-exhaustive-types = []
|
||||
|
@ -4,14 +4,13 @@ use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::{
|
||||
push::{PusherData, Tweak},
|
||||
Outgoing,
|
||||
Outgoing, StringEnum,
|
||||
};
|
||||
use ruma_events::EventType;
|
||||
use ruma_identifiers::{EventId, RoomAliasId, RoomId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
use std::time::SystemTime;
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -137,16 +136,17 @@ impl<'a> Notification<'a> {
|
||||
///
|
||||
/// This may be used by push gateways to deliver less time-sensitive
|
||||
/// notifications in a way that will preserve battery power on mobile devices.
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[derive(Clone, Debug, PartialEq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum NotificationPriority {
|
||||
/// A high priority notification
|
||||
High,
|
||||
|
||||
/// A low priority notification
|
||||
Low,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(String),
|
||||
}
|
||||
|
||||
impl Default for NotificationPriority {
|
||||
|
@ -15,6 +15,7 @@ version = "0.6.0-dev.1"
|
||||
[dependencies]
|
||||
base64 = "0.12.3"
|
||||
ring = "0.16.15"
|
||||
ruma-common = { version = "0.2.0", path = "../ruma-common" }
|
||||
ruma-identifiers = { version = "0.17.4", path = "../ruma-identifiers" }
|
||||
ruma-serde = { version = "0.2.3", path = "../ruma-serde" }
|
||||
serde_json = "1.0.57"
|
||||
|
@ -49,6 +49,8 @@ use std::{
|
||||
fmt::{Display, Formatter, Result as FmtResult},
|
||||
};
|
||||
|
||||
use ruma_common::{AsRefStr, DisplayAsRefStr};
|
||||
|
||||
pub use functions::{
|
||||
canonical_json, content_hash, hash_and_sign_event, redact, reference_hash, sign_json,
|
||||
verify_event, verify_json,
|
||||
@ -114,22 +116,13 @@ impl From<ruma_serde::CanonicalJsonError> for Error {
|
||||
}
|
||||
|
||||
/// The algorithm used for signing data.
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, AsRefStr, DisplayAsRefStr)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
pub enum Algorithm {
|
||||
/// The Ed25519 digital signature algorithm.
|
||||
Ed25519,
|
||||
}
|
||||
|
||||
impl Display for Algorithm {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
let name = match *self {
|
||||
Self::Ed25519 => "ed25519",
|
||||
};
|
||||
|
||||
write!(f, "{}", name)
|
||||
}
|
||||
}
|
||||
|
||||
/// An error when trying to extract the algorithm and version from a key identifier.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
enum SplitError<'a> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user