2 activities::send::generate_activity_id,
3 activity_queue::send_activity_single_dest,
4 extensions::context::lemmy_context,
9 kind::{FollowType, UndoType},
13 base::{AnyBase, BaseExt, ExtendsExt},
16 use lemmy_db_queries::{ApubObject, DbPool, Followable};
17 use lemmy_db_schema::source::{
18 community::{Community, CommunityFollower, CommunityFollowerForm},
21 use lemmy_structs::blocking;
22 use lemmy_utils::LemmyError;
23 use lemmy_websocket::LemmyContext;
26 #[async_trait::async_trait(?Send)]
27 impl ActorType for User_ {
28 fn actor_id(&self) -> Url {
29 self.actor_id.to_owned().into_inner()
32 fn public_key(&self) -> Option<String> {
33 self.public_key.to_owned()
36 fn private_key(&self) -> Option<String> {
37 self.private_key.to_owned()
40 /// As a given local user, send out a follow request to a remote community.
43 follow_actor_id: &Url,
44 context: &LemmyContext,
45 ) -> Result<(), LemmyError> {
46 let follow_actor_id = follow_actor_id.to_owned();
47 let community = blocking(context.pool(), move |conn| {
48 Community::read_from_apub_id(conn, &follow_actor_id.into())
52 let community_follower_form = CommunityFollowerForm {
53 community_id: community.id,
57 blocking(&context.pool(), move |conn| {
58 CommunityFollower::follow(conn, &community_follower_form).ok()
62 let mut follow = Follow::new(self.actor_id.to_owned().into_inner(), community.actor_id());
64 .set_many_contexts(lemmy_context()?)
65 .set_id(generate_activity_id(FollowType::Follow)?)
66 .set_to(community.actor_id());
68 send_activity_single_dest(follow, self, community.get_inbox_url()?, context).await?;
72 async fn send_unfollow(
74 follow_actor_id: &Url,
75 context: &LemmyContext,
76 ) -> Result<(), LemmyError> {
77 let follow_actor_id = follow_actor_id.to_owned();
78 let community = blocking(context.pool(), move |conn| {
79 Community::read_from_apub_id(conn, &follow_actor_id.into())
83 let mut follow = Follow::new(self.actor_id.to_owned().into_inner(), community.actor_id());
85 .set_many_contexts(lemmy_context()?)
86 .set_id(generate_activity_id(FollowType::Follow)?)
87 .set_to(community.actor_id());
89 // Undo that fake activity
90 let mut undo = Undo::new(
91 self.actor_id.to_owned().into_inner(),
92 follow.into_any_base()?,
95 .set_many_contexts(lemmy_context()?)
96 .set_id(generate_activity_id(UndoType::Undo)?)
97 .set_to(community.actor_id());
99 send_activity_single_dest(undo, self, community.get_inbox_url()?, context).await?;
103 async fn send_accept_follow(
106 _context: &LemmyContext,
107 ) -> Result<(), LemmyError> {
111 async fn send_delete(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
115 async fn send_undo_delete(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
119 async fn send_remove(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
123 async fn send_undo_remove(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
127 async fn send_announce(
130 _context: &LemmyContext,
131 ) -> Result<(), LemmyError> {
135 async fn get_follower_inboxes(&self, _pool: &DbPool) -> Result<Vec<Url>, LemmyError> {