events: Make room::member types non-exhaustive
This commit is contained in:
parent
e1ab817e0b
commit
54cf81e9ab
@ -38,6 +38,7 @@ pub type MemberEvent = StateEvent<MemberEventContent>;
|
|||||||
|
|
||||||
/// The payload for `MemberEvent`.
|
/// The payload for `MemberEvent`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.room.member", kind = State)]
|
#[ruma_event(type = "m.room.member", kind = State)]
|
||||||
pub struct MemberEventContent {
|
pub struct MemberEventContent {
|
||||||
/// The avatar URL for this user, if any. This is added by the homeserver.
|
/// The avatar URL for this user, if any. This is added by the homeserver.
|
||||||
@ -55,8 +56,8 @@ pub struct MemberEventContent {
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub displayname: Option<String>,
|
pub displayname: Option<String>,
|
||||||
|
|
||||||
/// Flag indicating if the room containing this event was created
|
/// Flag indicating whether the room containing this event was created with the intention of
|
||||||
/// with the intention of being a direct chat.
|
/// being a direct chat.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub is_direct: Option<bool>,
|
pub is_direct: Option<bool>,
|
||||||
|
|
||||||
@ -70,6 +71,19 @@ pub struct MemberEventContent {
|
|||||||
pub third_party_invite: Option<ThirdPartyInvite>,
|
pub third_party_invite: Option<ThirdPartyInvite>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl MemberEventContent {
|
||||||
|
/// Creates a new `MemberEventContent` with the given membership state.
|
||||||
|
pub fn new(membership: MembershipState) -> Self {
|
||||||
|
Self {
|
||||||
|
membership,
|
||||||
|
avatar_url: None,
|
||||||
|
displayname: None,
|
||||||
|
is_direct: None,
|
||||||
|
third_party_invite: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The membership state of a user.
|
/// The membership state of a user.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||||
#[ruma_enum(rename_all = "lowercase")]
|
#[ruma_enum(rename_all = "lowercase")]
|
||||||
@ -95,19 +109,29 @@ pub enum MembershipState {
|
|||||||
|
|
||||||
/// Information about a third party invitation.
|
/// Information about a third party invitation.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct ThirdPartyInvite {
|
pub struct ThirdPartyInvite {
|
||||||
/// A name which can be displayed to represent the user instead of their third party
|
/// A name which can be displayed to represent the user instead of their third party
|
||||||
/// identifier.
|
/// identifier.
|
||||||
pub display_name: String,
|
pub display_name: String,
|
||||||
|
|
||||||
/// A block of content which has been signed, which servers can use to verify the event.
|
/// A block of content which has been signed, which servers can use to verify the event.
|
||||||
|
///
|
||||||
/// Clients should ignore this.
|
/// Clients should ignore this.
|
||||||
pub signed: SignedContent,
|
pub signed: SignedContent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ThirdPartyInvite {
|
||||||
|
/// Creates a new `ThirdPartyInvite` with the given display name and signed content.
|
||||||
|
pub fn new(display_name: String, signed: SignedContent) -> Self {
|
||||||
|
Self { display_name, signed }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A block of content which has been signed, which servers can use to verify a third party
|
/// A block of content which has been signed, which servers can use to verify a third party
|
||||||
/// invitation.
|
/// invitation.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct SignedContent {
|
pub struct SignedContent {
|
||||||
/// The invited Matrix user ID.
|
/// The invited Matrix user ID.
|
||||||
///
|
///
|
||||||
@ -118,10 +142,21 @@ pub struct SignedContent {
|
|||||||
/// section of the server-server API.
|
/// section of the server-server API.
|
||||||
pub signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
|
pub signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
|
||||||
|
|
||||||
/// The token property of the containing third_party_invite object.
|
/// The token property of the containing `third_party_invite` object.
|
||||||
pub token: String,
|
pub token: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SignedContent {
|
||||||
|
/// Creates a new `SignedContent` with the given mxid, signature and token.
|
||||||
|
pub fn new(
|
||||||
|
mxid: UserId,
|
||||||
|
signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
|
||||||
|
token: String,
|
||||||
|
) -> Self {
|
||||||
|
Self { mxid, signatures, token }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Translation of the membership change in `m.room.member` event.
|
/// Translation of the membership change in `m.room.member` event.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user