add: user follow requests
add: nsfw questions fix: inherit nsfw status from questions fix: inherit community from questions
This commit is contained in:
parent
d6c7372610
commit
ad17acec98
24 changed files with 492 additions and 59 deletions
|
@ -1,5 +1,7 @@
|
|||
use super::*;
|
||||
use crate::cache::Cache;
|
||||
use crate::model::auth::FollowResult;
|
||||
use crate::model::requests::{ActionRequest, ActionType};
|
||||
use crate::model::{Error, Result, auth::User, auth::UserFollow, permissions::FinePermission};
|
||||
use crate::{auto_method, execute, get, query_row, query_rows, params};
|
||||
|
||||
|
@ -219,7 +221,26 @@ impl DataManager {
|
|||
///
|
||||
/// # Arguments
|
||||
/// * `data` - a mock [`UserFollow`] object to insert
|
||||
pub async fn create_userfollow(&self, data: UserFollow) -> Result<()> {
|
||||
/// * `force` - if we should skip the request stage
|
||||
pub async fn create_userfollow(&self, data: UserFollow, force: bool) -> Result<FollowResult> {
|
||||
if !force {
|
||||
let other_user = self.get_user_by_id(data.receiver).await?;
|
||||
|
||||
if other_user.settings.private_profile {
|
||||
// send follow request instead
|
||||
self.create_request(ActionRequest::with_id(
|
||||
data.initiator,
|
||||
data.receiver,
|
||||
ActionType::Follow,
|
||||
data.receiver,
|
||||
))
|
||||
.await?;
|
||||
|
||||
return Ok(FollowResult::Requested);
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
|
@ -248,13 +269,16 @@ impl DataManager {
|
|||
self.incr_user_follower_count(data.receiver).await.unwrap();
|
||||
|
||||
// return
|
||||
Ok(())
|
||||
Ok(FollowResult::Followed)
|
||||
}
|
||||
|
||||
pub async fn delete_userfollow(&self, id: usize, user: &User) -> Result<()> {
|
||||
let follow = self.get_userfollow_by_id(id).await?;
|
||||
|
||||
if (user.id != follow.initiator) && (user.id != follow.receiver) && !user.permissions.check(FinePermission::MANAGE_FOLLOWS) {
|
||||
if (user.id != follow.initiator)
|
||||
&& (user.id != follow.receiver)
|
||||
&& !user.permissions.check(FinePermission::MANAGE_FOLLOWS)
|
||||
{
|
||||
return Err(Error::NotAllowed);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue