de-global server_is_ours / user_is_local
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
010e4ee35a
commit
59efabbbc2
34 changed files with 179 additions and 169 deletions
|
@ -14,7 +14,7 @@ use ruma::{
|
|||
};
|
||||
|
||||
use self::data::Data;
|
||||
use crate::{admin, appservice, appservice::RegistrationInfo, globals, rooms, sending, server_is_ours, Dep};
|
||||
use crate::{admin, appservice, appservice::RegistrationInfo, globals, rooms, sending, Dep};
|
||||
|
||||
pub struct Service {
|
||||
db: Data,
|
||||
|
@ -85,7 +85,10 @@ impl Service {
|
|||
pub async fn resolve_alias(
|
||||
&self, room_alias: &RoomAliasId, servers: Option<&Vec<OwnedServerName>>,
|
||||
) -> Result<(OwnedRoomId, Option<Vec<OwnedServerName>>)> {
|
||||
if !server_is_ours(room_alias.server_name())
|
||||
if !self
|
||||
.services
|
||||
.globals
|
||||
.server_is_ours(room_alias.server_name())
|
||||
&& (!servers
|
||||
.as_ref()
|
||||
.is_some_and(|servers| servers.contains(&self.services.globals.server_name().to_owned()))
|
||||
|
@ -195,7 +198,11 @@ impl Service {
|
|||
pub async fn appservice_checks(
|
||||
&self, room_alias: &RoomAliasId, appservice_info: &Option<RegistrationInfo>,
|
||||
) -> Result<()> {
|
||||
if !server_is_ours(room_alias.server_name()) {
|
||||
if !self
|
||||
.services
|
||||
.globals
|
||||
.server_is_ours(room_alias.server_name())
|
||||
{
|
||||
return Err(Error::BadRequest(ErrorKind::InvalidParam, "Alias is from another server."));
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use ruma::{
|
|||
OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
|
||||
};
|
||||
|
||||
use crate::{appservice::RegistrationInfo, globals, user_is_local, users, Dep};
|
||||
use crate::{appservice::RegistrationInfo, globals, users, Dep};
|
||||
|
||||
type StrippedStateEventIter<'a> = Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a>;
|
||||
type AnySyncStateEventIter<'a> = Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnySyncStateEvent>>)>> + 'a>;
|
||||
|
@ -355,7 +355,7 @@ impl Data {
|
|||
Box::new(
|
||||
self.room_members(room_id)
|
||||
.filter_map(Result::ok)
|
||||
.filter(|user| user_is_local(user)),
|
||||
.filter(|user| self.services.globals.user_is_local(user)),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ use ruma::{
|
|||
OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
|
||||
};
|
||||
|
||||
use crate::{account_data, appservice::RegistrationInfo, rooms, user_is_local, users, Dep};
|
||||
use crate::{account_data, appservice::RegistrationInfo, globals, rooms, users, Dep};
|
||||
|
||||
pub struct Service {
|
||||
services: Services,
|
||||
|
@ -30,6 +30,7 @@ pub struct Service {
|
|||
|
||||
struct Services {
|
||||
account_data: Dep<account_data::Service>,
|
||||
globals: Dep<globals::Service>,
|
||||
state_accessor: Dep<rooms::state_accessor::Service>,
|
||||
users: Dep<users::Service>,
|
||||
}
|
||||
|
@ -39,6 +40,7 @@ impl crate::Service for Service {
|
|||
Ok(Arc::new(Self {
|
||||
services: Services {
|
||||
account_data: args.depend::<account_data::Service>("account_data"),
|
||||
globals: args.depend::<globals::Service>("globals"),
|
||||
state_accessor: args.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
|
||||
users: args.depend::<users::Service>("users"),
|
||||
},
|
||||
|
@ -65,7 +67,7 @@ impl Service {
|
|||
// TODO: use futures to update remote profiles without blocking the membership
|
||||
// update
|
||||
#[allow(clippy::collapsible_if)]
|
||||
if !user_is_local(user_id) {
|
||||
if !self.services.globals.user_is_local(user_id) {
|
||||
if !self.services.users.exists(user_id)? {
|
||||
self.services.users.create(user_id, None)?;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ use tokio::sync::RwLock;
|
|||
use self::data::Data;
|
||||
use crate::{
|
||||
account_data, admin, appservice, appservice::NamespaceRegex, globals, pusher, rooms,
|
||||
rooms::state_compressor::CompressedStateEvent, sending, server_is_ours, Dep,
|
||||
rooms::state_compressor::CompressedStateEvent, sending, Dep,
|
||||
};
|
||||
|
||||
// Update Relationships
|
||||
|
@ -846,7 +846,7 @@ impl Service {
|
|||
.state_cache
|
||||
.room_members(room_id)
|
||||
.filter_map(Result::ok)
|
||||
.filter(|m| server_is_ours(m.server_name()) && m != target)
|
||||
.filter(|m| self.services.globals.server_is_ours(m.server_name()) && m != target)
|
||||
.count();
|
||||
if count < 2 {
|
||||
warn!("Last admin cannot leave from admins room");
|
||||
|
@ -871,7 +871,7 @@ impl Service {
|
|||
.state_cache
|
||||
.room_members(room_id)
|
||||
.filter_map(Result::ok)
|
||||
.filter(|m| server_is_ours(m.server_name()) && m != target)
|
||||
.filter(|m| self.services.globals.server_is_ours(m.server_name()) && m != target)
|
||||
.count();
|
||||
if count < 2 {
|
||||
warn!("Last admin cannot be banned in admins room");
|
||||
|
@ -1092,7 +1092,7 @@ impl Service {
|
|||
.unwrap_or_default();
|
||||
|
||||
let room_mods = power_levels.users.iter().filter_map(|(user_id, level)| {
|
||||
if level > &power_levels.users_default && !server_is_ours(user_id.server_name()) {
|
||||
if level > &power_levels.users_default && !self.services.globals.user_is_local(user_id) {
|
||||
Some(user_id.server_name().to_owned())
|
||||
} else {
|
||||
None
|
||||
|
@ -1106,7 +1106,7 @@ impl Service {
|
|||
.filter_map(|alias| {
|
||||
alias
|
||||
.ok()
|
||||
.filter(|alias| !server_is_ours(alias.server_name()))
|
||||
.filter(|alias| !self.services.globals.server_is_ours(alias.server_name()))
|
||||
.map(|alias| alias.server_name().to_owned())
|
||||
});
|
||||
|
||||
|
@ -1114,7 +1114,7 @@ impl Service {
|
|||
.chain(room_alias_servers)
|
||||
.chain(self.services.server.config.trusted_servers.clone())
|
||||
.filter(|server_name| {
|
||||
if server_is_ours(server_name) {
|
||||
if self.services.globals.server_is_ours(server_name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use ruma::{
|
|||
};
|
||||
use tokio::sync::{broadcast, RwLock};
|
||||
|
||||
use crate::{globals, sending, user_is_local, Dep};
|
||||
use crate::{globals, sending, Dep};
|
||||
|
||||
pub struct Service {
|
||||
server: Arc<Server>,
|
||||
|
@ -63,7 +63,7 @@ impl Service {
|
|||
}
|
||||
|
||||
// update federation
|
||||
if user_is_local(user_id) {
|
||||
if self.services.globals.user_is_local(user_id) {
|
||||
self.federation_send(room_id, user_id, true)?;
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ impl Service {
|
|||
}
|
||||
|
||||
// update federation
|
||||
if user_is_local(user_id) {
|
||||
if self.services.globals.user_is_local(user_id) {
|
||||
self.federation_send(room_id, user_id, false)?;
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ impl Service {
|
|||
|
||||
// update federation
|
||||
for user in removable {
|
||||
if user_is_local(&user) {
|
||||
if self.services.globals.user_is_local(&user) {
|
||||
self.federation_send(room_id, &user, false)?;
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +184,11 @@ impl Service {
|
|||
}
|
||||
|
||||
fn federation_send(&self, room_id: &RoomId, user_id: &UserId, typing: bool) -> Result<()> {
|
||||
debug_assert!(user_is_local(user_id), "tried to broadcast typing status of remote user",);
|
||||
debug_assert!(
|
||||
self.services.globals.user_is_local(user_id),
|
||||
"tried to broadcast typing status of remote user",
|
||||
);
|
||||
|
||||
if !self.server.config.allow_outgoing_typing {
|
||||
return Ok(());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue