ruma_state_res/events/
third_party_invite.rs1use std::{collections::BTreeSet, ops::Deref};
4
5use ruma_common::{serde::from_raw_json_value, third_party_invite::IdentityServerBase64PublicKey};
6use serde::Deserialize;
7
8use super::Event;
9
10#[derive(Debug, Clone)]
14pub struct RoomThirdPartyInviteEvent<E: Event>(E);
15
16impl<E: Event> RoomThirdPartyInviteEvent<E> {
17 pub fn new(event: E) -> Self {
19 Self(event)
20 }
21
22 pub fn public_keys(&self) -> Result<BTreeSet<IdentityServerBase64PublicKey>, String> {
24 #[derive(Deserialize)]
25 struct RoomThirdPartyInviteContentPublicKeys {
26 public_key: Option<IdentityServerBase64PublicKey>,
27 #[serde(default)]
28 public_keys: Vec<PublicKey>,
29 }
30
31 #[derive(Deserialize)]
32 struct PublicKey {
33 public_key: IdentityServerBase64PublicKey,
34 }
35
36 let content: RoomThirdPartyInviteContentPublicKeys = from_raw_json_value(self.content())
37 .map_err(|err: serde_json::Error| {
38 format!("invalid `public_key` or `public_keys` field in `m.room.third_party_invite` event: {err}")
39 })?;
40 Ok(content
41 .public_key
42 .into_iter()
43 .chain(content.public_keys.into_iter().map(|k| k.public_key))
44 .collect())
45 }
46}
47
48impl<E: Event> Deref for RoomThirdPartyInviteEvent<E> {
49 type Target = E;
50
51 fn deref(&self) -> &Self::Target {
52 &self.0
53 }
54}