]> Untitled Git - lemmy.git/commitdiff
Implement undo<dislike> for activitypub (#83)
authornutomic <nutomic@noreply.yerbamate.dev>
Wed, 12 Aug 2020 14:43:45 +0000 (14:43 +0000)
committerdessalines <dessalines@noreply.yerbamate.dev>
Wed, 12 Aug 2020 14:43:45 +0000 (14:43 +0000)
Merge branch 'main' into undo-dislike

Implement undo<dislike> 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 <me@nutomic.com>
Reviewed-on: https://yerbamate.dev/LemmyNet/lemmy/pulls/83

16 files changed:
server/lemmy_db/src/comment.rs
server/lemmy_db/src/comment_view.rs
server/lemmy_db/src/lib.rs
server/lemmy_db/src/post.rs
server/lemmy_db/src/post_view.rs
server/src/api/comment.rs
server/src/api/post.rs
server/src/apub/comment.rs
server/src/apub/community.rs
server/src/apub/fetcher.rs
server/src/apub/inbox/activities/dislike.rs
server/src/apub/inbox/activities/like.rs
server/src/apub/inbox/activities/undo.rs
server/src/apub/mod.rs
server/src/apub/post.rs
server/src/apub/user.rs

index 6802ad62cdb6d39bb6e71eeb5747161e73276bc1..594e83cdf4b83b5620c7986a66fc61d5801d6ee7 100644 (file)
@@ -178,12 +178,12 @@ impl Likeable<CommentLikeForm> for CommentLike {
       .values(comment_like_form)
       .get_result::<Self>(conn)
   }
-  fn remove(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<usize, Error> {
-    use crate::schema::comment_like::dsl::*;
+  fn remove(conn: &PgConnection, user_id: i32, comment_id: i32) -> Result<usize, Error> {
+    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();
index 9400e32089437f5fbed5f18b1996a58db7dcee0b..5b14013770542fd1dbeb4d1f07ee4f1975b013e1 100644 (file)
@@ -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();
index 3c22d1776253bdfda6978ef465fc6bd533c5620c..a5805ef9599fbfdc971571e7ea0a4d3d75ffeb16 100644 (file)
@@ -80,7 +80,7 @@ pub trait Likeable<T> {
   fn like(conn: &PgConnection, form: &T) -> Result<Self, Error>
   where
     Self: Sized;
-  fn remove(conn: &PgConnection, form: &T) -> Result<usize, Error>
+  fn remove(conn: &PgConnection, user_id: i32, item_id: i32) -> Result<usize, Error>
   where
     Self: Sized;
 }
index 3c697e33d3343432f4e7bcedfd568e5d107416e3..de8f5c6c861dd0c6656c1783ff4215bff00774fe 100644 (file)
@@ -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<PostLikeForm> for PostLike {
       .values(post_like_form)
       .get_result::<Self>(conn)
   }
-  fn remove(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<usize, Error> {
-    use crate::schema::post_like::dsl::*;
+  fn remove(conn: &PgConnection, user_id: i32, post_id: i32) -> Result<usize, Error> {
+    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();
index c10cdf1e702eb9c0143dd433f4fd44073b30a37c..35bfc7ab3958b15666147919211b0e1f79e3c323 100644 (file)
@@ -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();
index cb366e3eb92048af00113c415a7ca9189670abf4..dc76b6b5af8da6f3a3e520e966dfa59a27222536 100644 (file)
@@ -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);
index 4d089bff7b4c6d2a8ce161b2186d5550d33ee3b4..2141cc10dd3c65dc9d13a8cb0f486b32b450c2ac 100644 (file)
@@ -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);
index d90d8227b3e423c42f9974f6f9af4f922b1c3553..f84bc609ee218eea5f8da5687b0ace24689d1fa7 100644 (file)
@@ -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<String>,
+  addressed_ccs: Vec<Url>,
   inboxes: Vec<Url>,
   tags: Vec<Mention>,
 }
@@ -564,7 +564,7 @@ async fn collect_non_local_mentions_and_addresses(
   client: &Client,
   pool: &DbPool,
 ) -> Result<MentionsAndAddresses, LemmyError> {
-  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()?;
index fb8ef9bc6507d458c42004922269408cbe737c1d..adb4a3ca781fc28fc413e97d1c9580928f9f65ae 100644 (file)
@@ -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?;
 
index f6573a1f486f5ba1ea9f23a6f2ae2fda9aefc34d..5fcf6ad97a1067c29816ba56974acad3b9a8329d 100644 (file)
@@ -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??];
index 233c89d815534b87a9acebbf3b48c3d1b077cb60..07f5ac30b43d6f9596145b3d9c52ae6b9fd91f31 100644 (file)
@@ -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??;
index db34190f27178d85a4358d775a882a038cc8b189..b82f5f72c6ea17d36f181d4a2b1782768e36b9db 100644 (file)
@@ -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??;
index 457fef6d85e7272c40c6cfa5d34e180cc1628aba..4cfcea272928161eefa0dd40d3f6a9adb39fc99e 100644 (file)
@@ -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<HttpResponse, LemmyError> {
   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<Dislike>
-
   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<HttpResponse, LemmyError> {
+  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(&note, 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<HttpResponse, LemmyError> {
+  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??;
index 491762680a5c7447e722910a887f5839facf7116..c759db1a8f8969a8d57b707a3edba8a6f4e31c29 100644 (file)
@@ -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, ParseError> {
+    Url::parse(&format!("{}/followers", &self.actor_id_str()))
   }
 
   fn get_following_url(&self) -> String {
index caf8f076a3de20b5b80d8e80bea9e7496942203c..da548516b398c03e63ab0bdc089a573d81a1a18e 100644 (file)
@@ -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,
index 5f80b48176fc1ebc79d2978261253824012ccf3d..0baa8cc035ee6f7068c88b91f82350d10ceca5c9 100644 (file)
@@ -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 {