pub mod v1 {
use ruma_common::{
OwnedRoomId, OwnedUserId,
api::{request, response},
metadata,
serde::Raw,
};
use ruma_events::{
StateEventType,
room::{
member::{MembershipState, RoomMemberEventContent, ThirdPartyInvite},
third_party_invite::RoomThirdPartyInviteEventContent,
},
};
use crate::{authentication::ServerSignatures, thirdparty::bind_callback};
metadata! {
method: PUT,
rate_limited: false,
authentication: ServerSignatures,
path: "/_matrix/federation/v1/exchange_third_party_invite/{room_id}",
}
#[request]
pub struct Request {
#[ruma_api(path)]
pub room_id: OwnedRoomId,
#[serde(rename = "type")]
pub kind: StateEventType,
pub sender: OwnedUserId,
pub state_key: OwnedUserId,
pub content: Raw<RoomMemberEventContent>,
}
#[response]
#[derive(Default)]
pub struct Response {}
impl Request {
pub fn new(
room_id: OwnedRoomId,
sender: OwnedUserId,
state_key: OwnedUserId,
content: Raw<RoomMemberEventContent>,
) -> Self {
Self { room_id, kind: StateEventType::RoomMember, sender, state_key, content }
}
pub fn with_third_party_invite(
room_id: OwnedRoomId,
sender: OwnedUserId,
state_key: OwnedUserId,
third_party_invite: ThirdPartyInvite,
) -> Result<Self, serde_json::Error> {
let mut content = RoomMemberEventContent::new(MembershipState::Invite);
content.third_party_invite = Some(third_party_invite);
let content = Raw::new(&content)?;
Ok(Self::new(room_id, sender, state_key, content))
}
pub fn with_bind_callback_request_and_event(
bind_callback_invite: bind_callback::v1::ThirdPartyInvite,
room_third_party_invite_event: &RoomThirdPartyInviteEventContent,
) -> Result<Self, serde_json::Error> {
let third_party_invite = ThirdPartyInvite::new(
room_third_party_invite_event.display_name.clone(),
bind_callback_invite.signed,
);
Self::with_third_party_invite(
bind_callback_invite.room_id,
bind_callback_invite.sender,
bind_callback_invite.mxid,
third_party_invite,
)
}
}
impl Response {
pub fn new() -> Self {
Self {}
}
}
}