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_api_structs::blocking;
17 use lemmy_db_queries::{ApubObject, DbPool, Followable};
18 use lemmy_db_schema::source::{
19 community::{Community, CommunityFollower, CommunityFollowerForm},
22 use lemmy_utils::LemmyError;
23 use lemmy_websocket::LemmyContext;
26 #[async_trait::async_trait(?Send)]
27 impl ActorType for User_ {
28 fn is_local(&self) -> bool {
31 fn actor_id(&self) -> Url {
32 self.actor_id.to_owned().into_inner()
35 fn public_key(&self) -> Option<String> {
36 self.public_key.to_owned()
39 fn private_key(&self) -> Option<String> {
40 self.private_key.to_owned()
43 fn get_shared_inbox_or_inbox_url(&self) -> Url {
47 .unwrap_or_else(|| self.inbox_url.to_owned())
51 /// As a given local user, send out a follow request to a remote community.
54 follow_actor_id: &Url,
55 context: &LemmyContext,
56 ) -> Result<(), LemmyError> {
57 let follow_actor_id = follow_actor_id.to_owned();
58 let community = blocking(context.pool(), move |conn| {
59 Community::read_from_apub_id(conn, &follow_actor_id.into())
63 let community_follower_form = CommunityFollowerForm {
64 community_id: community.id,
68 blocking(&context.pool(), move |conn| {
69 CommunityFollower::follow(conn, &community_follower_form).ok()
73 let mut follow = Follow::new(self.actor_id.to_owned().into_inner(), community.actor_id());
75 .set_many_contexts(lemmy_context()?)
76 .set_id(generate_activity_id(FollowType::Follow)?)
77 .set_to(community.actor_id());
79 send_activity_single_dest(follow, self, community.inbox_url.into(), context).await?;
83 async fn send_unfollow(
85 follow_actor_id: &Url,
86 context: &LemmyContext,
87 ) -> Result<(), LemmyError> {
88 let follow_actor_id = follow_actor_id.to_owned();
89 let community = blocking(context.pool(), move |conn| {
90 Community::read_from_apub_id(conn, &follow_actor_id.into())
94 let mut follow = Follow::new(self.actor_id.to_owned().into_inner(), community.actor_id());
96 .set_many_contexts(lemmy_context()?)
97 .set_id(generate_activity_id(FollowType::Follow)?)
98 .set_to(community.actor_id());
100 // Undo that fake activity
101 let mut undo = Undo::new(
102 self.actor_id.to_owned().into_inner(),
103 follow.into_any_base()?,
106 .set_many_contexts(lemmy_context()?)
107 .set_id(generate_activity_id(UndoType::Undo)?)
108 .set_to(community.actor_id());
110 send_activity_single_dest(undo, self, community.inbox_url.into(), context).await?;
114 async fn send_accept_follow(
117 _context: &LemmyContext,
118 ) -> Result<(), LemmyError> {
122 async fn send_delete(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
126 async fn send_undo_delete(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
130 async fn send_remove(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
134 async fn send_undo_remove(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
138 async fn send_announce(
141 _context: &LemmyContext,
142 ) -> Result<(), LemmyError> {
146 async fn get_follower_inboxes(&self, _pool: &DbPool) -> Result<Vec<Url>, LemmyError> {