feat: Chat request implementation #14
1 changed files with 32 additions and 40 deletions
|
@ -103,17 +103,15 @@ impl UsersStatusExt for DatabaseConnection {
|
||||||
whitelister: &UserModel,
|
whitelister: &UserModel,
|
||||||
target_public_key: &PublicKey,
|
target_public_key: &PublicKey,
|
||||||
) -> ServerResult<bool> {
|
) -> ServerResult<bool> {
|
||||||
whitelister
|
get_user_status(
|
||||||
awiteb marked this conversation as resolved
|
|||||||
.find_related(UsersStatusEntity)
|
self,
|
||||||
.filter(
|
whitelister,
|
||||||
UsersStatusColumn::Target
|
target_public_key,
|
||||||
.eq(target_public_key.to_string())
|
AccessStatus::Whitelisted,
|
||||||
.and(UsersStatusColumn::Status.eq(AccessStatus::Whitelisted)),
|
)
|
||||||
)
|
.await
|
||||||
.one(self)
|
.map(|u| u.is_some())
|
||||||
.await
|
.map_err(Into::into)
|
||||||
.map(|u| u.is_some())
|
|
||||||
.map_err(Into::into)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn is_blacklisted(
|
async fn is_blacklisted(
|
||||||
|
@ -121,17 +119,15 @@ impl UsersStatusExt for DatabaseConnection {
|
||||||
blacklister: &UserModel,
|
blacklister: &UserModel,
|
||||||
target_public_key: &PublicKey,
|
target_public_key: &PublicKey,
|
||||||
) -> ServerResult<bool> {
|
) -> ServerResult<bool> {
|
||||||
blacklister
|
get_user_status(
|
||||||
.find_related(UsersStatusEntity)
|
self,
|
||||||
.filter(
|
blacklister,
|
||||||
UsersStatusColumn::Target
|
target_public_key,
|
||||||
.eq(target_public_key.to_string())
|
AccessStatus::Blacklisted,
|
||||||
.and(UsersStatusColumn::Status.eq(AccessStatus::Blacklisted)),
|
)
|
||||||
)
|
.await
|
||||||
.one(self)
|
.map(|u| u.is_some())
|
||||||
.await
|
.map_err(Into::into)
|
||||||
.map(|u| u.is_some())
|
|
||||||
.map_err(Into::into)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn add_to_whitelist(
|
async fn add_to_whitelist(
|
||||||
|
@ -223,15 +219,13 @@ impl UsersStatusExt for DatabaseConnection {
|
||||||
whitelister: &UserModel,
|
whitelister: &UserModel,
|
||||||
target_public_key: &PublicKey,
|
target_public_key: &PublicKey,
|
||||||
) -> ServerResult<()> {
|
) -> ServerResult<()> {
|
||||||
if let Some(target_user) = whitelister
|
if let Some(target_user) = get_user_status(
|
||||||
.find_related(UsersStatusEntity)
|
self,
|
||||||
.filter(
|
whitelister,
|
||||||
UsersStatusColumn::Target
|
target_public_key,
|
||||||
.eq(target_public_key.to_string())
|
AccessStatus::Whitelisted,
|
||||||
.and(UsersStatusColumn::Status.eq(AccessStatus::Whitelisted)),
|
)
|
||||||
)
|
.await?
|
||||||
.one(self)
|
|
||||||
.await?
|
|
||||||
{
|
{
|
||||||
target_user.delete(self).await?;
|
target_user.delete(self).await?;
|
||||||
}
|
}
|
||||||
|
@ -243,15 +237,13 @@ impl UsersStatusExt for DatabaseConnection {
|
||||||
blacklister: &UserModel,
|
blacklister: &UserModel,
|
||||||
target_public_key: &PublicKey,
|
target_public_key: &PublicKey,
|
||||||
) -> ServerResult<()> {
|
) -> ServerResult<()> {
|
||||||
if let Some(target_user) = blacklister
|
if let Some(target_user) = get_user_status(
|
||||||
.find_related(UsersStatusEntity)
|
self,
|
||||||
.filter(
|
blacklister,
|
||||||
UsersStatusColumn::Target
|
target_public_key,
|
||||||
.eq(target_public_key.to_string())
|
AccessStatus::Blacklisted,
|
||||||
.and(UsersStatusColumn::Status.eq(AccessStatus::Blacklisted)),
|
)
|
||||||
)
|
.await?
|
||||||
.one(self)
|
|
||||||
.await?
|
|
||||||
{
|
{
|
||||||
target_user.delete(self).await?;
|
target_user.delete(self).await?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue
you can use
get_user_status
here and alsois_blacklisted
. also inremove...
functions