From: nutomic Date: Wed, 12 Aug 2020 14:43:45 +0000 (+0000) Subject: Implement undo for activitypub (#83) X-Git-Url: http://these/git/%7B%27/docs/static/git-favicon.png?a=commitdiff_plain;h=a496d8af65b01dda219d5d3bc35fa685f888855d;p=lemmy.git Implement undo for activitypub (#83) Merge branch 'main' into undo-dislike Implement undo for activitypub Fix some TODOs in activitypub code Add post_read back in, do some cleanup Add some delete functions back in Merge branch 'main' into remove-dead-code Replace body of unused db functions with unimplemented!() Remove dead code Remove remaining usages of unwrap() from activitypub code Remove most usage of Option::unwrap() from activitypub code Co-authored-by: Felix Ableitner Reviewed-on: https://yerbamate.dev/LemmyNet/lemmy/pulls/83 --- diff --git a/server/lemmy_db/src/comment.rs b/server/lemmy_db/src/comment.rs index 6802ad62..594e83cd 100644 --- a/server/lemmy_db/src/comment.rs +++ b/server/lemmy_db/src/comment.rs @@ -178,12 +178,12 @@ impl Likeable for CommentLike { .values(comment_like_form) .get_result::(conn) } - fn remove(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result { - use crate::schema::comment_like::dsl::*; + fn remove(conn: &PgConnection, user_id: i32, comment_id: i32) -> Result { + use crate::schema::comment_like::dsl; diesel::delete( - comment_like - .filter(comment_id.eq(comment_like_form.comment_id)) - .filter(user_id.eq(comment_like_form.user_id)), + dsl::comment_like + .filter(dsl::comment_id.eq(comment_id)) + .filter(dsl::user_id.eq(user_id)), ) .execute(conn) } @@ -388,7 +388,7 @@ mod tests { let read_comment = Comment::read(&conn, inserted_comment.id).unwrap(); let updated_comment = Comment::update(&conn, inserted_comment.id, &comment_form).unwrap(); - let like_removed = CommentLike::remove(&conn, &comment_like_form).unwrap(); + let like_removed = CommentLike::remove(&conn, inserted_user.id, inserted_comment.id).unwrap(); let saved_removed = CommentSaved::unsave(&conn, &comment_saved_form).unwrap(); let num_deleted = Comment::delete(&conn, inserted_comment.id).unwrap(); Comment::delete(&conn, inserted_child_comment.id).unwrap(); diff --git a/server/lemmy_db/src/comment_view.rs b/server/lemmy_db/src/comment_view.rs index 9400e320..5b140137 100644 --- a/server/lemmy_db/src/comment_view.rs +++ b/server/lemmy_db/src/comment_view.rs @@ -688,7 +688,7 @@ mod tests { read_comment_views_with_user[0].hot_rank = 0; read_comment_views_with_user[0].hot_rank_active = 0; - let like_removed = CommentLike::remove(&conn, &comment_like_form).unwrap(); + let like_removed = CommentLike::remove(&conn, inserted_user.id, inserted_comment.id).unwrap(); let num_deleted = Comment::delete(&conn, inserted_comment.id).unwrap(); Post::delete(&conn, inserted_post.id).unwrap(); Community::delete(&conn, inserted_community.id).unwrap(); diff --git a/server/lemmy_db/src/lib.rs b/server/lemmy_db/src/lib.rs index 3c22d177..a5805ef9 100644 --- a/server/lemmy_db/src/lib.rs +++ b/server/lemmy_db/src/lib.rs @@ -80,7 +80,7 @@ pub trait Likeable { fn like(conn: &PgConnection, form: &T) -> Result where Self: Sized; - fn remove(conn: &PgConnection, form: &T) -> Result + fn remove(conn: &PgConnection, user_id: i32, item_id: i32) -> Result where Self: Sized; } diff --git a/server/lemmy_db/src/post.rs b/server/lemmy_db/src/post.rs index 3c697e33..de8f5c6c 100644 --- a/server/lemmy_db/src/post.rs +++ b/server/lemmy_db/src/post.rs @@ -1,11 +1,4 @@ -use crate::{ - naive_now, - schema::{post, post_like, post_read, post_saved}, - Crud, - Likeable, - Readable, - Saveable, -}; +use crate::{naive_now, schema::{post, post_like, post_read, post_saved}, Crud, Likeable, Saveable, Readable}; use diesel::{dsl::*, result::Error, *}; use serde::{Deserialize, Serialize}; use url::{ParseError, Url}; @@ -207,12 +200,12 @@ impl Likeable for PostLike { .values(post_like_form) .get_result::(conn) } - fn remove(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result { - use crate::schema::post_like::dsl::*; + fn remove(conn: &PgConnection, user_id: i32, post_id: i32) -> Result { + use crate::schema::post_like::dsl; diesel::delete( - post_like - .filter(post_id.eq(post_like_form.post_id)) - .filter(user_id.eq(post_like_form.user_id)), + dsl::post_like + .filter(dsl::post_id.eq(post_id)) + .filter(dsl::user_id.eq(user_id)), ) .execute(conn) } @@ -437,22 +430,22 @@ mod tests { // Post Read let post_read_form = PostReadForm { - post_id: inserted_post.id, - user_id: inserted_user.id, - }; + post_id: inserted_post.id, + user_id: inserted_user.id, + }; let inserted_post_read = PostRead::mark_as_read(&conn, &post_read_form).unwrap(); let expected_post_read = PostRead { - id: inserted_post_read.id, - post_id: inserted_post.id, - user_id: inserted_user.id, - published: inserted_post_read.published, + id: inserted_post_read.id, + post_id: inserted_post.id, + user_id: inserted_user.id, + published: inserted_post_read.published, }; let read_post = Post::read(&conn, inserted_post.id).unwrap(); let updated_post = Post::update(&conn, inserted_post.id, &new_post).unwrap(); - let like_removed = PostLike::remove(&conn, &post_like_form).unwrap(); + let like_removed = PostLike::remove(&conn, inserted_user.id, inserted_post.id).unwrap(); let saved_removed = PostSaved::unsave(&conn, &post_saved_form).unwrap(); let read_removed = PostRead::mark_as_unread(&conn, &post_read_form).unwrap(); let num_deleted = Post::delete(&conn, inserted_post.id).unwrap(); diff --git a/server/lemmy_db/src/post_view.rs b/server/lemmy_db/src/post_view.rs index c10cdf1e..35bfc7ab 100644 --- a/server/lemmy_db/src/post_view.rs +++ b/server/lemmy_db/src/post_view.rs @@ -494,12 +494,6 @@ mod tests { score: 1, }; - let post_like_form = PostLikeForm { - post_id: inserted_post.id, - user_id: inserted_user.id, - score: 1, - }; - let read_post_listings_with_user = PostQueryBuilder::create(&conn) .listing_type(ListingType::Community) .sort(&SortType::New) @@ -618,7 +612,7 @@ mod tests { community_local: true, }; - let like_removed = PostLike::remove(&conn, &post_like_form).unwrap(); + let like_removed = PostLike::remove(&conn, inserted_user.id, inserted_post.id).unwrap(); let num_deleted = Post::delete(&conn, inserted_post.id).unwrap(); Community::delete(&conn, inserted_community.id).unwrap(); User_::delete(&conn, inserted_user.id).unwrap(); diff --git a/server/src/api/comment.rs b/server/src/api/comment.rs index cb366e3e..dc76b6b5 100644 --- a/server/src/api/comment.rs +++ b/server/src/api/comment.rs @@ -645,8 +645,11 @@ impl Perform for CreateCommentLike { }; // Remove any likes first - let like_form2 = like_form.clone(); - blocking(pool, move |conn| CommentLike::remove(conn, &like_form2)).await??; + let user_id = user.id; + blocking(pool, move |conn| { + CommentLike::remove(conn, user_id, comment_id) + }) + .await??; // Only add the like if the score isnt 0 let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1); diff --git a/server/src/api/post.rs b/server/src/api/post.rs index 4d089bff..2141cc10 100644 --- a/server/src/api/post.rs +++ b/server/src/api/post.rs @@ -430,8 +430,8 @@ impl Perform for CreatePostLike { }; // Remove any likes first - let like_form2 = like_form.clone(); - blocking(pool, move |conn| PostLike::remove(conn, &like_form2)).await??; + let user_id = user.id; + blocking(pool, move |conn| PostLike::remove(conn, user_id, post_id)).await??; // Only add the like if the score isnt 0 let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1); diff --git a/server/src/apub/comment.rs b/server/src/apub/comment.rs index d90d8227..f84bc609 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 fb8ef9bc..adb4a3ca 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 f6573a1f..5fcf6ad9 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/inbox/activities/dislike.rs b/server/src/apub/inbox/activities/dislike.rs index 233c89d8..07f5ac30 100644 --- a/server/src/apub/inbox/activities/dislike.rs +++ b/server/src/apub/inbox/activities/dislike.rs @@ -72,8 +72,9 @@ async fn receive_dislike_post( user_id: user.id, score: -1, }; + let user_id = user.id; blocking(pool, move |conn| { - PostLike::remove(conn, &like_form)?; + PostLike::remove(conn, user_id, post_id)?; PostLike::like(conn, &like_form) }) .await??; @@ -121,8 +122,9 @@ async fn receive_dislike_comment( user_id: user.id, score: -1, }; + let user_id = user.id; blocking(pool, move |conn| { - CommentLike::remove(conn, &like_form)?; + CommentLike::remove(conn, user_id, comment_id)?; CommentLike::like(conn, &like_form) }) .await??; diff --git a/server/src/apub/inbox/activities/like.rs b/server/src/apub/inbox/activities/like.rs index db34190f..b82f5f72 100644 --- a/server/src/apub/inbox/activities/like.rs +++ b/server/src/apub/inbox/activities/like.rs @@ -66,8 +66,9 @@ async fn receive_like_post( user_id: user.id, score: 1, }; + let user_id = user.id; blocking(pool, move |conn| { - PostLike::remove(conn, &like_form)?; + PostLike::remove(conn, user_id, post_id)?; PostLike::like(conn, &like_form) }) .await??; @@ -109,8 +110,9 @@ async fn receive_like_comment( user_id: user.id, score: 1, }; + let user_id = user.id; blocking(pool, move |conn| { - CommentLike::remove(conn, &like_form)?; + CommentLike::remove(conn, user_id, comment_id)?; CommentLike::like(conn, &like_form) }) .await??; diff --git a/server/src/apub/inbox/activities/undo.rs b/server/src/apub/inbox/activities/undo.rs index 457fef6d..4cfcea27 100644 --- a/server/src/apub/inbox/activities/undo.rs +++ b/server/src/apub/inbox/activities/undo.rs @@ -30,12 +30,12 @@ use activitystreams::{ use actix_web::{client::Client, HttpResponse}; use anyhow::{anyhow, Context}; use lemmy_db::{ - comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, + comment::{Comment, CommentForm, CommentLike}, comment_view::CommentView, community::{Community, CommunityForm}, community_view::CommunityView, naive_now, - post::{Post, PostForm, PostLike, PostLikeForm}, + post::{Post, PostForm, PostLike}, post_view::PostView, Crud, Likeable, @@ -145,21 +145,23 @@ async fn receive_undo_like( async fn receive_undo_dislike( undo: Undo, - _client: &Client, - _pool: &DbPool, - _chat_server: ChatServerParam, + client: &Client, + pool: &DbPool, + chat_server: ChatServerParam, ) -> Result { let dislike = Dislike::from_any_base(undo.object().to_owned().one().context(location_info!())?)? .context(location_info!())?; check_is_undo_valid(&undo, &dislike)?; - // TODO: need to implement Undo - let type_ = dislike .object() .as_single_kind_str() .context(location_info!())?; - Err(anyhow!("Undo Delete type {} not supported", type_).into()) + match type_ { + "Note" => receive_undo_dislike_comment(undo, &dislike, client, pool, chat_server).await, + "Page" => receive_undo_dislike_post(undo, &dislike, client, pool, chat_server).await, + d => Err(anyhow!("Undo Delete type {} not supported", d).into()), + } } async fn receive_undo_delete_comment( @@ -543,13 +545,11 @@ async fn receive_undo_like_comment( .await? .id; - let like_form = CommentLikeForm { - comment_id, - post_id: comment.post_id, - user_id: user.id, - score: 0, - }; - blocking(pool, move |conn| CommentLike::remove(conn, &like_form)).await??; + let user_id = user.id; + blocking(pool, move |conn| { + CommentLike::remove(conn, user_id, comment_id) + }) + .await??; // Refetch the view let comment_view = @@ -590,12 +590,100 @@ async fn receive_undo_like_post( .await? .id; - let like_form = PostLikeForm { - post_id, - user_id: user.id, - score: 1, + let user_id = user.id; + blocking(pool, move |conn| PostLike::remove(conn, user_id, post_id)).await??; + + // Refetch the view + let post_view = blocking(pool, move |conn| PostView::read(conn, post_id, None)).await??; + + let res = PostResponse { post: post_view }; + + chat_server.do_send(SendPost { + op: UserOperation::CreatePostLike, + post: res, + my_id: None, + }); + + announce_if_community_is_local(undo, &user, client, pool).await?; + Ok(HttpResponse::Ok().finish()) +} + +async fn receive_undo_dislike_comment( + undo: Undo, + dislike: &Dislike, + client: &Client, + pool: &DbPool, + chat_server: ChatServerParam, +) -> Result { + let user = get_user_from_activity(dislike, client, pool).await?; + let note = Note::from_any_base( + dislike + .object() + .to_owned() + .one() + .context(location_info!())?, + )? + .context(location_info!())?; + + let comment = CommentForm::from_apub(¬e, client, pool, None).await?; + + let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool) + .await? + .id; + + let user_id = user.id; + blocking(pool, move |conn| { + CommentLike::remove(conn, user_id, comment_id) + }) + .await??; + + // Refetch the view + let comment_view = + blocking(pool, move |conn| CommentView::read(conn, comment_id, None)).await??; + + // TODO get those recipient actor ids from somewhere + let recipient_ids = vec![]; + let res = CommentResponse { + comment: comment_view, + recipient_ids, + form_id: None, }; - blocking(pool, move |conn| PostLike::remove(conn, &like_form)).await??; + + chat_server.do_send(SendComment { + op: UserOperation::CreateCommentLike, + comment: res, + my_id: None, + }); + + announce_if_community_is_local(undo, &user, client, pool).await?; + Ok(HttpResponse::Ok().finish()) +} + +async fn receive_undo_dislike_post( + undo: Undo, + dislike: &Dislike, + client: &Client, + pool: &DbPool, + chat_server: ChatServerParam, +) -> Result { + let user = get_user_from_activity(dislike, client, pool).await?; + let page = PageExt::from_any_base( + dislike + .object() + .to_owned() + .one() + .context(location_info!())?, + )? + .context(location_info!())?; + + let post = PostForm::from_apub(&page, client, pool, None).await?; + + let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool) + .await? + .id; + + let user_id = user.id; + blocking(pool, move |conn| PostLike::remove(conn, user_id, post_id)).await??; // Refetch the view let post_view = blocking(pool, move |conn| PostView::read(conn, post_id, None)).await??; diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index 49176268..c759db1a 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 caf8f076..da548516 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 5f80b481..0baa8cc0 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 {