remove unnecessary loops/allocations in client /capabilities
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
14b9511d2e
commit
5dbb868936
1 changed files with 19 additions and 10 deletions
|
@ -1,8 +1,11 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use axum::extract::State;
|
||||
use ruma::api::client::discovery::get_capabilities::{
|
||||
use ruma::{
|
||||
api::client::discovery::get_capabilities::{
|
||||
self, Capabilities, RoomVersionStability, RoomVersionsCapability, ThirdPartyIdChangesCapability,
|
||||
},
|
||||
RoomVersionId,
|
||||
};
|
||||
|
||||
use crate::{Result, Ruma};
|
||||
|
@ -14,13 +17,19 @@ use crate::{Result, Ruma};
|
|||
pub(crate) async fn get_capabilities_route(
|
||||
State(services): State<crate::State>, _body: Ruma<get_capabilities::v3::Request>,
|
||||
) -> Result<get_capabilities::v3::Response> {
|
||||
let mut available = BTreeMap::new();
|
||||
for room_version in &services.globals.unstable_room_versions {
|
||||
available.insert(room_version.clone(), RoomVersionStability::Unstable);
|
||||
}
|
||||
for room_version in &services.globals.stable_room_versions {
|
||||
available.insert(room_version.clone(), RoomVersionStability::Stable);
|
||||
}
|
||||
let available: BTreeMap<RoomVersionId, RoomVersionStability> = services
|
||||
.globals
|
||||
.unstable_room_versions
|
||||
.iter()
|
||||
.map(|unstable_room_version| (unstable_room_version.clone(), RoomVersionStability::Unstable))
|
||||
.chain(
|
||||
services
|
||||
.globals
|
||||
.stable_room_versions
|
||||
.iter()
|
||||
.map(|stable_room_version| (stable_room_version.clone(), RoomVersionStability::Stable)),
|
||||
)
|
||||
.collect();
|
||||
|
||||
let mut capabilities = Capabilities::default();
|
||||
capabilities.room_versions = RoomVersionsCapability {
|
||||
|
@ -28,7 +37,7 @@ pub(crate) async fn get_capabilities_route(
|
|||
available,
|
||||
};
|
||||
|
||||
// conduit does not implement 3PID stuff
|
||||
// we do not implement 3PID stuff
|
||||
capabilities.thirdparty_id_changes = ThirdPartyIdChangesCapability {
|
||||
enabled: false,
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue