mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2025-12-14 19:28:57 -05:00
merge and resplit/cleanup appservice service
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
efb28c1a99
commit
9438dc89e6
5 changed files with 157 additions and 181 deletions
39
src/service/appservice/registration_info.rs
Normal file
39
src/service/appservice/registration_info.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use conduit::Result;
|
||||
use ruma::{api::appservice::Registration, UserId};
|
||||
|
||||
use super::NamespaceRegex;
|
||||
|
||||
/// Appservice registration combined with its compiled regular expressions.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RegistrationInfo {
|
||||
pub registration: Registration,
|
||||
pub users: NamespaceRegex,
|
||||
pub aliases: NamespaceRegex,
|
||||
pub rooms: NamespaceRegex,
|
||||
}
|
||||
|
||||
impl RegistrationInfo {
|
||||
#[must_use]
|
||||
pub fn is_user_match(&self, user_id: &UserId) -> bool {
|
||||
self.users.is_match(user_id.as_str()) || self.registration.sender_localpart == user_id.localpart()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn is_exclusive_user_match(&self, user_id: &UserId) -> bool {
|
||||
self.users.is_exclusive_match(user_id.as_str()) || self.registration.sender_localpart == user_id.localpart()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Registration> for RegistrationInfo {
|
||||
type Error = regex::Error;
|
||||
|
||||
fn try_from(value: Registration) -> Result<Self, regex::Error> {
|
||||
Ok(Self {
|
||||
users: value.namespaces.users.clone().try_into()?,
|
||||
aliases: value.namespaces.aliases.clone().try_into()?,
|
||||
rooms: value.namespaces.rooms.clone().try_into()?,
|
||||
registration: value,
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue