slightly cleanup appservice_in_room
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
0b085ea84f
commit
84191656fb
1 changed files with 29 additions and 32 deletions
|
@ -5,6 +5,7 @@ use std::{
|
||||||
|
|
||||||
use conduit::{
|
use conduit::{
|
||||||
err, is_not_empty,
|
err, is_not_empty,
|
||||||
|
result::LogErr,
|
||||||
utils::{stream::TryIgnore, ReadyExt, StreamTools},
|
utils::{stream::TryIgnore, ReadyExt, StreamTools},
|
||||||
warn, Result,
|
warn, Result,
|
||||||
};
|
};
|
||||||
|
@ -246,45 +247,41 @@ impl Service {
|
||||||
|
|
||||||
#[tracing::instrument(skip(self, room_id, appservice), level = "debug")]
|
#[tracing::instrument(skip(self, room_id, appservice), level = "debug")]
|
||||||
pub async fn appservice_in_room(&self, room_id: &RoomId, appservice: &RegistrationInfo) -> bool {
|
pub async fn appservice_in_room(&self, room_id: &RoomId, appservice: &RegistrationInfo) -> bool {
|
||||||
let maybe = self
|
if let Some(cached) = self
|
||||||
.appservice_in_room_cache
|
.appservice_in_room_cache
|
||||||
.read()
|
.read()
|
||||||
.expect("locked")
|
.expect("locked")
|
||||||
.get(room_id)
|
.get(room_id)
|
||||||
.and_then(|map| map.get(&appservice.registration.id))
|
.and_then(|map| map.get(&appservice.registration.id))
|
||||||
.copied();
|
.copied()
|
||||||
|
{
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(b) = maybe {
|
|
||||||
b
|
|
||||||
} else {
|
|
||||||
let bridge_user_id = UserId::parse_with_server_name(
|
let bridge_user_id = UserId::parse_with_server_name(
|
||||||
appservice.registration.sender_localpart.as_str(),
|
appservice.registration.sender_localpart.as_str(),
|
||||||
self.services.globals.server_name(),
|
self.services.globals.server_name(),
|
||||||
)
|
);
|
||||||
.ok();
|
|
||||||
|
|
||||||
let in_room = if let Some(id) = &bridge_user_id {
|
let Ok(bridge_user_id) = bridge_user_id.log_err() else {
|
||||||
self.is_joined(id, room_id).await
|
return false;
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let in_room = in_room
|
let in_room = self.is_joined(&bridge_user_id, room_id).await
|
||||||
|| self
|
|| self
|
||||||
.room_members(room_id)
|
.room_members(room_id)
|
||||||
.ready_any(|userid| appservice.users.is_match(userid.as_str()))
|
.ready_any(|user_id| appservice.users.is_match(user_id.as_str()))
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
self.appservice_in_room_cache
|
self.appservice_in_room_cache
|
||||||
.write()
|
.write()
|
||||||
.expect("locked")
|
.expect("locked")
|
||||||
.entry(room_id.to_owned())
|
.entry(room_id.into())
|
||||||
.or_default()
|
.or_default()
|
||||||
.insert(appservice.registration.id.clone(), in_room);
|
.insert(appservice.registration.id.clone(), in_room);
|
||||||
|
|
||||||
in_room
|
in_room
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Direct DB function to directly mark a user as joined. It is not
|
/// Direct DB function to directly mark a user as joined. It is not
|
||||||
/// recommended to use this directly. You most likely should use
|
/// recommended to use this directly. You most likely should use
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue