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_str(&self) -> String {
29 self.actor_id.to_owned()
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_string();
47 let community = blocking(context.pool(), move |conn| {
48 Community::read_from_apub_id(conn, &follow_actor_id)
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(), 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_string();
78 let community = blocking(context.pool(), move |conn| {
79 Community::read_from_apub_id(conn, &follow_actor_id)
83 let mut follow = Follow::new(self.actor_id.to_owned(), 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(Url::parse(&self.actor_id)?, follow.into_any_base()?);
92 .set_many_contexts(lemmy_context()?)
93 .set_id(generate_activity_id(UndoType::Undo)?)
94 .set_to(community.actor_id()?);
96 send_activity_single_dest(undo, self, community.get_inbox_url()?, context).await?;
100 async fn send_accept_follow(
103 _context: &LemmyContext,
104 ) -> Result<(), LemmyError> {
108 async fn send_delete(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
112 async fn send_undo_delete(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
116 async fn send_remove(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
120 async fn send_undo_remove(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
124 async fn send_announce(
127 _context: &LemmyContext,
128 ) -> Result<(), LemmyError> {
132 async fn get_follower_inboxes(&self, _pool: &DbPool) -> Result<Vec<Url>, LemmyError> {