mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2025-12-18 21:28:52 -05:00
knocking implementation
Signed-off-by: strawberry <strawberry@puppygock.gay> add sync bit of knocking Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
fabd3cf567
commit
5a1c41e66b
14 changed files with 978 additions and 117 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use conduwuit::{implement, is_false, Err, Result};
|
||||
use conduwuit_service::Services;
|
||||
use futures::{future::OptionFuture, join, FutureExt};
|
||||
use futures::{future::OptionFuture, join, FutureExt, StreamExt};
|
||||
use ruma::{EventId, RoomId, ServerName};
|
||||
|
||||
pub(super) struct AccessCheck<'a> {
|
||||
|
|
@ -31,6 +31,15 @@ pub(super) async fn check(&self) -> Result {
|
|||
.state_cache
|
||||
.server_in_room(self.origin, self.room_id);
|
||||
|
||||
// if any user on our homeserver is trying to knock this room, we'll need to
|
||||
// acknowledge bans or leaves
|
||||
let user_is_knocking = self
|
||||
.services
|
||||
.rooms
|
||||
.state_cache
|
||||
.room_members_knocked(self.room_id)
|
||||
.count();
|
||||
|
||||
let server_can_see: OptionFuture<_> = self
|
||||
.event_id
|
||||
.map(|event_id| {
|
||||
|
|
@ -42,14 +51,14 @@ pub(super) async fn check(&self) -> Result {
|
|||
})
|
||||
.into();
|
||||
|
||||
let (world_readable, server_in_room, server_can_see, acl_check) =
|
||||
join!(world_readable, server_in_room, server_can_see, acl_check);
|
||||
let (world_readable, server_in_room, server_can_see, acl_check, user_is_knocking) =
|
||||
join!(world_readable, server_in_room, server_can_see, acl_check, user_is_knocking);
|
||||
|
||||
if !acl_check {
|
||||
return Err!(Request(Forbidden("Server access denied.")));
|
||||
}
|
||||
|
||||
if !world_readable && !server_in_room {
|
||||
if !world_readable && !server_in_room && user_is_knocking == 0 {
|
||||
return Err!(Request(Forbidden("Server is not in room.")));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue