mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-13 04:06:54 +00:00
feat: Add stable mutual rooms endpoint
This commit is contained in:
1 parent
4a40290514
commit
4e001abe92
5 files changed
+47
-17
No files matched your search
@@ -1,7 +1,7 @@
|
||||
use axum::extract::State;
|
||||
use conduwuit::{Err, Result};
|
||||
use futures::StreamExt;
|
||||
use ruma::api::client::membership::mutual_rooms;
|
||||
use ruma::{OwnedRoomId, api::client::membership::mutual_rooms};
|
||||
|
||||
use crate::Ruma;
|
||||
|
||||
@@ -11,14 +11,14 @@ use crate::Ruma;
|
||||
///
|
||||
/// An implementation of [MSC2666](https://github.com/matrix-org/matrix-spec-proposals/pull/2666)
|
||||
#[tracing::instrument(skip_all, name = "mutual_rooms", level = "info")]
|
||||
pub(crate) async fn get_mutual_rooms_route(
|
||||
pub(crate) async fn get_mutual_rooms_unstable_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<mutual_rooms::unstable::Request>,
|
||||
) -> Result<mutual_rooms::unstable::Response> {
|
||||
let sender_user = body.identity.expect_sender_user()?;
|
||||
|
||||
if sender_user == body.user_id {
|
||||
return Err!(Request(Unknown("You cannot request rooms in common with yourself.")));
|
||||
return Err!(Request(InvalidParam("You cannot request rooms in common with yourself.")));
|
||||
}
|
||||
|
||||
let mutual_rooms = services
|
||||
@@ -30,3 +30,33 @@ pub(crate) async fn get_mutual_rooms_route(
|
||||
|
||||
Ok(mutual_rooms::unstable::Response::new(mutual_rooms))
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/client/v1/mutual_rooms`
|
||||
///
|
||||
/// Gets all the rooms the sender shares with the specified user.
|
||||
#[tracing::instrument(skip_all, name = "mutual_rooms", level = "info")]
|
||||
pub(crate) async fn get_mutual_rooms_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<mutual_rooms::v1::Request>,
|
||||
) -> Result<mutual_rooms::v1::Response> {
|
||||
let sender_user = body.identity.expect_sender_user()?;
|
||||
|
||||
if sender_user == body.user_id {
|
||||
return Err!(Request(InvalidParam("You cannot request rooms in common with yourself.")));
|
||||
}
|
||||
|
||||
let mutual_rooms: Vec<OwnedRoomId> = services
|
||||
.rooms
|
||||
.state_cache
|
||||
.get_shared_rooms(sender_user, &body.user_id)
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
Ok(mutual_rooms::v1::Response::new(
|
||||
mutual_rooms
|
||||
.len()
|
||||
.try_into()
|
||||
.expect("user should be in fewer than 9.1 quadrillion rooms"),
|
||||
mutual_rooms,
|
||||
))
|
||||
}
|
||||
@@ -177,6 +177,7 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
|
||||
.ruma_route(&client::get_relating_events_with_rel_type_route)
|
||||
.ruma_route(&client::get_relating_events_route)
|
||||
.ruma_route(&client::get_hierarchy_route)
|
||||
.ruma_route(&client::get_mutual_rooms_unstable_route)
|
||||
.ruma_route(&client::get_mutual_rooms_route)
|
||||
.ruma_route(&client::get_room_summary)
|
||||
.ruma_route(&client::get_suspended_status)
|
||||
|
||||
Reference in new issue
Block a user