From 7f2b4c95543cee11605b90b503d35aba895801c9 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 12 Aug 2020 14:15:07 +0200 Subject: [PATCH] Fix some TODOs in activitypub code --- server/src/apub/comment.rs | 26 +++++++++++++------------- server/src/apub/community.rs | 21 +++++++++------------ server/src/apub/fetcher.rs | 18 ------------------ server/src/apub/mod.rs | 4 ++-- server/src/apub/post.rs | 24 ++++++++++++------------ server/src/apub/user.rs | 2 +- 6 files changed, 37 insertions(+), 58 deletions(-) diff --git a/server/src/apub/comment.rs b/server/src/apub/comment.rs index d90d8227b..f84bc609e 100644 --- a/server/src/apub/comment.rs +++ b/server/src/apub/comment.rs @@ -297,7 +297,7 @@ impl ApubObjectType for Comment { .set_context(context()) .set_id(generate_activity_id(DeleteType::Delete)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( &creator, @@ -331,7 +331,7 @@ impl ApubObjectType for Comment { .set_context(context()) .set_id(generate_activity_id(DeleteType::Delete)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); // Undo that fake activity let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?); @@ -339,7 +339,7 @@ impl ApubObjectType for Comment { .set_context(context()) .set_id(generate_activity_id(UndoType::Undo)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( &creator, @@ -372,7 +372,7 @@ impl ApubObjectType for Comment { .set_context(context()) .set_id(generate_activity_id(RemoveType::Remove)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( &mod_, @@ -406,7 +406,7 @@ impl ApubObjectType for Comment { .set_context(context()) .set_id(generate_activity_id(RemoveType::Remove)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); // Undo that fake activity let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?); @@ -414,7 +414,7 @@ impl ApubObjectType for Comment { .set_context(context()) .set_id(generate_activity_id(UndoType::Undo)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( &mod_, @@ -450,7 +450,7 @@ impl ApubLikeableType for Comment { .set_context(context()) .set_id(generate_activity_id(LikeType::Like)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( &creator, @@ -483,7 +483,7 @@ impl ApubLikeableType for Comment { .set_context(context()) .set_id(generate_activity_id(DislikeType::Dislike)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( &creator, @@ -516,7 +516,7 @@ impl ApubLikeableType for Comment { .set_context(context()) .set_id(generate_activity_id(DislikeType::Dislike)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); // Undo that fake activity let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?); @@ -524,7 +524,7 @@ impl ApubLikeableType for Comment { .set_context(context()) .set_id(generate_activity_id(UndoType::Undo)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( &creator, @@ -540,7 +540,7 @@ impl ApubLikeableType for Comment { } struct MentionsAndAddresses { - addressed_ccs: Vec, + addressed_ccs: Vec, inboxes: Vec, tags: Vec, } @@ -564,7 +564,7 @@ async fn collect_non_local_mentions_and_addresses( client: &Client, pool: &DbPool, ) -> Result { - let mut addressed_ccs = vec![community.get_followers_url()]; + let mut addressed_ccs = vec![community.get_followers_url()?]; // Add the mention tag let mut tags = Vec::new(); @@ -581,7 +581,7 @@ async fn collect_non_local_mentions_and_addresses( // TODO should it be fetching it every time? if let Ok(actor_id) = fetch_webfinger_url(mention, client).await { debug!("mention actor_id: {}", actor_id); - addressed_ccs.push(actor_id.to_owned().to_string()); + addressed_ccs.push(actor_id.to_owned().to_string().parse()?); let mention_user = get_or_fetch_and_upsert_user(&actor_id, client, pool).await?; let shared_inbox = mention_user.get_shared_inbox_url()?; diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs index fb8ef9bc6..adb4a3ca7 100644 --- a/server/src/apub/community.rs +++ b/server/src/apub/community.rs @@ -95,7 +95,7 @@ impl ToApub for Community { ap_actor .set_preferred_username(self.title.to_owned()) .set_outbox(self.get_outbox_url()?) - .set_followers(self.get_followers_url().parse()?) + .set_followers(self.get_followers_url()?) .set_following(self.get_following_url().parse()?) .set_liked(self.get_liked_url().parse()?) .set_endpoints(Endpoints { @@ -174,7 +174,7 @@ impl ActorType for Community { .set_context(context()) .set_id(generate_activity_id(DeleteType::Delete)?) .set_to(public()) - .set_many_ccs(vec![self.get_followers_url()]); + .set_many_ccs(vec![self.get_followers_url()?]); insert_activity(self.creator_id, delete.clone(), true, pool).await?; @@ -200,16 +200,14 @@ impl ActorType for Community { .set_context(context()) .set_id(generate_activity_id(DeleteType::Delete)?) .set_to(public()) - .set_many_ccs(vec![self.get_followers_url()]); + .set_many_ccs(vec![self.get_followers_url()?]); - // TODO - // Undo that fake activity let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?); undo .set_context(context()) .set_id(generate_activity_id(UndoType::Undo)?) .set_to(public()) - .set_many_ccs(vec![self.get_followers_url()]); + .set_many_ccs(vec![self.get_followers_url()?]); insert_activity(self.creator_id, undo.clone(), true, pool).await?; @@ -235,7 +233,7 @@ impl ActorType for Community { .set_context(context()) .set_id(generate_activity_id(RemoveType::Remove)?) .set_to(public()) - .set_many_ccs(vec![self.get_followers_url()]); + .set_many_ccs(vec![self.get_followers_url()?]); insert_activity(mod_.id, remove.clone(), true, pool).await?; @@ -261,7 +259,7 @@ impl ActorType for Community { .set_context(context()) .set_id(generate_activity_id(RemoveType::Remove)?) .set_to(public()) - .set_many_ccs(vec![self.get_followers_url()]); + .set_many_ccs(vec![self.get_followers_url()?]); // Undo that fake activity let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?); @@ -269,7 +267,7 @@ impl ActorType for Community { .set_context(context()) .set_id(generate_activity_id(LikeType::Like)?) .set_to(public()) - .set_many_ccs(vec![self.get_followers_url()]); + .set_many_ccs(vec![self.get_followers_url()?]); insert_activity(mod_.id, undo.clone(), true, pool).await?; @@ -474,8 +472,7 @@ pub async fn get_apub_community_followers( let mut collection = UnorderedCollection::new(); collection .set_context(context()) - // TODO: this needs its own ID - .set_id(community.actor_id.parse()?) + .set_id(community.get_followers_url()?) .set_total_items(community_followers.len() as u64); Ok(create_apub_response(&collection)) } @@ -522,7 +519,7 @@ pub async fn do_announce( .set_context(context()) .set_id(generate_activity_id(AnnounceType::Announce)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); insert_activity(community.creator_id, announce.clone(), true, pool).await?; diff --git a/server/src/apub/fetcher.rs b/server/src/apub/fetcher.rs index f6573a1f4..5fcf6ad97 100644 --- a/server/src/apub/fetcher.rs +++ b/server/src/apub/fetcher.rs @@ -146,8 +146,6 @@ pub async fn search_by_apub_id( let community = get_or_fetch_and_upsert_community(community_uri, client, pool).await?; - // TODO Maybe at some point in the future, fetch all the history of a community - // fetch_community_outbox(&c, conn)?; response.communities = vec![ blocking(pool, move |conn| { CommunityView::read(conn, community.id, None) @@ -166,24 +164,8 @@ pub async fn search_by_apub_id( response } SearchAcceptedObjects::Comment(c) => { - let post_url = c - .in_reply_to() - .as_ref() - .context(location_info!())? - .as_many() - .context(location_info!())?; - - // TODO: also fetch parent comments if any - let x = post_url - .first() - .context(location_info!())? - .as_xsd_any_uri() - .context(location_info!())?; - let post = fetch_remote_object(client, x).await?; - let post_form = PostForm::from_apub(&post, client, pool, Some(query_url.clone())).await?; let comment_form = CommentForm::from_apub(&c, client, pool, Some(query_url)).await?; - blocking(pool, move |conn| upsert_post(&post_form, conn)).await??; let c = blocking(pool, move |conn| upsert_comment(&comment_form, conn)).await??; response.comments = vec![blocking(pool, move |conn| CommentView::read(conn, c.id, None)).await??]; diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index 491762680..c759db1a8 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -328,8 +328,8 @@ pub trait ActorType { Url::parse(&format!("{}/outbox", &self.actor_id_str())) } - fn get_followers_url(&self) -> String { - format!("{}/followers", &self.actor_id_str()) + fn get_followers_url(&self) -> Result { + Url::parse(&format!("{}/followers", &self.actor_id_str())) } fn get_following_url(&self) -> String { diff --git a/server/src/apub/post.rs b/server/src/apub/post.rs index caf8f076a..da548516b 100644 --- a/server/src/apub/post.rs +++ b/server/src/apub/post.rs @@ -316,7 +316,7 @@ impl ApubObjectType for Post { .set_context(context()) .set_id(generate_activity_id(CreateType::Create)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( creator, @@ -347,7 +347,7 @@ impl ApubObjectType for Post { .set_context(context()) .set_id(generate_activity_id(UpdateType::Update)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( creator, @@ -377,7 +377,7 @@ impl ApubObjectType for Post { .set_context(context()) .set_id(generate_activity_id(DeleteType::Delete)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( creator, @@ -407,7 +407,7 @@ impl ApubObjectType for Post { .set_context(context()) .set_id(generate_activity_id(DeleteType::Delete)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); // Undo that fake activity let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?); @@ -415,7 +415,7 @@ impl ApubObjectType for Post { .set_context(context()) .set_id(generate_activity_id(UndoType::Undo)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( creator, @@ -445,7 +445,7 @@ impl ApubObjectType for Post { .set_context(context()) .set_id(generate_activity_id(RemoveType::Remove)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( mod_, @@ -475,7 +475,7 @@ impl ApubObjectType for Post { .set_context(context()) .set_id(generate_activity_id(RemoveType::Remove)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); // Undo that fake activity let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?); @@ -483,7 +483,7 @@ impl ApubObjectType for Post { .set_context(context()) .set_id(generate_activity_id(UndoType::Undo)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( mod_, @@ -516,7 +516,7 @@ impl ApubLikeableType for Post { .set_context(context()) .set_id(generate_activity_id(LikeType::Like)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( &creator, @@ -546,7 +546,7 @@ impl ApubLikeableType for Post { .set_context(context()) .set_id(generate_activity_id(DislikeType::Dislike)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( &creator, @@ -576,7 +576,7 @@ impl ApubLikeableType for Post { .set_context(context()) .set_id(generate_activity_id(LikeType::Like)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); // Undo that fake activity let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?); @@ -584,7 +584,7 @@ impl ApubLikeableType for Post { .set_context(context()) .set_id(generate_activity_id(UndoType::Undo)?) .set_to(public()) - .set_many_ccs(vec![community.get_followers_url()]); + .set_many_ccs(vec![community.get_followers_url()?]); send_activity_to_community( &creator, diff --git a/server/src/apub/user.rs b/server/src/apub/user.rs index 5f80b4817..0baa8cc03 100644 --- a/server/src/apub/user.rs +++ b/server/src/apub/user.rs @@ -80,7 +80,7 @@ impl ToApub for User_ { let mut ap_actor = ApActor::new(self.get_inbox_url()?, person); ap_actor .set_outbox(self.get_outbox_url()?) - .set_followers(self.get_followers_url().parse()?) + .set_followers(self.get_followers_url()?) .set_following(self.get_following_url().parse()?) .set_liked(self.get_liked_url().parse()?) .set_endpoints(Endpoints {