common: Add join_rule to directory::PublicRoomsChunk
This commit is contained in:
parent
0be32f989b
commit
2047dbf420
@ -4,7 +4,7 @@ use std::fmt;
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{MxcUri, RoomAliasId, RoomId, RoomName};
|
||||
use ruma_serde::Outgoing;
|
||||
use ruma_serde::{Outgoing, StringEnum};
|
||||
use serde::{
|
||||
de::{Error, MapAccess, Visitor},
|
||||
ser::SerializeStruct,
|
||||
@ -12,6 +12,8 @@ use serde::{
|
||||
};
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
use crate::PrivOwnedStr;
|
||||
|
||||
/// A chunk of a room list response, describing one room.
|
||||
///
|
||||
/// To create an instance of this type, first create a `PublicRoomsChunkInit` and convert it via
|
||||
@ -59,6 +61,10 @@ pub struct PublicRoomsChunk {
|
||||
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||
)]
|
||||
pub avatar_url: Option<Box<MxcUri>>,
|
||||
|
||||
/// The join rule of the room.
|
||||
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
|
||||
pub join_rule: PublicRoomJoinRule,
|
||||
}
|
||||
|
||||
/// Initial set of mandatory fields of `PublicRoomsChunk`.
|
||||
@ -97,6 +103,7 @@ impl From<PublicRoomsChunkInit> for PublicRoomsChunk {
|
||||
world_readable,
|
||||
guest_can_join,
|
||||
avatar_url: None,
|
||||
join_rule: PublicRoomJoinRule::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -223,6 +230,37 @@ impl<'de> Visitor<'de> for RoomNetworkVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
/// The rule used for users wishing to join a public room.
|
||||
///
|
||||
/// This type can hold an arbitrary string. To check for join rules that are not available as a
|
||||
/// documented variant here, use its string representation, obtained through `.as_str()`.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub enum PublicRoomJoinRule {
|
||||
/// Users can request an invite to the room.
|
||||
Knock,
|
||||
|
||||
/// Anyone can join the room without any prior action.
|
||||
Public,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl PublicRoomJoinRule {
|
||||
/// Returns the string name of this `PublicRoomJoinRule`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PublicRoomJoinRule {
|
||||
fn default() -> Self {
|
||||
Self::Public
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||
|
Loading…
x
Reference in New Issue
Block a user