tuwunel_api/client/
thirdparty.rs1use axum::extract::State;
2use ruma::api::client::thirdparty::{
3 get_location_for_protocol, get_location_for_room_alias, get_protocol, get_protocols,
4 get_user_for_protocol, get_user_for_user_id,
5};
6use tuwunel_core::{Result, err};
7
8use crate::Ruma;
9
10pub(crate) async fn get_protocols_route(
17 State(services): State<crate::State>,
18 _body: Ruma<get_protocols::v3::Request>,
19) -> Result<get_protocols::v3::Response> {
20 let protocols = services
21 .appservice
22 .thirdparty_protocols(None)
23 .await;
24
25 Ok(get_protocols::v3::Response { protocols })
26}
27
28pub(crate) async fn get_protocol_route(
34 State(services): State<crate::State>,
35 body: Ruma<get_protocol::v3::Request>,
36) -> Result<get_protocol::v3::Response> {
37 let protocol = services
38 .appservice
39 .thirdparty_protocols(Some(body.protocol.as_str()))
40 .await
41 .remove(&body.protocol)
42 .ok_or_else(|| err!(Request(NotFound("Unknown protocol."))))?;
43
44 Ok(get_protocol::v3::Response { protocol })
45}
46
47pub(crate) async fn get_user_for_protocol_route(
53 State(services): State<crate::State>,
54 body: Ruma<get_user_for_protocol::v3::Request>,
55) -> Result<get_user_for_protocol::v3::Response> {
56 let users = services
57 .appservice
58 .thirdparty_users(&body.protocol, &body.fields)
59 .await;
60
61 Ok(get_user_for_protocol::v3::Response { users })
62}
63
64pub(crate) async fn get_location_for_protocol_route(
70 State(services): State<crate::State>,
71 body: Ruma<get_location_for_protocol::v3::Request>,
72) -> Result<get_location_for_protocol::v3::Response> {
73 let locations = services
74 .appservice
75 .thirdparty_locations(&body.protocol, &body.fields)
76 .await;
77
78 Ok(get_location_for_protocol::v3::Response { locations })
79}
80
81pub(crate) async fn get_user_for_user_id_route(
86 _body: Ruma<get_user_for_user_id::v3::Request>,
87) -> Result<get_user_for_user_id::v3::Response> {
88 Ok(get_user_for_user_id::v3::Response { users: Vec::new() })
89}
90
91pub(crate) async fn get_location_for_room_alias_route(
96 _body: Ruma<get_location_for_room_alias::v3::Request>,
97) -> Result<get_location_for_room_alias::v3::Response> {
98 Ok(get_location_for_room_alias::v3::Response { locations: Vec::new() })
99}