]> Untitled Git - lemmy.git/commitdiff
Merge branch 'main' into inbox-refactoring-merge
authorDessalines <tyhou13@gmx.com>
Tue, 28 Jul 2020 16:08:28 +0000 (12:08 -0400)
committerDessalines <tyhou13@gmx.com>
Tue, 28 Jul 2020 16:08:28 +0000 (12:08 -0400)
15 files changed:
1  2 
server/lemmy_db/src/community.rs
server/src/api/comment.rs
server/src/apub/inbox/activities/announce.rs
server/src/apub/inbox/activities/create.rs
server/src/apub/inbox/activities/delete.rs
server/src/apub/inbox/activities/dislike.rs
server/src/apub/inbox/activities/like.rs
server/src/apub/inbox/activities/remove.rs
server/src/apub/inbox/activities/undo.rs
server/src/apub/inbox/activities/update.rs
server/src/apub/inbox/mod.rs
server/src/apub/inbox/shared_inbox.rs
server/src/apub/user.rs
server/src/routes/federation.rs
ui/src/components/create-post.tsx

index e1f24391991f312771ab501ac7fddbf429149a5f,3a78d769d33620ce89550e86c178d76f79315cb0..c4930d7931e958dc3649cc8c9f761adb91e29bf4
@@@ -99,6 -99,60 +99,57 @@@ impl Community 
      use crate::schema::community::dsl::*;
      community.filter(local.eq(true)).load::<Community>(conn)
    }
 -  fn community_mods_and_admins(
 -    conn: &PgConnection,
 -    community_id: i32,
 -  ) -> Result<Vec<i32>, Error> {
+   pub fn update_deleted(
+     conn: &PgConnection,
+     community_id: i32,
+     new_deleted: bool,
+   ) -> Result<Self, Error> {
+     use crate::schema::community::dsl::*;
+     diesel::update(community.find(community_id))
+       .set(deleted.eq(new_deleted))
+       .get_result::<Self>(conn)
+   }
+   pub fn update_removed(
+     conn: &PgConnection,
+     community_id: i32,
+     new_removed: bool,
+   ) -> Result<Self, Error> {
+     use crate::schema::community::dsl::*;
+     diesel::update(community.find(community_id))
+       .set(removed.eq(new_removed))
+       .get_result::<Self>(conn)
+   }
+   pub fn update_creator(
+     conn: &PgConnection,
+     community_id: i32,
+     new_creator_id: i32,
+   ) -> Result<Self, Error> {
+     use crate::schema::community::dsl::*;
+     diesel::update(community.find(community_id))
+       .set((creator_id.eq(new_creator_id), updated.eq(naive_now())))
+       .get_result::<Self>(conn)
+   }
++  fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error> {
+     use crate::{community_view::CommunityModeratorView, user_view::UserView};
+     let mut mods_and_admins: Vec<i32> = Vec::new();
+     mods_and_admins.append(
+       &mut CommunityModeratorView::for_community(conn, community_id)
+         .map(|v| v.into_iter().map(|m| m.user_id).collect())?,
+     );
+     mods_and_admins
+       .append(&mut UserView::admins(conn).map(|v| v.into_iter().map(|a| a.id).collect())?);
+     Ok(mods_and_admins)
+   }
+   pub fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool {
+     Self::community_mods_and_admins(conn, community_id)
+       .unwrap_or_default()
+       .contains(&user_id)
+   }
  }
  
  #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
index d0dfa7a7c5037fd7dc5552efd1b8d110b85e3ed3,df772f53591b32ea8fe2f02bd08e83c9982bec59..7dfce473f3e5b6016f6a2999d7df815ec8c9265c
@@@ -175,8 -196,15 +196,8 @@@ impl Perform for Oper<CreateComment> 
  
      // Scan the comment for user mentions, add those rows
      let mentions = scrape_text_for_mentions(&comment_form.content);
 -    let recipient_ids = send_local_notifs(
 -      mentions,
 -      updated_comment.clone(),
 -      user.clone(),
 -      post,
 -      pool,
 -      true,
 -    )
 -    .await?;
 +    let recipient_ids =
-       send_local_notifs(mentions, updated_comment.clone(), &user, post, pool).await?;
++      send_local_notifs(mentions, updated_comment.clone(), &user, post, pool, true).await?;
  
      // You like your own comment by default
      let like_form = CommentLikeForm {
@@@ -243,116 -270,124 +263,124 @@@ impl Perform for Oper<EditComment> 
      let orig_comment =
        blocking(pool, move |conn| CommentView::read(&conn, edit_id, None)).await??;
  
-     let mut editors: Vec<i32> = vec![orig_comment.creator_id];
-     let mut moderators: Vec<i32> = vec![];
+     // Check for a site ban
+     let user = blocking(pool, move |conn| User_::read(conn, user_id)).await??;
+     if user.banned {
+       return Err(APIError::err("site_ban").into());
+     }
  
+     // Check for a community ban
      let community_id = orig_comment.community_id;
-     moderators.append(
-       &mut blocking(pool, move |conn| {
-         CommunityModeratorView::for_community(&conn, community_id)
-           .map(|v| v.into_iter().map(|m| m.user_id).collect())
-       })
-       .await??,
-     );
-     moderators.append(
-       &mut blocking(pool, move |conn| {
-         UserView::admins(conn).map(|v| v.into_iter().map(|a| a.id).collect())
-       })
-       .await??,
-     );
-     editors.extend(&moderators);
-     // You are allowed to mark the comment as read even if you're banned.
-     if data.read.is_none() {
-       // Verify its the creator or a mod, or an admin
-       if !editors.contains(&user_id) {
-         return Err(APIError::err("no_comment_edit_allowed").into());
-       }
-       // Check for a community ban
-       let community_id = orig_comment.community_id;
-       let is_banned =
-         move |conn: &'_ _| CommunityUserBanView::get(conn, user_id, community_id).is_ok();
-       if blocking(pool, is_banned).await? {
-         return Err(APIError::err("community_ban").into());
-       }
+     let is_banned =
+       move |conn: &'_ _| CommunityUserBanView::get(conn, user_id, community_id).is_ok();
+     if blocking(pool, is_banned).await? {
+       return Err(APIError::err("community_ban").into());
+     }
  
-       // Check for a site ban
-       if user.banned {
-         return Err(APIError::err("site_ban").into());
-       }
-     } else {
-       // check that user can mark as read
-       let parent_id = orig_comment.parent_id;
-       match parent_id {
-         Some(pid) => {
-           let parent_comment =
-             blocking(pool, move |conn| CommentView::read(&conn, pid, None)).await??;
-           if user_id != parent_comment.creator_id {
-             return Err(APIError::err("no_comment_edit_allowed").into());
-           }
-         }
-         None => {
-           let parent_post_id = orig_comment.post_id;
-           let parent_post = blocking(pool, move |conn| Post::read(conn, parent_post_id)).await??;
-           if user_id != parent_post.creator_id {
-             return Err(APIError::err("no_comment_edit_allowed").into());
-           }
-         }
-       }
+     // Verify that only the creator can edit
+     if user_id != orig_comment.creator_id {
+       return Err(APIError::err("no_comment_edit_allowed").into());
      }
  
+     // Do the update
      let content_slurs_removed = remove_slurs(&data.content.to_owned());
 -      send_local_notifs(mentions, updated_comment, user, post, pool, false).await?;
+     let edit_id = data.edit_id;
+     let updated_comment = match blocking(pool, move |conn| {
+       Comment::update_content(conn, edit_id, &content_slurs_removed)
+     })
+     .await?
+     {
+       Ok(comment) => comment,
+       Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
+     };
+     // Send the apub update
+     updated_comment
+       .send_update(&user, &self.client, pool)
+       .await?;
+     // Do the mentions / recipients
+     let post_id = orig_comment.post_id;
+     let post = blocking(pool, move |conn| Post::read(conn, post_id)).await??;
+     let updated_comment_content = updated_comment.content.to_owned();
+     let mentions = scrape_text_for_mentions(&updated_comment_content);
+     let recipient_ids =
++      send_local_notifs(mentions, updated_comment, &user, post, pool, false).await?;
  
      let edit_id = data.edit_id;
-     let read_comment = blocking(pool, move |conn| Comment::read(conn, edit_id)).await??;
-     let comment_form = {
-       if data.read.is_none() {
-         // the ban etc checks should been made and have passed
-         // the comment can be properly edited
-         let post_removed = if moderators.contains(&user_id) {
-           data.removed
-         } else {
-           Some(read_comment.removed)
-         };
-         CommentForm {
-           content: content_slurs_removed,
-           parent_id: read_comment.parent_id,
-           post_id: read_comment.post_id,
-           creator_id: read_comment.creator_id,
-           removed: post_removed.to_owned(),
-           deleted: data.deleted.to_owned(),
-           read: Some(read_comment.read),
-           published: None,
-           updated: Some(naive_now()),
-           ap_id: read_comment.ap_id,
-           local: read_comment.local,
-         }
-       } else {
-         // the only field that can be updated it the read field
-         CommentForm {
-           content: read_comment.content,
-           parent_id: read_comment.parent_id,
-           post_id: read_comment.post_id,
-           creator_id: read_comment.creator_id,
-           removed: Some(read_comment.removed).to_owned(),
-           deleted: Some(read_comment.deleted).to_owned(),
-           read: data.read.to_owned(),
-           published: None,
-           updated: orig_comment.updated,
-           ap_id: read_comment.ap_id,
-           local: read_comment.local,
-         }
-       }
+     let comment_view = blocking(pool, move |conn| {
+       CommentView::read(conn, edit_id, Some(user_id))
+     })
+     .await??;
+     let mut res = CommentResponse {
+       comment: comment_view,
+       recipient_ids,
+       form_id: data.form_id.to_owned(),
      };
  
+     if let Some(ws) = websocket_info {
+       ws.chatserver.do_send(SendComment {
+         op: UserOperation::EditComment,
+         comment: res.clone(),
+         my_id: ws.id,
+       });
+       // strip out the recipient_ids, so that
+       // users don't get double notifs
+       res.recipient_ids = Vec::new();
+     }
+     Ok(res)
+   }
+ }
+ #[async_trait::async_trait(?Send)]
+ impl Perform for Oper<DeleteComment> {
+   type Response = CommentResponse;
+   async fn perform(
+     &self,
+     pool: &DbPool,
+     websocket_info: Option<WebsocketInfo>,
+   ) -> Result<CommentResponse, LemmyError> {
+     let data: &DeleteComment = &self.data;
+     let claims = match Claims::decode(&data.auth) {
+       Ok(claims) => claims.claims,
+       Err(_e) => return Err(APIError::err("not_logged_in").into()),
+     };
+     let user_id = claims.id;
      let edit_id = data.edit_id;
-     let comment_form2 = comment_form.clone();
+     let orig_comment =
+       blocking(pool, move |conn| CommentView::read(&conn, edit_id, None)).await??;
+     // Check for a site ban
+     let user = blocking(pool, move |conn| User_::read(conn, user_id)).await??;
+     if user.banned {
+       return Err(APIError::err("site_ban").into());
+     }
+     // Check for a community ban
+     let community_id = orig_comment.community_id;
+     let is_banned =
+       move |conn: &'_ _| CommunityUserBanView::get(conn, user_id, community_id).is_ok();
+     if blocking(pool, is_banned).await? {
+       return Err(APIError::err("community_ban").into());
+     }
+     // Verify that only the creator can delete
+     if user_id != orig_comment.creator_id {
+       return Err(APIError::err("no_comment_edit_allowed").into());
+     }
+     // Do the delete
+     let deleted = data.deleted;
      let updated_comment = match blocking(pool, move |conn| {
-       Comment::update(conn, edit_id, &comment_form2)
+       Comment::update_deleted(conn, edit_id, deleted)
      })
      .await?
      {
        Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
      };
  
-     if data.read.is_none() {
-       if let Some(deleted) = data.deleted.to_owned() {
-         if deleted {
-           updated_comment
-             .send_delete(&user, &self.client, pool)
-             .await?;
-         } else {
-           updated_comment
-             .send_undo_delete(&user, &self.client, pool)
-             .await?;
-         }
-       } else if let Some(removed) = data.removed.to_owned() {
-         if moderators.contains(&user_id) {
-           if removed {
-             updated_comment
-               .send_remove(&user, &self.client, pool)
-               .await?;
-           } else {
-             updated_comment
-               .send_undo_remove(&user, &self.client, pool)
-               .await?;
-           }
-         }
-       } else {
-         updated_comment
-           .send_update(&user, &self.client, pool)
-           .await?;
-       }
-       // Mod tables
-       if moderators.contains(&user_id) {
-         if let Some(removed) = data.removed.to_owned() {
-           let form = ModRemoveCommentForm {
-             mod_user_id: user_id,
-             comment_id: data.edit_id,
-             removed: Some(removed),
-             reason: data.reason.to_owned(),
-           };
-           blocking(pool, move |conn| ModRemoveComment::create(conn, &form)).await??;
-         }
-       }
+     // Send the apub message
+     if deleted {
+       updated_comment
+         .send_delete(&user, &self.client, pool)
+         .await?;
+     } else {
+       updated_comment
+         .send_undo_delete(&user, &self.client, pool)
+         .await?;
      }
  
-     let post_id = data.post_id;
+     // Refetch it
+     let edit_id = data.edit_id;
+     let comment_view = blocking(pool, move |conn| {
+       CommentView::read(conn, edit_id, Some(user_id))
+     })
+     .await??;
+     // Build the recipients
+     let post_id = comment_view.post_id;
      let post = blocking(pool, move |conn| Post::read(conn, post_id)).await??;
 -      send_local_notifs(mentions, updated_comment, user, post, pool, false).await?;
+     let mentions = vec![];
+     let recipient_ids =
++      send_local_notifs(mentions, updated_comment, &user, post, pool, false).await?;
  
-     let mentions = scrape_text_for_mentions(&comment_form.content);
-     let recipient_ids = send_local_notifs(mentions, updated_comment, &user, post, pool).await?;
+     let mut res = CommentResponse {
+       comment: comment_view,
+       recipient_ids,
+       form_id: None,
+     };
+     if let Some(ws) = websocket_info {
+       ws.chatserver.do_send(SendComment {
+         op: UserOperation::DeleteComment,
+         comment: res.clone(),
+         my_id: ws.id,
+       });
+       // strip out the recipient_ids, so that
+       // users don't get double notifs
+       res.recipient_ids = Vec::new();
+     }
+     Ok(res)
+   }
+ }
+ #[async_trait::async_trait(?Send)]
+ impl Perform for Oper<RemoveComment> {
+   type Response = CommentResponse;
+   async fn perform(
+     &self,
+     pool: &DbPool,
+     websocket_info: Option<WebsocketInfo>,
+   ) -> Result<CommentResponse, LemmyError> {
+     let data: &RemoveComment = &self.data;
+     let claims = match Claims::decode(&data.auth) {
+       Ok(claims) => claims.claims,
+       Err(_e) => return Err(APIError::err("not_logged_in").into()),
+     };
+     let user_id = claims.id;
+     let edit_id = data.edit_id;
+     let orig_comment =
+       blocking(pool, move |conn| CommentView::read(&conn, edit_id, None)).await??;
+     // Check for a site ban
+     let user = blocking(pool, move |conn| User_::read(conn, user_id)).await??;
+     if user.banned {
+       return Err(APIError::err("site_ban").into());
+     }
+     // Check for a community ban
+     let community_id = orig_comment.community_id;
+     let is_banned =
+       move |conn: &'_ _| CommunityUserBanView::get(conn, user_id, community_id).is_ok();
+     if blocking(pool, is_banned).await? {
+       return Err(APIError::err("community_ban").into());
+     }
+     // Verify that only a mod or admin can remove
+     is_mod_or_admin(pool, user_id, community_id).await?;
+     // Do the remove
+     let removed = data.removed;
+     let updated_comment = match blocking(pool, move |conn| {
+       Comment::update_removed(conn, edit_id, removed)
+     })
+     .await?
+     {
+       Ok(comment) => comment,
+       Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
+     };
+     // Mod tables
+     let form = ModRemoveCommentForm {
+       mod_user_id: user_id,
+       comment_id: data.edit_id,
+       removed: Some(removed),
+       reason: data.reason.to_owned(),
+     };
+     blocking(pool, move |conn| ModRemoveComment::create(conn, &form)).await??;
+     // Send the apub message
+     if removed {
+       updated_comment
+         .send_remove(&user, &self.client, pool)
+         .await?;
+     } else {
+       updated_comment
+         .send_undo_remove(&user, &self.client, pool)
+         .await?;
+     }
  
+     // Refetch it
      let edit_id = data.edit_id;
      let comment_view = blocking(pool, move |conn| {
        CommentView::read(conn, edit_id, Some(user_id))
      })
      .await??;
  
 -      send_local_notifs(mentions, updated_comment, user, post, pool, false).await?;
+     // Build the recipients
+     let post_id = comment_view.post_id;
+     let post = blocking(pool, move |conn| Post::read(conn, post_id)).await??;
+     let mentions = vec![];
+     let recipient_ids =
++      send_local_notifs(mentions, updated_comment, &user, post, pool, false).await?;
      let mut res = CommentResponse {
        comment: comment_view,
        recipient_ids,
@@@ -672,13 -870,13 +863,14 @@@ impl Perform for Oper<GetComments> 
  pub async fn send_local_notifs(
    mentions: Vec<MentionData>,
    comment: Comment,
 -  user: User_,
 +  user: &User_,
    post: Post,
    pool: &DbPool,
+   do_send_email: bool,
  ) -> Result<Vec<i32>, LemmyError> {
 +  let user2 = user.clone();
    let ids = blocking(pool, move |conn| {
-     do_send_local_notifs(conn, &mentions, &comment, &user2, &post)
 -    do_send_local_notifs(conn, &mentions, &comment, &user, &post, do_send_email)
++    do_send_local_notifs(conn, &mentions, &comment, &user2, &post, do_send_email)
    })
    .await?;
  
index 9564555a6c8b79c16cefc21b00aa612ac81e524e,0000000000000000000000000000000000000000..78a005fb17618a97e1cb0a5b05c70421a1f70696
mode 100644,000000..100644
--- /dev/null
@@@ -1,56 -1,0 +1,41 @@@
-   apub::{
-     inbox::activities::{
 +use crate::{
-     inbox::shared_inbox::receive_unhandled_activity,
++  apub::inbox::{
++    activities::{
 +      create::receive_create,
 +      delete::receive_delete,
 +      dislike::receive_dislike,
 +      like::receive_like,
 +      remove::receive_remove,
 +      undo::receive_undo,
 +      update::receive_update,
 +    },
- use activitystreams_new::{activity::*, prelude::ExtendsExt};
++    shared_inbox::receive_unhandled_activity,
 +  },
 +  routes::ChatServerParam,
 +  DbPool,
 +  LemmyError,
 +};
- use activitystreams_new::base::AnyBase;
++use activitystreams_new::{activity::*, base::AnyBase, prelude::ExtendsExt};
 +use actix_web::{client::Client, HttpResponse};
-     Some("Create") => {
-       receive_create(object2, client, pool, chat_server).await
-     }
-     Some("Update") => {
-       receive_update(object2, client, pool, chat_server).await
-     }
-     Some("Like") => {
-       receive_like(object2, client, pool, chat_server).await
-     }
-     Some("Dislike") => {
-       receive_dislike(object2, client, pool, chat_server).await
-     }
-     Some("Delete") => {
-       receive_delete(object2, client, pool, chat_server).await
-     }
-     Some("Remove") => {
-       receive_remove(object2, client, pool, chat_server).await
-     }
-     Some("Undo") => {
-       receive_undo(object2, client, pool, chat_server).await
-     }
 +
 +pub async fn receive_announce(
 +  activity: AnyBase,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let announce = Announce::from_any_base(activity)?.unwrap();
 +  let kind = announce.object().as_single_kind_str();
 +  let object = announce.object();
 +  let object2 = object.clone().one().unwrap();
 +  match kind {
++    Some("Create") => receive_create(object2, client, pool, chat_server).await,
++    Some("Update") => receive_update(object2, client, pool, chat_server).await,
++    Some("Like") => receive_like(object2, client, pool, chat_server).await,
++    Some("Dislike") => receive_dislike(object2, client, pool, chat_server).await,
++    Some("Delete") => receive_delete(object2, client, pool, chat_server).await,
++    Some("Remove") => receive_remove(object2, client, pool, chat_server).await,
++    Some("Undo") => receive_undo(object2, client, pool, chat_server).await,
 +    _ => receive_unhandled_activity(announce),
 +  }
 +}
index 413a2977b5ab6a1c2d9ba6f8d1e57fc95cb1cce2,0000000000000000000000000000000000000000..da90bea53109a198d323052ddc6b74a8d8c04161
mode 100644,000000..100644
--- /dev/null
@@@ -1,124 -1,0 +1,127 @@@
-   apub::inbox::shared_inbox::{get_user_from_activity, receive_unhandled_activity},
 +use crate::{
 +  api::{
 +    comment::{send_local_notifs, CommentResponse},
 +    post::PostResponse,
 +  },
- use activitystreams_new::{activity::Create, object::Note, prelude::*};
 +  apub::{
++    inbox::shared_inbox::{
++      announce_if_community_is_local,
++      get_user_from_activity,
++      receive_unhandled_activity,
++    },
 +    ActorType,
 +    FromApub,
 +    PageExt,
 +  },
 +  blocking,
 +  routes::ChatServerParam,
 +  websocket::{
 +    server::{SendComment, SendPost},
 +    UserOperation,
 +  },
 +  DbPool,
 +  LemmyError,
 +};
- use activitystreams_new::base::AnyBase;
- use crate::apub::inbox::shared_inbox::{announce_if_community_is_local};
++use activitystreams_new::{activity::Create, base::AnyBase, object::Note, prelude::*};
 +use actix_web::{client::Client, HttpResponse};
 +use lemmy_db::{
 +  comment::{Comment, CommentForm},
 +  comment_view::CommentView,
 +  post::{Post, PostForm},
 +  post_view::PostView,
 +  Crud,
 +};
 +use lemmy_utils::scrape_text_for_mentions;
-     send_local_notifs(mentions, inserted_comment.clone(), &user, post, pool).await?;
 +
 +pub async fn receive_create(
 +  activity: AnyBase,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let create = Create::from_any_base(activity)?.unwrap();
 +  dbg!(create.object().as_single_kind_str());
 +  match create.object().as_single_kind_str() {
 +    Some("Page") => receive_create_post(create, client, pool, chat_server).await,
 +    Some("Note") => receive_create_comment(create, client, pool, chat_server).await,
 +    _ => receive_unhandled_activity(create),
 +  }
 +}
 +
 +async fn receive_create_post(
 +  create: Create,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let user = get_user_from_activity(&create, client, pool).await?;
 +  let page = PageExt::from_any_base(create.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
 +
 +  let inserted_post = blocking(pool, move |conn| Post::create(conn, &post)).await??;
 +
 +  // Refetch the view
 +  let inserted_post_id = inserted_post.id;
 +  let post_view = blocking(pool, move |conn| {
 +    PostView::read(conn, inserted_post_id, None)
 +  })
 +  .await??;
 +
 +  let res = PostResponse { post: post_view };
 +
 +  chat_server.do_send(SendPost {
 +    op: UserOperation::CreatePost,
 +    post: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(create, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_create_comment(
 +  create: Create,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let user = get_user_from_activity(&create, client, pool).await?;
 +  let note = Note::from_any_base(create.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let comment = CommentForm::from_apub(&note, client, pool, &user.actor_id()?).await?;
 +
 +  let inserted_comment = blocking(pool, move |conn| Comment::create(conn, &comment)).await??;
 +
 +  let post_id = inserted_comment.post_id;
 +  let post = blocking(pool, move |conn| Post::read(conn, post_id)).await??;
 +
 +  // Note:
 +  // Although mentions could be gotten from the post tags (they are included there), or the ccs,
 +  // Its much easier to scrape them from the comment body, since the API has to do that
 +  // anyway.
 +  let mentions = scrape_text_for_mentions(&inserted_comment.content);
 +  let recipient_ids =
++    send_local_notifs(mentions, inserted_comment.clone(), &user, post, pool, true).await?;
 +
 +  // Refetch the view
 +  let comment_view = blocking(pool, move |conn| {
 +    CommentView::read(conn, inserted_comment.id, None)
 +  })
 +  .await??;
 +
 +  let res = CommentResponse {
 +    comment: comment_view,
 +    recipient_ids,
++    form_id: None,
 +  };
 +
 +  chat_server.do_send(SendComment {
 +    op: UserOperation::CreateComment,
 +    comment: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(create, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
index 9c0d146fbdceb19c2bcf832c1945883c63b769b3,0000000000000000000000000000000000000000..4b072ebdd3e3eebe03fd18ddd294742a6dbf0dd8
mode 100644,000000..100644
--- /dev/null
@@@ -1,222 -1,0 +1,224 @@@
-   apub::inbox::
-   shared_inbox::{get_user_from_activity, receive_unhandled_activity},
 +use crate::{
 +  api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
- use activitystreams_new::{activity::Delete, object::Note, prelude::*};
 +  apub::{
 +    fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
++    inbox::shared_inbox::{
++      announce_if_community_is_local,
++      get_user_from_activity,
++      receive_unhandled_activity,
++    },
 +    ActorType,
 +    FromApub,
 +    GroupExt,
 +    PageExt,
 +  },
 +  blocking,
 +  routes::ChatServerParam,
 +  websocket::{
 +    server::{SendComment, SendCommunityRoomMessage, SendPost},
 +    UserOperation,
 +  },
 +  DbPool,
 +  LemmyError,
 +};
- use activitystreams_new::base::AnyBase;
- use crate::apub::inbox::shared_inbox::announce_if_community_is_local;
++use activitystreams_new::{activity::Delete, base::AnyBase, object::Note, prelude::*};
 +use actix_web::{client::Client, HttpResponse};
 +use lemmy_db::{
 +  comment::{Comment, CommentForm},
 +  comment_view::CommentView,
 +  community::{Community, CommunityForm},
 +  community_view::CommunityView,
 +  naive_now,
 +  post::{Post, PostForm},
 +  post_view::PostView,
 +  Crud,
 +};
 +
 +pub async fn receive_delete(
 +  activity: AnyBase,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let delete = Delete::from_any_base(activity)?.unwrap();
 +  match delete.object().as_single_kind_str() {
 +    Some("Page") => receive_delete_post(delete, client, pool, chat_server).await,
 +    Some("Note") => receive_delete_comment(delete, client, pool, chat_server).await,
 +    Some("Group") => receive_delete_community(delete, client, pool, chat_server).await,
 +    _ => receive_unhandled_activity(delete),
 +  }
 +}
 +
 +async fn receive_delete_post(
 +  delete: Delete,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let user = get_user_from_activity(&delete, client, pool).await?;
 +  let page = PageExt::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let post_ap_id = PostForm::from_apub(&page, client, pool, &user.actor_id()?)
 +    .await?
 +    .get_ap_id()?;
 +
 +  let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
 +
 +  let post_form = PostForm {
 +    name: post.name.to_owned(),
 +    url: post.url.to_owned(),
 +    body: post.body.to_owned(),
 +    creator_id: post.creator_id.to_owned(),
 +    community_id: post.community_id,
 +    removed: None,
 +    deleted: Some(true),
 +    nsfw: post.nsfw,
 +    locked: None,
 +    stickied: None,
 +    updated: Some(naive_now()),
 +    embed_title: post.embed_title,
 +    embed_description: post.embed_description,
 +    embed_html: post.embed_html,
 +    thumbnail_url: post.thumbnail_url,
 +    ap_id: post.ap_id,
 +    local: post.local,
 +    published: None,
 +  };
 +  let post_id = post.id;
 +  blocking(pool, move |conn| Post::update(conn, post_id, &post_form)).await??;
 +
 +  // Refetch the view
 +  let post_id = post.id;
 +  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::EditPost,
 +    post: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(delete, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_delete_comment(
 +  delete: Delete,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let user = get_user_from_activity(&delete, client, pool).await?;
 +  let note = Note::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let comment_ap_id = CommentForm::from_apub(&note, client, pool, &user.actor_id()?)
 +    .await?
 +    .get_ap_id()?;
 +
 +  let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
 +
 +  let comment_form = CommentForm {
 +    content: comment.content.to_owned(),
 +    parent_id: comment.parent_id,
 +    post_id: comment.post_id,
 +    creator_id: comment.creator_id,
 +    removed: None,
 +    deleted: Some(true),
 +    read: None,
 +    published: None,
 +    updated: Some(naive_now()),
 +    ap_id: comment.ap_id,
 +    local: comment.local,
 +  };
 +  let comment_id = comment.id;
 +  blocking(pool, move |conn| {
 +    Comment::update(conn, comment_id, &comment_form)
 +  })
 +  .await??;
 +
 +  // Refetch the view
 +  let comment_id = comment.id;
 +  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,
 +  };
 +
 +  chat_server.do_send(SendComment {
 +    op: UserOperation::EditComment,
 +    comment: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(delete, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_delete_community(
 +  delete: Delete,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let group = GroupExt::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap();
 +  let user = get_user_from_activity(&delete, client, pool).await?;
 +
 +  let community_actor_id = CommunityForm::from_apub(&group, client, pool, &user.actor_id()?)
 +    .await?
 +    .actor_id;
 +
 +  let community = blocking(pool, move |conn| {
 +    Community::read_from_actor_id(conn, &community_actor_id)
 +  })
 +  .await??;
 +
 +  let community_form = CommunityForm {
 +    name: community.name.to_owned(),
 +    title: community.title.to_owned(),
 +    description: community.description.to_owned(),
 +    category_id: community.category_id, // Note: need to keep this due to foreign key constraint
 +    creator_id: community.creator_id,   // Note: need to keep this due to foreign key constraint
 +    removed: None,
 +    published: None,
 +    updated: Some(naive_now()),
 +    deleted: Some(true),
 +    nsfw: community.nsfw,
 +    actor_id: community.actor_id,
 +    local: community.local,
 +    private_key: community.private_key,
 +    public_key: community.public_key,
 +    last_refreshed_at: None,
 +  };
 +
 +  let community_id = community.id;
 +  blocking(pool, move |conn| {
 +    Community::update(conn, community_id, &community_form)
 +  })
 +  .await??;
 +
 +  let community_id = community.id;
 +  let res = CommunityResponse {
 +    community: blocking(pool, move |conn| {
 +      CommunityView::read(conn, community_id, None)
 +    })
 +    .await??,
 +  };
 +
 +  let community_id = res.community.id;
 +
 +  chat_server.do_send(SendCommunityRoomMessage {
 +    op: UserOperation::EditCommunity,
 +    response: res,
 +    community_id,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(delete, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
index 2b887c55eae60a414bef6f2c20333b85854fef38,0000000000000000000000000000000000000000..94790220c98230f6c7d716cf6a05698f65cd0f22
mode 100644,000000..100644
--- /dev/null
@@@ -1,132 -1,0 +1,135 @@@
-   apub::inbox::shared_inbox::{get_user_from_activity, receive_unhandled_activity},
 +use crate::{
 +  api::{comment::CommentResponse, post::PostResponse},
- use activitystreams_new::{activity::Dislike, object::Note, prelude::*};
 +  apub::{
 +    fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
++    inbox::shared_inbox::{
++      announce_if_community_is_local,
++      get_user_from_activity,
++      receive_unhandled_activity,
++    },
 +    ActorType,
 +    FromApub,
 +    PageExt,
 +  },
 +  blocking,
 +  routes::ChatServerParam,
 +  websocket::{
 +    server::{SendComment, SendPost},
 +    UserOperation,
 +  },
 +  DbPool,
 +  LemmyError,
 +};
- use activitystreams_new::base::AnyBase;
- use crate::apub::inbox::shared_inbox::announce_if_community_is_local;
++use activitystreams_new::{activity::Dislike, base::AnyBase, object::Note, prelude::*};
 +use actix_web::{client::Client, HttpResponse};
 +use lemmy_db::{
 +  comment::{CommentForm, CommentLike, CommentLikeForm},
 +  comment_view::CommentView,
 +  post::{PostForm, PostLike, PostLikeForm},
 +  post_view::PostView,
 +  Likeable,
 +};
 +
 +pub async fn receive_dislike(
 +  activity: AnyBase,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let dislike = Dislike::from_any_base(activity)?.unwrap();
 +  match dislike.object().as_single_kind_str() {
 +    Some("Page") => receive_dislike_post(dislike, client, pool, chat_server).await,
 +    Some("Note") => receive_dislike_comment(dislike, client, pool, chat_server).await,
 +    _ => receive_unhandled_activity(dislike),
 +  }
 +}
 +
 +async fn receive_dislike_post(
 +  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().unwrap())?.unwrap();
 +
 +  let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
 +
 +  let post_id = get_or_fetch_and_insert_remote_post(&post.get_ap_id()?, client, pool)
 +    .await?
 +    .id;
 +
 +  let like_form = PostLikeForm {
 +    post_id,
 +    user_id: user.id,
 +    score: -1,
 +  };
 +  blocking(pool, move |conn| {
 +    PostLike::remove(conn, &like_form)?;
 +    PostLike::like(conn, &like_form)
 +  })
 +  .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(dislike, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_dislike_comment(
 +  dislike: Dislike,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let note = Note::from_any_base(dislike.object().to_owned().one().unwrap())?.unwrap();
 +  let user = get_user_from_activity(&dislike, client, pool).await?;
 +
 +  let comment = CommentForm::from_apub(&note, client, pool, &user.actor_id()?).await?;
 +
 +  let comment_id = get_or_fetch_and_insert_remote_comment(&comment.get_ap_id()?, client, pool)
 +    .await?
 +    .id;
 +
 +  let like_form = CommentLikeForm {
 +    comment_id,
 +    post_id: comment.post_id,
 +    user_id: user.id,
 +    score: -1,
 +  };
 +  blocking(pool, move |conn| {
 +    CommentLike::remove(conn, &like_form)?;
 +    CommentLike::like(conn, &like_form)
 +  })
 +  .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,
 +  };
 +
 +  chat_server.do_send(SendComment {
 +    op: UserOperation::CreateCommentLike,
 +    comment: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(dislike, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
index 51a7d0333e07468598f864219bd372be57d62bc2,0000000000000000000000000000000000000000..1df20a0563e391d23fb7e071774c60fcdd83afbf
mode 100644,000000..100644
--- /dev/null
@@@ -1,132 -1,0 +1,135 @@@
-   apub::inbox::shared_inbox::{get_user_from_activity, receive_unhandled_activity},
 +use crate::{
 +  api::{comment::CommentResponse, post::PostResponse},
- use activitystreams_new::{activity::Like, object::Note, prelude::*};
 +  apub::{
 +    fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
++    inbox::shared_inbox::{
++      announce_if_community_is_local,
++      get_user_from_activity,
++      receive_unhandled_activity,
++    },
 +    ActorType,
 +    FromApub,
 +    PageExt,
 +  },
 +  blocking,
 +  routes::ChatServerParam,
 +  websocket::{
 +    server::{SendComment, SendPost},
 +    UserOperation,
 +  },
 +  DbPool,
 +  LemmyError,
 +};
- use activitystreams_new::base::AnyBase;
- use crate::apub::inbox::shared_inbox::announce_if_community_is_local;
++use activitystreams_new::{activity::Like, base::AnyBase, object::Note, prelude::*};
 +use actix_web::{client::Client, HttpResponse};
 +use lemmy_db::{
 +  comment::{CommentForm, CommentLike, CommentLikeForm},
 +  comment_view::CommentView,
 +  post::{PostForm, PostLike, PostLikeForm},
 +  post_view::PostView,
 +  Likeable,
 +};
 +
 +pub async fn receive_like(
 +  activity: AnyBase,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let like = Like::from_any_base(activity)?.unwrap();
 +  match like.object().as_single_kind_str() {
 +    Some("Page") => receive_like_post(like, client, pool, chat_server).await,
 +    Some("Note") => receive_like_comment(like, client, pool, chat_server).await,
 +    _ => receive_unhandled_activity(like),
 +  }
 +}
 +
 +async fn receive_like_post(
 +  like: Like,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let user = get_user_from_activity(&like, client, pool).await?;
 +  let page = PageExt::from_any_base(like.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
 +
 +  let post_id = get_or_fetch_and_insert_remote_post(&post.get_ap_id()?, client, pool)
 +    .await?
 +    .id;
 +
 +  let like_form = PostLikeForm {
 +    post_id,
 +    user_id: user.id,
 +    score: 1,
 +  };
 +  blocking(pool, move |conn| {
 +    PostLike::remove(conn, &like_form)?;
 +    PostLike::like(conn, &like_form)
 +  })
 +  .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(like, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_like_comment(
 +  like: Like,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let note = Note::from_any_base(like.object().to_owned().one().unwrap())?.unwrap();
 +  let user = get_user_from_activity(&like, client, pool).await?;
 +
 +  let comment = CommentForm::from_apub(&note, client, pool, &user.actor_id()?).await?;
 +
 +  let comment_id = get_or_fetch_and_insert_remote_comment(&comment.get_ap_id()?, client, pool)
 +    .await?
 +    .id;
 +
 +  let like_form = CommentLikeForm {
 +    comment_id,
 +    post_id: comment.post_id,
 +    user_id: user.id,
 +    score: 1,
 +  };
 +  blocking(pool, move |conn| {
 +    CommentLike::remove(conn, &like_form)?;
 +    CommentLike::like(conn, &like_form)
 +  })
 +  .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,
 +  };
 +
 +  chat_server.do_send(SendComment {
 +    op: UserOperation::CreateCommentLike,
 +    comment: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(like, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
index a056b898e0416ae48dae2b9ae3dcfbe03101591a,0000000000000000000000000000000000000000..cb2a1292b5d1f87eef20dae1ecc2d48809779b39
mode 100644,000000..100644
--- /dev/null
@@@ -1,221 -1,0 +1,224 @@@
-   apub::inbox::shared_inbox::{get_user_from_activity, receive_unhandled_activity},
 +use crate::{
 +  api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
- use activitystreams_new::{activity::Remove, object::Note, prelude::*};
 +  apub::{
 +    fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
++    inbox::shared_inbox::{
++      announce_if_community_is_local,
++      get_user_from_activity,
++      receive_unhandled_activity,
++    },
 +    ActorType,
 +    FromApub,
 +    GroupExt,
 +    PageExt,
 +  },
 +  blocking,
 +  routes::ChatServerParam,
 +  websocket::{
 +    server::{SendComment, SendCommunityRoomMessage, SendPost},
 +    UserOperation,
 +  },
 +  DbPool,
 +  LemmyError,
 +};
- use activitystreams_new::base::AnyBase;
- use crate::apub::inbox::shared_inbox::announce_if_community_is_local;
++use activitystreams_new::{activity::Remove, base::AnyBase, object::Note, prelude::*};
 +use actix_web::{client::Client, HttpResponse};
 +use lemmy_db::{
 +  comment::{Comment, CommentForm},
 +  comment_view::CommentView,
 +  community::{Community, CommunityForm},
 +  community_view::CommunityView,
 +  naive_now,
 +  post::{Post, PostForm},
 +  post_view::PostView,
 +  Crud,
 +};
 +
 +pub async fn receive_remove(
 +  activity: AnyBase,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let remove = Remove::from_any_base(activity)?.unwrap();
 +  match remove.object().as_single_kind_str() {
 +    Some("Page") => receive_remove_post(remove, client, pool, chat_server).await,
 +    Some("Note") => receive_remove_comment(remove, client, pool, chat_server).await,
 +    Some("Group") => receive_remove_community(remove, client, pool, chat_server).await,
 +    _ => receive_unhandled_activity(remove),
 +  }
 +}
 +
 +async fn receive_remove_post(
 +  remove: Remove,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let mod_ = get_user_from_activity(&remove, client, pool).await?;
 +  let page = PageExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let post_ap_id = PostForm::from_apub(&page, client, pool, &mod_.actor_id()?)
 +    .await?
 +    .get_ap_id()?;
 +
 +  let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
 +
 +  let post_form = PostForm {
 +    name: post.name.to_owned(),
 +    url: post.url.to_owned(),
 +    body: post.body.to_owned(),
 +    creator_id: post.creator_id.to_owned(),
 +    community_id: post.community_id,
 +    removed: Some(true),
 +    deleted: None,
 +    nsfw: post.nsfw,
 +    locked: None,
 +    stickied: None,
 +    updated: Some(naive_now()),
 +    embed_title: post.embed_title,
 +    embed_description: post.embed_description,
 +    embed_html: post.embed_html,
 +    thumbnail_url: post.thumbnail_url,
 +    ap_id: post.ap_id,
 +    local: post.local,
 +    published: None,
 +  };
 +  let post_id = post.id;
 +  blocking(pool, move |conn| Post::update(conn, post_id, &post_form)).await??;
 +
 +  // Refetch the view
 +  let post_id = post.id;
 +  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::EditPost,
 +    post: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(remove, &mod_, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_remove_comment(
 +  remove: Remove,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let mod_ = get_user_from_activity(&remove, client, pool).await?;
 +  let note = Note::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let comment_ap_id = CommentForm::from_apub(&note, client, pool, &mod_.actor_id()?)
 +    .await?
 +    .get_ap_id()?;
 +
 +  let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
 +
 +  let comment_form = CommentForm {
 +    content: comment.content.to_owned(),
 +    parent_id: comment.parent_id,
 +    post_id: comment.post_id,
 +    creator_id: comment.creator_id,
 +    removed: Some(true),
 +    deleted: None,
 +    read: None,
 +    published: None,
 +    updated: Some(naive_now()),
 +    ap_id: comment.ap_id,
 +    local: comment.local,
 +  };
 +  let comment_id = comment.id;
 +  blocking(pool, move |conn| {
 +    Comment::update(conn, comment_id, &comment_form)
 +  })
 +  .await??;
 +
 +  // Refetch the view
 +  let comment_id = comment.id;
 +  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,
 +  };
 +
 +  chat_server.do_send(SendComment {
 +    op: UserOperation::EditComment,
 +    comment: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(remove, &mod_, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_remove_community(
 +  remove: Remove,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let mod_ = get_user_from_activity(&remove, client, pool).await?;
 +  let group = GroupExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let community_actor_id = CommunityForm::from_apub(&group, client, pool, &mod_.actor_id()?)
 +    .await?
 +    .actor_id;
 +
 +  let community = blocking(pool, move |conn| {
 +    Community::read_from_actor_id(conn, &community_actor_id)
 +  })
 +  .await??;
 +
 +  let community_form = CommunityForm {
 +    name: community.name.to_owned(),
 +    title: community.title.to_owned(),
 +    description: community.description.to_owned(),
 +    category_id: community.category_id, // Note: need to keep this due to foreign key constraint
 +    creator_id: community.creator_id,   // Note: need to keep this due to foreign key constraint
 +    removed: Some(true),
 +    published: None,
 +    updated: Some(naive_now()),
 +    deleted: None,
 +    nsfw: community.nsfw,
 +    actor_id: community.actor_id,
 +    local: community.local,
 +    private_key: community.private_key,
 +    public_key: community.public_key,
 +    last_refreshed_at: None,
 +  };
 +
 +  let community_id = community.id;
 +  blocking(pool, move |conn| {
 +    Community::update(conn, community_id, &community_form)
 +  })
 +  .await??;
 +
 +  let community_id = community.id;
 +  let res = CommunityResponse {
 +    community: blocking(pool, move |conn| {
 +      CommunityView::read(conn, community_id, None)
 +    })
 +    .await??,
 +  };
 +
 +  let community_id = res.community.id;
 +
 +  chat_server.do_send(SendCommunityRoomMessage {
 +    op: UserOperation::EditCommunity,
 +    response: res,
 +    community_id,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(remove, &mod_, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
index a084722617f0d36b16c13d2c152e27934956c450,0000000000000000000000000000000000000000..3c5bdb68b4b1170c35b841f4acb766ec64a51a68
mode 100644,000000..100644
--- /dev/null
@@@ -1,550 -1,0 +1,552 @@@
-   apub::inbox::shared_inbox::{get_user_from_activity, receive_unhandled_activity},
 +use crate::{
 +  api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
- use activitystreams_new::{activity::*, object::Note, prelude::*};
 +  apub::{
 +    fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
++    inbox::shared_inbox::{
++      announce_if_community_is_local,
++      get_user_from_activity,
++      receive_unhandled_activity,
++    },
 +    ActorType,
 +    FromApub,
 +    GroupExt,
 +    PageExt,
 +  },
 +  blocking,
 +  routes::ChatServerParam,
 +  websocket::{
 +    server::{SendComment, SendCommunityRoomMessage, SendPost},
 +    UserOperation,
 +  },
 +  DbPool,
 +  LemmyError,
 +};
- use activitystreams_new::base::AnyBase;
- use crate::apub::inbox::shared_inbox::announce_if_community_is_local;
++use activitystreams_new::{activity::*, base::AnyBase, object::Note, prelude::*};
 +use actix_web::{client::Client, HttpResponse};
 +use lemmy_db::{
 +  comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
 +  comment_view::CommentView,
 +  community::{Community, CommunityForm},
 +  community_view::CommunityView,
 +  naive_now,
 +  post::{Post, PostForm, PostLike, PostLikeForm},
 +  post_view::PostView,
 +  Crud,
 +  Likeable,
 +};
-   client: &Client,
-   pool: &DbPool,
-   chat_server: ChatServerParam,
 +
 +pub async fn receive_undo(
 +  activity: AnyBase,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let undo = Undo::from_any_base(activity)?.unwrap();
 +  match undo.object().as_single_kind_str() {
 +    Some("Delete") => receive_undo_delete(undo, client, pool, chat_server).await,
 +    Some("Remove") => receive_undo_remove(undo, client, pool, chat_server).await,
 +    Some("Like") => receive_undo_like(undo, client, pool, chat_server).await,
 +    Some("Dislike") => receive_undo_dislike(undo, client, pool, chat_server).await,
 +    // TODO: handle undo_dislike?
 +    _ => receive_unhandled_activity(undo),
 +  }
 +}
 +
 +async fn receive_undo_delete(
 +  undo: Undo,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let delete = Delete::from_any_base(undo.object().to_owned().one().unwrap())?.unwrap();
 +  let type_ = delete.object().as_single_kind_str().unwrap();
 +  match type_ {
 +    "Note" => receive_undo_delete_comment(undo, &delete, client, pool, chat_server).await,
 +    "Page" => receive_undo_delete_post(undo, &delete, client, pool, chat_server).await,
 +    "Group" => receive_undo_delete_community(undo, &delete, client, pool, chat_server).await,
 +    d => Err(format_err!("Undo Delete type {} not supported", d).into()),
 +  }
 +}
 +
 +async fn receive_undo_remove(
 +  undo: Undo,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let remove = Remove::from_any_base(undo.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let type_ = remove.object().as_single_kind_str().unwrap();
 +  match type_ {
 +    "Note" => receive_undo_remove_comment(undo, &remove, client, pool, chat_server).await,
 +    "Page" => receive_undo_remove_post(undo, &remove, client, pool, chat_server).await,
 +    "Group" => receive_undo_remove_community(undo, &remove, client, pool, chat_server).await,
 +    d => Err(format_err!("Undo Delete type {} not supported", d).into()),
 +  }
 +}
 +
 +async fn receive_undo_like(
 +  undo: Undo,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let like = Like::from_any_base(undo.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let type_ = like.object().as_single_kind_str().unwrap();
 +  match type_ {
 +    "Note" => receive_undo_like_comment(undo, &like, client, pool, chat_server).await,
 +    "Page" => receive_undo_like_post(undo, &like, client, pool, chat_server).await,
 +    d => Err(format_err!("Undo Delete type {} not supported", d).into()),
 +  }
 +}
 +
 +async fn receive_undo_dislike(
 +  undo: Undo,
-   match type_ {
-     // TODO: handle dislike
-     d => Err(format_err!("Undo Delete type {} not supported", d).into()),
-   }
++  _client: &Client,
++  _pool: &DbPool,
++  _chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let dislike = Dislike::from_any_base(undo.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let type_ = dislike.object().as_single_kind_str().unwrap();
++  Err(format_err!("Undo Delete type {} not supported", type_).into())
 +}
 +
 +async fn receive_undo_delete_comment(
 +  undo: Undo,
 +  delete: &Delete,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let user = get_user_from_activity(delete, client, pool).await?;
 +  let note = Note::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let comment_ap_id = CommentForm::from_apub(&note, client, pool, &user.actor_id()?)
 +    .await?
 +    .get_ap_id()?;
 +
 +  let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
 +
 +  let comment_form = CommentForm {
 +    content: comment.content.to_owned(),
 +    parent_id: comment.parent_id,
 +    post_id: comment.post_id,
 +    creator_id: comment.creator_id,
 +    removed: None,
 +    deleted: Some(false),
 +    read: None,
 +    published: None,
 +    updated: Some(naive_now()),
 +    ap_id: comment.ap_id,
 +    local: comment.local,
 +  };
 +  let comment_id = comment.id;
 +  blocking(pool, move |conn| {
 +    Comment::update(conn, comment_id, &comment_form)
 +  })
 +  .await??;
 +
 +  // Refetch the view
 +  let comment_id = comment.id;
 +  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,
 +  };
 +
 +  chat_server.do_send(SendComment {
 +    op: UserOperation::EditComment,
 +    comment: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(undo, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_undo_remove_comment(
 +  undo: Undo,
 +  remove: &Remove,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let mod_ = get_user_from_activity(remove, client, pool).await?;
 +  let note = Note::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let comment_ap_id = CommentForm::from_apub(&note, client, pool, &mod_.actor_id()?)
 +    .await?
 +    .get_ap_id()?;
 +
 +  let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
 +
 +  let comment_form = CommentForm {
 +    content: comment.content.to_owned(),
 +    parent_id: comment.parent_id,
 +    post_id: comment.post_id,
 +    creator_id: comment.creator_id,
 +    removed: Some(false),
 +    deleted: None,
 +    read: None,
 +    published: None,
 +    updated: Some(naive_now()),
 +    ap_id: comment.ap_id,
 +    local: comment.local,
 +  };
 +  let comment_id = comment.id;
 +  blocking(pool, move |conn| {
 +    Comment::update(conn, comment_id, &comment_form)
 +  })
 +  .await??;
 +
 +  // Refetch the view
 +  let comment_id = comment.id;
 +  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,
 +  };
 +
 +  chat_server.do_send(SendComment {
 +    op: UserOperation::EditComment,
 +    comment: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(undo, &mod_, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_undo_delete_post(
 +  undo: Undo,
 +  delete: &Delete,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let user = get_user_from_activity(delete, client, pool).await?;
 +  let page = PageExt::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let post_ap_id = PostForm::from_apub(&page, client, pool, &user.actor_id()?)
 +    .await?
 +    .get_ap_id()?;
 +
 +  let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
 +
 +  let post_form = PostForm {
 +    name: post.name.to_owned(),
 +    url: post.url.to_owned(),
 +    body: post.body.to_owned(),
 +    creator_id: post.creator_id.to_owned(),
 +    community_id: post.community_id,
 +    removed: None,
 +    deleted: Some(false),
 +    nsfw: post.nsfw,
 +    locked: None,
 +    stickied: None,
 +    updated: Some(naive_now()),
 +    embed_title: post.embed_title,
 +    embed_description: post.embed_description,
 +    embed_html: post.embed_html,
 +    thumbnail_url: post.thumbnail_url,
 +    ap_id: post.ap_id,
 +    local: post.local,
 +    published: None,
 +  };
 +  let post_id = post.id;
 +  blocking(pool, move |conn| Post::update(conn, post_id, &post_form)).await??;
 +
 +  // Refetch the view
 +  let post_id = post.id;
 +  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::EditPost,
 +    post: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(undo, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_undo_remove_post(
 +  undo: Undo,
 +  remove: &Remove,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let mod_ = get_user_from_activity(remove, client, pool).await?;
 +  let page = PageExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let post_ap_id = PostForm::from_apub(&page, client, pool, &mod_.actor_id()?)
 +    .await?
 +    .get_ap_id()?;
 +
 +  let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
 +
 +  let post_form = PostForm {
 +    name: post.name.to_owned(),
 +    url: post.url.to_owned(),
 +    body: post.body.to_owned(),
 +    creator_id: post.creator_id.to_owned(),
 +    community_id: post.community_id,
 +    removed: Some(false),
 +    deleted: None,
 +    nsfw: post.nsfw,
 +    locked: None,
 +    stickied: None,
 +    updated: Some(naive_now()),
 +    embed_title: post.embed_title,
 +    embed_description: post.embed_description,
 +    embed_html: post.embed_html,
 +    thumbnail_url: post.thumbnail_url,
 +    ap_id: post.ap_id,
 +    local: post.local,
 +    published: None,
 +  };
 +  let post_id = post.id;
 +  blocking(pool, move |conn| Post::update(conn, post_id, &post_form)).await??;
 +
 +  // Refetch the view
 +  let post_id = post.id;
 +  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::EditPost,
 +    post: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(undo, &mod_, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_undo_delete_community(
 +  undo: Undo,
 +  delete: &Delete,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let user = get_user_from_activity(delete, client, pool).await?;
 +  let group = GroupExt::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let community_actor_id = CommunityForm::from_apub(&group, client, pool, &user.actor_id()?)
 +    .await?
 +    .actor_id;
 +
 +  let community = blocking(pool, move |conn| {
 +    Community::read_from_actor_id(conn, &community_actor_id)
 +  })
 +  .await??;
 +
 +  let community_form = CommunityForm {
 +    name: community.name.to_owned(),
 +    title: community.title.to_owned(),
 +    description: community.description.to_owned(),
 +    category_id: community.category_id, // Note: need to keep this due to foreign key constraint
 +    creator_id: community.creator_id,   // Note: need to keep this due to foreign key constraint
 +    removed: None,
 +    published: None,
 +    updated: Some(naive_now()),
 +    deleted: Some(false),
 +    nsfw: community.nsfw,
 +    actor_id: community.actor_id,
 +    local: community.local,
 +    private_key: community.private_key,
 +    public_key: community.public_key,
 +    last_refreshed_at: None,
 +  };
 +
 +  let community_id = community.id;
 +  blocking(pool, move |conn| {
 +    Community::update(conn, community_id, &community_form)
 +  })
 +  .await??;
 +
 +  let community_id = community.id;
 +  let res = CommunityResponse {
 +    community: blocking(pool, move |conn| {
 +      CommunityView::read(conn, community_id, None)
 +    })
 +    .await??,
 +  };
 +
 +  let community_id = res.community.id;
 +
 +  chat_server.do_send(SendCommunityRoomMessage {
 +    op: UserOperation::EditCommunity,
 +    response: res,
 +    community_id,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(undo, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_undo_remove_community(
 +  undo: Undo,
 +  remove: &Remove,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let mod_ = get_user_from_activity(remove, client, pool).await?;
 +  let group = GroupExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let community_actor_id = CommunityForm::from_apub(&group, client, pool, &mod_.actor_id()?)
 +    .await?
 +    .actor_id;
 +
 +  let community = blocking(pool, move |conn| {
 +    Community::read_from_actor_id(conn, &community_actor_id)
 +  })
 +  .await??;
 +
 +  let community_form = CommunityForm {
 +    name: community.name.to_owned(),
 +    title: community.title.to_owned(),
 +    description: community.description.to_owned(),
 +    category_id: community.category_id, // Note: need to keep this due to foreign key constraint
 +    creator_id: community.creator_id,   // Note: need to keep this due to foreign key constraint
 +    removed: Some(false),
 +    published: None,
 +    updated: Some(naive_now()),
 +    deleted: None,
 +    nsfw: community.nsfw,
 +    actor_id: community.actor_id,
 +    local: community.local,
 +    private_key: community.private_key,
 +    public_key: community.public_key,
 +    last_refreshed_at: None,
 +  };
 +
 +  let community_id = community.id;
 +  blocking(pool, move |conn| {
 +    Community::update(conn, community_id, &community_form)
 +  })
 +  .await??;
 +
 +  let community_id = community.id;
 +  let res = CommunityResponse {
 +    community: blocking(pool, move |conn| {
 +      CommunityView::read(conn, community_id, None)
 +    })
 +    .await??,
 +  };
 +
 +  let community_id = res.community.id;
 +
 +  chat_server.do_send(SendCommunityRoomMessage {
 +    op: UserOperation::EditCommunity,
 +    response: res,
 +    community_id,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(undo, &mod_, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_undo_like_comment(
 +  undo: Undo,
 +  like: &Like,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let user = get_user_from_activity(like, client, pool).await?;
 +  let note = Note::from_any_base(like.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let comment = CommentForm::from_apub(&note, client, pool, &user.actor_id()?).await?;
 +
 +  let comment_id = get_or_fetch_and_insert_remote_comment(&comment.get_ap_id()?, client, pool)
 +    .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??;
 +
 +  // 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,
 +  };
 +
 +  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_like_post(
 +  undo: Undo,
 +  like: &Like,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let user = get_user_from_activity(like, client, pool).await?;
 +  let page = PageExt::from_any_base(like.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
 +
 +  let post_id = get_or_fetch_and_insert_remote_post(&post.get_ap_id()?, client, pool)
 +    .await?
 +    .id;
 +
 +  let like_form = PostLikeForm {
 +    post_id,
 +    user_id: user.id,
 +    score: 1,
 +  };
 +  blocking(pool, move |conn| PostLike::remove(conn, &like_form)).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())
 +}
index 96e0efac6e2b23208631451792fc470a13630538,0000000000000000000000000000000000000000..f46c7ff78cc7f434bbf02a590afaccb9443b72bf
mode 100644,000000..100644
--- /dev/null
@@@ -1,128 -1,0 +1,128 @@@
-   apub::inbox::shared_inbox::{get_user_from_activity, receive_unhandled_activity},
 +use crate::{
 +  api::{
 +    comment::{send_local_notifs, CommentResponse},
 +    post::PostResponse,
 +  },
- use activitystreams_new::{
-   activity::{Update},
-   object::Note,
-   prelude::*,
- };
 +  apub::{
 +    fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
++    inbox::shared_inbox::{
++      announce_if_community_is_local,
++      get_user_from_activity,
++      receive_unhandled_activity,
++    },
 +    ActorType,
 +    FromApub,
 +    PageExt,
 +  },
 +  blocking,
 +  routes::ChatServerParam,
 +  websocket::{
 +    server::{SendComment, SendPost},
 +    UserOperation,
 +  },
 +  DbPool,
 +  LemmyError,
 +};
- use activitystreams_new::base::AnyBase;
- use crate::apub::inbox::shared_inbox::announce_if_community_is_local;
++use activitystreams_new::{activity::Update, base::AnyBase, object::Note, prelude::*};
 +use actix_web::{client::Client, HttpResponse};
 +use lemmy_db::{
 +  comment::{Comment, CommentForm},
 +  comment_view::CommentView,
 +  post::{Post, PostForm},
 +  post_view::PostView,
 +  Crud,
 +};
 +use lemmy_utils::scrape_text_for_mentions;
-   let recipient_ids = send_local_notifs(mentions, updated_comment, &user, post, pool).await?;
 +
 +pub async fn receive_update(
 +  activity: AnyBase,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let update = Update::from_any_base(activity)?.unwrap();
 +  match update.object().as_single_kind_str() {
 +    Some("Page") => receive_update_post(update, client, pool, chat_server).await,
 +    Some("Note") => receive_update_comment(update, client, pool, chat_server).await,
 +    _ => receive_unhandled_activity(update),
 +  }
 +}
 +
 +async fn receive_update_post(
 +  update: Update,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let user = get_user_from_activity(&update, client, pool).await?;
 +  let page = PageExt::from_any_base(update.object().to_owned().one().unwrap())?.unwrap();
 +
 +  let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
 +
 +  let post_id = get_or_fetch_and_insert_remote_post(&post.get_ap_id()?, client, pool)
 +    .await?
 +    .id;
 +
 +  blocking(pool, move |conn| Post::update(conn, post_id, &post)).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::EditPost,
 +    post: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(update, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
 +
 +async fn receive_update_comment(
 +  update: Update,
 +  client: &Client,
 +  pool: &DbPool,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let note = Note::from_any_base(update.object().to_owned().one().unwrap())?.unwrap();
 +  let user = get_user_from_activity(&update, client, pool).await?;
 +
 +  let comment = CommentForm::from_apub(&note, client, pool, &user.actor_id()?).await?;
 +
 +  let comment_id = get_or_fetch_and_insert_remote_comment(&comment.get_ap_id()?, client, pool)
 +    .await?
 +    .id;
 +
 +  let updated_comment = blocking(pool, move |conn| {
 +    Comment::update(conn, comment_id, &comment)
 +  })
 +  .await??;
 +
 +  let post_id = updated_comment.post_id;
 +  let post = blocking(pool, move |conn| Post::read(conn, post_id)).await??;
 +
 +  let mentions = scrape_text_for_mentions(&updated_comment.content);
++  let recipient_ids =
++    send_local_notifs(mentions, updated_comment, &user, post, pool, false).await?;
 +
 +  // Refetch the view
 +  let comment_view =
 +    blocking(pool, move |conn| CommentView::read(conn, comment_id, None)).await??;
 +
 +  let res = CommentResponse {
 +    comment: comment_view,
 +    recipient_ids,
++    form_id: None,
 +  };
 +
 +  chat_server.do_send(SendComment {
 +    op: UserOperation::EditComment,
 +    comment: res,
 +    my_id: None,
 +  });
 +
 +  announce_if_community_is_local(update, &user, client, pool).await?;
 +  Ok(HttpResponse::Ok().finish())
 +}
index d7b7b7433d2a886ff0d5ddd7e0a26addea1e9946,0000000000000000000000000000000000000000..b9db61fa83662381ed65d82bfcb58c790ec184a2
mode 100644,000000..100644
--- /dev/null
@@@ -1,4 -1,0 +1,4 @@@
- pub mod user_inbox;
 +pub mod activities;
 +pub mod community_inbox;
 +pub mod shared_inbox;
++pub mod user_inbox;
index 2a51d98ae9c715316ed3b142ec2e1a4577ad0228,0000000000000000000000000000000000000000..f406d83ac40953acd1431f993226dfdddba4e2fe
mode 100644,000000..100644
--- /dev/null
@@@ -1,136 -1,0 +1,135 @@@
-   base::{AsBase},
 +use crate::{
 +  apub::{
++    community::do_announce,
 +    extensions::signatures::verify,
 +    fetcher::{
 +      get_or_fetch_and_upsert_remote_actor,
++      get_or_fetch_and_upsert_remote_community,
 +      get_or_fetch_and_upsert_remote_user,
 +    },
 +    inbox::activities::{
 +      announce::receive_announce,
 +      create::receive_create,
 +      delete::receive_delete,
 +      dislike::receive_dislike,
 +      like::receive_like,
 +      remove::receive_remove,
 +      undo::receive_undo,
 +      update::receive_update,
 +    },
 +    insert_activity,
 +  },
 +  routes::{ChatServerParam, DbPoolParam},
 +  DbPool,
 +  LemmyError,
 +};
 +use activitystreams_new::{
 +  activity::{ActorAndObject, ActorAndObjectRef},
- use lemmy_db::{user::User_};
++  base::{AsBase, Extends},
++  object::AsObject,
 +  prelude::*,
 +};
 +use actix_web::{client::Client, web, HttpRequest, HttpResponse};
- use std::fmt::Debug;
- use crate::apub::fetcher::get_or_fetch_and_upsert_remote_community;
- use activitystreams_new::object::AsObject;
- use crate::apub::community::do_announce;
- use activitystreams_new::base::Extends;
++use lemmy_db::user::User_;
 +use log::debug;
-     ValidTypes::Announce => {
-       receive_announce(any_base, &client, &pool, chat_server).await
-     }
 +use serde::Serialize;
++use std::fmt::Debug;
 +
 +#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize)]
 +#[serde(rename_all = "PascalCase")]
 +pub enum ValidTypes {
 +  Create,
 +  Update,
 +  Like,
 +  Dislike,
 +  Delete,
 +  Undo,
 +  Remove,
 +  Announce,
 +}
 +
 +// TODO: this isnt entirely correct, cause some of these activities are not ActorAndObject,
 +//       but it might still work due to the anybase conversion
 +pub type AcceptedActivities = ActorAndObject<ValidTypes>;
 +
 +/// Handler for all incoming activities to user inboxes.
 +pub async fn shared_inbox(
 +  request: HttpRequest,
 +  input: web::Json<AcceptedActivities>,
 +  client: web::Data<Client>,
 +  pool: DbPoolParam,
 +  chat_server: ChatServerParam,
 +) -> Result<HttpResponse, LemmyError> {
 +  let activity = input.into_inner();
 +
 +  let json = serde_json::to_string(&activity)?;
 +  debug!("Shared inbox received activity: {}", json);
 +
 +  let sender = &activity.actor()?.to_owned().single_xsd_any_uri().unwrap();
 +
 +  // TODO: pass this actor in instead of using get_user_from_activity()
 +  let actor = get_or_fetch_and_upsert_remote_actor(sender, &client, &pool).await?;
 +  verify(&request, actor.as_ref())?;
 +
 +  insert_activity(actor.user_id(), activity.clone(), false, &pool).await?;
 +
 +  let any_base = activity.clone().into_any_base()?;
 +  let kind = activity.kind().unwrap();
 +  dbg!(kind);
 +  match kind {
- pub(in crate::apub::inbox) fn receive_unhandled_activity<A>(activity: A) -> Result<HttpResponse, LemmyError>
++    ValidTypes::Announce => receive_announce(any_base, &client, &pool, chat_server).await,
 +    ValidTypes::Create => receive_create(any_base, &client, &pool, chat_server).await,
 +    ValidTypes::Update => receive_update(any_base, &client, &pool, chat_server).await,
 +    ValidTypes::Like => receive_like(any_base, &client, &pool, chat_server).await,
 +    ValidTypes::Dislike => receive_dislike(any_base, &client, &pool, chat_server).await,
 +    ValidTypes::Remove => receive_remove(any_base, &client, &pool, chat_server).await,
 +    ValidTypes::Delete => receive_delete(any_base, &client, &pool, chat_server).await,
 +    ValidTypes::Undo => receive_undo(any_base, &client, &pool, chat_server).await,
 +  }
 +}
 +
-   where
-     T: AsBase<A> + ActorAndObjectRef,
++pub(in crate::apub::inbox) fn receive_unhandled_activity<A>(
++  activity: A,
++) -> Result<HttpResponse, LemmyError>
 +where
 +  A: Debug,
 +{
 +  debug!("received unhandled activity type: {:?}", activity);
 +  Ok(HttpResponse::NotImplemented().finish())
 +}
 +
 +pub(in crate::apub::inbox) async fn get_user_from_activity<T, A>(
 +  activity: &T,
 +  client: &Client,
 +  pool: &DbPool,
 +) -> Result<User_, LemmyError>
-   where
-     T: AsObject<Kind>,
-     T: Extends<Kind>,
-     Kind: Serialize,
-     <T as Extends<Kind>>::Error: From<serde_json::Error> + Send + Sync + 'static,
++where
++  T: AsBase<A> + ActorAndObjectRef,
 +{
 +  let actor = activity.actor()?;
 +  let user_uri = actor.as_single_xsd_any_uri().unwrap();
 +  get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await
 +}
 +
 +pub(in crate::apub::inbox) async fn announce_if_community_is_local<T, Kind>(
 +  activity: T,
 +  user: &User_,
 +  client: &Client,
 +  pool: &DbPool,
 +) -> Result<(), LemmyError>
++where
++  T: AsObject<Kind>,
++  T: Extends<Kind>,
++  Kind: Serialize,
++  <T as Extends<Kind>>::Error: From<serde_json::Error> + Send + Sync + 'static,
 +{
 +  let cc = activity.cc().unwrap();
 +  let cc = cc.as_many().unwrap();
 +  let community_uri = cc.first().unwrap().as_xsd_any_uri().unwrap();
 +  let community = get_or_fetch_and_upsert_remote_community(&community_uri, client, pool).await?;
 +
 +  if community.local {
 +    do_announce(activity.into_any_base()?, &community, &user, client, pool).await?;
 +  }
 +  Ok(())
 +}
Simple merge
index 2d12f99fd5d86f634943f315c3aa760679903aff,cd4c47803dbfbebfaee98da7f1f4cdc7aa505c15..93aaac1c1828b26f0f48714a13f9b49b79560e65
@@@ -1,11 -1,11 +1,9 @@@
  use crate::apub::{
    comment::get_apub_comment,
    community::*,
-   inbox::community_inbox::community_inbox,
 -  community_inbox::community_inbox,
++  inbox::{community_inbox::community_inbox, shared_inbox::shared_inbox, user_inbox::user_inbox},
    post::get_apub_post,
-   inbox::shared_inbox::shared_inbox,
 -  shared_inbox::shared_inbox,
    user::*,
-   inbox::user_inbox::user_inbox,
 -  user_inbox::user_inbox,
    APUB_JSON_CONTENT_TYPE,
  };
  use actix_web::*;
index 4554326daaa34de2af329a0cf6253d93a035cf49,9d6cbb89ac75f522c29120c80c19429170d3faad..eb86d8f88868e14dd4085be848627eac2caebf0b
@@@ -100,7 -110,7 +110,7 @@@ export class CreatePost extends Compone
          return lastLocation.split('/c/')[1];
        }
      }
--    return undefined;
++    return;
    }
  
    handlePostCreate(id: number) {