Add helper function for get_alias route
parent
ea20032404
commit
5ccdd3694b
|
@ -1,11 +1,14 @@
|
||||||
use super::State;
|
use super::State;
|
||||||
use crate::{server_server, ConduitResult, Database, Error, Ruma};
|
use crate::{server_server, ConduitResult, Database, Error, Ruma};
|
||||||
use ruma::api::{
|
use ruma::{
|
||||||
|
api::{
|
||||||
client::{
|
client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
r0::alias::{create_alias, delete_alias, get_alias},
|
r0::alias::{create_alias, delete_alias, get_alias},
|
||||||
},
|
},
|
||||||
federation,
|
federation,
|
||||||
|
},
|
||||||
|
RoomAliasId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "conduit_bin")]
|
#[cfg(feature = "conduit_bin")]
|
||||||
|
@ -50,12 +53,19 @@ pub async fn get_alias_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_alias::IncomingRequest>,
|
body: Ruma<get_alias::IncomingRequest>,
|
||||||
) -> ConduitResult<get_alias::Response> {
|
) -> ConduitResult<get_alias::Response> {
|
||||||
if body.room_alias.server_name() != db.globals.server_name() {
|
get_alias_helper(db, &body.room_alias).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_alias_helper(
|
||||||
|
db: State<'_, Database>,
|
||||||
|
room_alias: &RoomAliasId,
|
||||||
|
) -> ConduitResult<get_alias::Response> {
|
||||||
|
if room_alias.server_name() != db.globals.server_name() {
|
||||||
let response = server_server::send_request(
|
let response = server_server::send_request(
|
||||||
&db,
|
&db,
|
||||||
body.room_alias.server_name().to_string(),
|
room_alias.server_name().to_string(),
|
||||||
federation::query::get_room_information::v1::Request {
|
federation::query::get_room_information::v1::Request {
|
||||||
room_alias: body.room_alias.to_string(),
|
room_alias: room_alias.to_string(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -65,7 +75,7 @@ pub async fn get_alias_route(
|
||||||
|
|
||||||
let room_id = db
|
let room_id = db
|
||||||
.rooms
|
.rooms
|
||||||
.id_from_alias(&body.room_alias)?
|
.id_from_alias(&room_alias)?
|
||||||
.ok_or(Error::BadRequest(
|
.ok_or(Error::BadRequest(
|
||||||
ErrorKind::NotFound,
|
ErrorKind::NotFound,
|
||||||
"Room with alias not found.",
|
"Room with alias not found.",
|
||||||
|
|
|
@ -8,15 +8,12 @@ use ruma::{
|
||||||
api::{
|
api::{
|
||||||
client::{
|
client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
r0::{
|
r0::membership::{
|
||||||
alias,
|
|
||||||
membership::{
|
|
||||||
ban_user, forget_room, get_member_events, invite_user, join_room_by_id,
|
ban_user, forget_room, get_member_events, invite_user, join_room_by_id,
|
||||||
join_room_by_id_or_alias, joined_members, joined_rooms, kick_user, leave_room,
|
join_room_by_id_or_alias, joined_members, joined_rooms, kick_user, leave_room,
|
||||||
unban_user, IncomingThirdPartySigned,
|
unban_user, IncomingThirdPartySigned,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
federation,
|
federation,
|
||||||
},
|
},
|
||||||
events::{room::member, EventType},
|
events::{room::member, EventType},
|
||||||
|
@ -58,21 +55,7 @@ pub async fn join_room_by_id_or_alias_route(
|
||||||
let room_id = match RoomId::try_from(body.room_id_or_alias.clone()) {
|
let room_id = match RoomId::try_from(body.room_id_or_alias.clone()) {
|
||||||
Ok(room_id) => room_id,
|
Ok(room_id) => room_id,
|
||||||
Err(room_alias) => {
|
Err(room_alias) => {
|
||||||
client_server::get_alias_route(
|
client_server::get_alias_helper(db, &room_alias)
|
||||||
db,
|
|
||||||
Ruma {
|
|
||||||
body: alias::get_alias::IncomingRequest::try_from(http::Request::new(
|
|
||||||
serde_json::json!({ "room_alias": room_alias, })
|
|
||||||
.to_string()
|
|
||||||
.as_bytes()
|
|
||||||
.to_vec(),
|
|
||||||
))
|
|
||||||
.unwrap(),
|
|
||||||
sender_id: body.sender_id.clone(),
|
|
||||||
device_id: body.device_id.clone(),
|
|
||||||
json_body: None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await?
|
.await?
|
||||||
.0
|
.0
|
||||||
.room_id
|
.room_id
|
||||||
|
@ -495,7 +478,7 @@ async fn join_room_by_id_helper(
|
||||||
room_id: room_id.clone(),
|
room_id: room_id.clone(),
|
||||||
event_id,
|
event_id,
|
||||||
pdu_stub: serde_json::from_value(join_event_stub_value)
|
pdu_stub: serde_json::from_value(join_event_stub_value)
|
||||||
.expect("Raw::from_value always works"),
|
.expect("we just created this event"),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
Loading…
Reference in New Issue