let community_follower_form = CommunityFollowerForm {
community_id: inserted_community.id,
user_id: user.id,
+ pending: false,
};
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
let community_follower_form = CommunityFollowerForm {
community_id: data.community_id,
user_id: user.id,
+ pending: false,
};
if community.local {
let community_follower_form = CommunityFollowerForm {
community_id: main_community.id,
user_id: inserted_user.id,
+ pending: false,
};
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
base::{AnyBase, BaseExt, ExtendsExt},
object::ObjectExt,
};
-use lemmy_db::{community::Community, user::User_, DbPool};
+use lemmy_db::{
+ community::{Community, CommunityFollower, CommunityFollowerForm},
+ user::User_,
+ DbPool,
+ Followable,
+};
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
})
.await??;
+ let community_follower_form = CommunityFollowerForm {
+ community_id: community.id,
+ user_id: self.id,
+ pending: true,
+ };
+ blocking(&context.pool(), move |conn| {
+ CommunityFollower::follow(conn, &community_follower_form).ok()
+ })
+ .await?;
+
let mut follow = Follow::new(self.actor_id.to_owned(), community.actor_id()?);
follow
.set_context(activitystreams::context())
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
user_id: user.id,
+ pending: false,
};
// This will fail if they're already a follower, but ignore the error.
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
user_id: user.id,
+ pending: false,
};
// This will fail if they aren't a follower, but ignore the error.
use anyhow::{anyhow, Context};
use diesel::NotFound;
use lemmy_db::{
- community::{Community, CommunityFollower, CommunityFollowerForm},
+ community::{Community, CommunityFollower},
private_message::PrivateMessage,
user::User_,
Followable,
let accept = Accept::from_any_base(activity)?.context(location_info!())?;
verify_activity_domains_valid(&accept, &actor.actor_id()?, false)?;
- // TODO: we should check that we actually sent this activity, because the remote instance
- // could just put a fake Follow
let object = accept.object().to_owned().one().context(location_info!())?;
let follow = Follow::from_any_base(object)?.context(location_info!())?;
verify_activity_domains_valid(&follow, &user.actor_id()?, false)?;
let community =
get_or_fetch_and_upsert_community(&community_uri, context, request_counter).await?;
- // Now you need to add this to the community follower
- let community_follower_form = CommunityFollowerForm {
- community_id: community.id,
- user_id: user.id,
- };
-
- // This will fail if they're already a follower
+ let community_id = community.id;
+ let user_id = user.id;
+ // This will throw an error if no follow was requested
blocking(&context.pool(), move |conn| {
- CommunityFollower::follow(conn, &community_follower_form).ok()
+ CommunityFollower::follow_accepted(conn, community_id, user_id)
})
- .await?;
+ .await??;
Ok(())
}
pub id: i32,
pub community_id: i32,
pub user_id: i32,
+ pub pending: bool,
pub published: chrono::NaiveDateTime,
}
pub struct CommunityFollowerForm {
pub community_id: i32,
pub user_id: i32,
+ pub pending: bool,
}
impl Followable<CommunityFollowerForm> for CommunityFollower {
.values(community_follower_form)
.get_result::<Self>(conn)
}
+ fn follow_accepted(conn: &PgConnection, community_id_: i32, user_id_: i32) -> Result<Self, Error>
+ where
+ Self: Sized,
+ {
+ use crate::schema::community_follower::dsl::*;
+ diesel::update(
+ community_follower
+ .filter(community_id.eq(community_id_))
+ .filter(user_id.eq(user_id_)),
+ )
+ .set(pending.eq(true))
+ .get_result::<Self>(conn)
+ }
fn unfollow(
conn: &PgConnection,
community_follower_form: &CommunityFollowerForm,
pub trait Followable<T> {
fn follow(conn: &PgConnection, form: &T) -> Result<Self, Error>
+ where
+ Self: Sized;
+ fn follow_accepted(conn: &PgConnection, community_id: i32, user_id: i32) -> Result<Self, Error>
where
Self: Sized;
fn unfollow(conn: &PgConnection, form: &T) -> Result<usize, Error>
id -> Int4,
community_id -> Int4,
user_id -> Int4,
+ pending -> Bool,
published -> Timestamp,
}
}
--- /dev/null
+ALTER TABLE community_follower DROP COLUMN pending;
\ No newline at end of file
--- /dev/null
+ALTER TABLE community_follower ADD COLUMN pending BOOLEAN DEFAULT FALSE;
\ No newline at end of file