Skip to content
Snippets Groups Projects
Commit 40596634 authored by 🥺's avatar 🥺 :transgender_flag: Committed by 🥺
Browse files

respond with actual servers for `/_matrix/federation/v1/query/directory`...

respond with actual servers for `/_matrix/federation/v1/query/directory` requests instead of just us

aka be spec compliant

Signed-off-by: default avatarstrawberry <strawberry@puppygock.gay>
parent 973fed15
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
use axum::{response::IntoResponse, Json};
use get_profile_information::v1::ProfileField;
use rand::seq::SliceRandom;
use ruma::{
api::{
client::error::ErrorKind,
......@@ -1423,9 +1424,30 @@ pub async fn get_room_information_route(
.resolve_local_alias(&body.room_alias)?
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Room alias not found."))?;
let mut servers: Vec<OwnedServerName> = services()
.rooms
.state_cache
.room_servers(&room_id)
.filter_map(Result::ok)
.collect::<Vec<_>>();
servers.sort_unstable();
servers.dedup();
servers.shuffle(&mut rand::thread_rng());
// insert our server as the very first choice if in list
if let Some(server_index) = servers
.iter()
.position(|server| server == services().globals.server_name())
{
servers.remove(server_index);
servers.insert(0, services().globals.server_name().to_owned());
}
Ok(get_room_information::v1::Response {
room_id,
servers: vec![services().globals.server_name().to_owned()], // TODO: add more than just us
servers,
})
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment