]> Untitled Git - lemmy.git/commitdiff
Take correct community uri in shared_inbox, rename fetch_remote* methods
authorFelix Ableitner <me@nutomic.com>
Wed, 29 Jul 2020 11:46:11 +0000 (13:46 +0200)
committerFelix Ableitner <me@nutomic.com>
Wed, 29 Jul 2020 11:46:11 +0000 (13:46 +0200)
19 files changed:
server/src/apub/activities.rs
server/src/apub/comment.rs
server/src/apub/community.rs
server/src/apub/fetcher.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/community_inbox.rs
server/src/apub/inbox/shared_inbox.rs
server/src/apub/inbox/user_inbox.rs
server/src/apub/mod.rs
server/src/apub/post.rs
server/src/apub/private_message.rs
server/src/apub/user.rs

index 9cc20af80f8844e297036cdcbfe234f665ce87b7..a622c691d4ede2982ab9e1656dd162075fe16ab0 100644 (file)
@@ -1,10 +1,14 @@
 use crate::{
   apub::{
-    community::do_announce, extensions::signatures::sign, insert_activity, is_apub_id_valid,
+    community::do_announce,
+    extensions::signatures::sign,
+    insert_activity,
+    is_apub_id_valid,
     ActorType,
   },
   request::retry_custom,
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::base::AnyBase;
 use actix_web::client::Client;
index 61a1d15e4ddf0c3a81209de1161b5a68f9ecbe9e..269e7fc25f58f695a7a88e155e08151c9cf5fb8c 100644 (file)
@@ -1,21 +1,36 @@
 use crate::{
   apub::{
     activities::{generate_activity_id, send_activity_to_community},
-    create_apub_response, create_apub_tombstone_response, create_tombstone, fetch_webfinger_url,
+    create_apub_response,
+    create_apub_tombstone_response,
+    create_tombstone,
+    fetch_webfinger_url,
     fetcher::{
-      get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post,
-      get_or_fetch_and_upsert_remote_user,
+      get_or_fetch_and_insert_comment,
+      get_or_fetch_and_insert_post,
+      get_or_fetch_and_upsert_user,
     },
-    ActorType, ApubLikeableType, ApubObjectType, FromApub, ToApub,
+    ActorType,
+    ApubLikeableType,
+    ApubObjectType,
+    FromApub,
+    ToApub,
   },
   blocking,
   routes::DbPoolParam,
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::{
   activity::{
     kind::{CreateType, DeleteType, DislikeType, LikeType, RemoveType, UndoType, UpdateType},
-    Create, Delete, Dislike, Like, Remove, Undo, Update,
+    Create,
+    Delete,
+    Dislike,
+    Like,
+    Remove,
+    Undo,
+    Update,
   },
   base::AnyBase,
   context,
@@ -124,7 +139,7 @@ impl FromApub for CommentForm {
       .as_single_xsd_any_uri()
       .unwrap();
 
-    let creator = get_or_fetch_and_upsert_remote_user(creator_actor_id, client, pool).await?;
+    let creator = get_or_fetch_and_upsert_user(creator_actor_id, client, pool).await?;
 
     let mut in_reply_tos = note
       .in_reply_to()
@@ -137,7 +152,7 @@ impl FromApub for CommentForm {
     let post_ap_id = in_reply_tos.next().unwrap();
 
     // This post, or the parent comment might not yet exist on this server yet, fetch them.
-    let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
+    let post = get_or_fetch_and_insert_post(&post_ap_id, client, pool).await?;
 
     // The 2nd item, if it exists, is the parent comment apub_id
     // For deeply nested comments, FromApub automatically gets called recursively
@@ -145,7 +160,7 @@ impl FromApub for CommentForm {
       Some(parent_comment_uri) => {
         let parent_comment_ap_id = &parent_comment_uri;
         let parent_comment =
-          get_or_fetch_and_insert_remote_comment(&parent_comment_ap_id, client, pool).await?;
+          get_or_fetch_and_insert_comment(&parent_comment_ap_id, client, pool).await?;
 
         Some(parent_comment.id)
       }
@@ -558,7 +573,7 @@ async fn collect_non_local_mentions_and_addresses(
       debug!("mention actor_id: {}", actor_id);
       addressed_ccs.push(actor_id.to_owned().to_string());
 
-      let mention_user = get_or_fetch_and_upsert_remote_user(&actor_id, client, pool).await?;
+      let mention_user = get_or_fetch_and_upsert_user(&actor_id, client, pool).await?;
       let shared_inbox = mention_user.get_shared_inbox_url();
 
       mention_inboxes.push(shared_inbox);
index 16d13711e7c177850fb0bbc07125f121a3354a47..b60059aa31c3cba3728df0702d5de99ed1620ef9 100644 (file)
@@ -1,20 +1,33 @@
 use crate::{
   apub::{
     activities::{generate_activity_id, send_activity},
-    create_apub_response, create_apub_tombstone_response, create_tombstone,
+    create_apub_response,
+    create_apub_tombstone_response,
+    create_tombstone,
     extensions::group_extensions::GroupExtension,
-    fetcher::get_or_fetch_and_upsert_remote_user,
-    get_shared_inbox, insert_activity, ActorType, FromApub, GroupExt, ToApub,
+    fetcher::get_or_fetch_and_upsert_user,
+    get_shared_inbox,
+    insert_activity,
+    ActorType,
+    FromApub,
+    GroupExt,
+    ToApub,
   },
   blocking,
   routes::DbPoolParam,
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_ext::Ext2;
 use activitystreams_new::{
   activity::{
     kind::{AcceptType, AnnounceType, DeleteType, LikeType, RemoveType, UndoType},
-    Accept, Announce, Delete, Follow, Remove, Undo,
+    Accept,
+    Announce,
+    Delete,
+    Follow,
+    Remove,
+    Undo,
   },
   actor::{kind::GroupType, ApActor, Endpoints, Group},
   base::{AnyBase, BaseExt},
@@ -324,7 +337,7 @@ impl FromApub for CommunityForm {
       .as_xsd_any_uri()
       .unwrap();
 
-    let creator = get_or_fetch_and_upsert_remote_user(creator_uri, client, pool).await?;
+    let creator = get_or_fetch_and_upsert_user(creator_uri, client, pool).await?;
 
     Ok(CommunityForm {
       name: group
index cf1986365d25c42db2c56952101936b498b4a27a..ff1ec11b7a92a47e55a345e8c8d11ea9857b94c7 100644 (file)
@@ -1,12 +1,19 @@
 use crate::{
   api::site::SearchResponse,
   apub::{
-    is_apub_id_valid, ActorType, FromApub, GroupExt, PageExt, PersonExt, APUB_JSON_CONTENT_TYPE,
+    is_apub_id_valid,
+    ActorType,
+    FromApub,
+    GroupExt,
+    PageExt,
+    PersonExt,
+    APUB_JSON_CONTENT_TYPE,
   },
   blocking,
   request::{retry, RecvError},
   routes::nodeinfo::{NodeInfo, NodeInfoWellKnown},
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::{base::BaseExt, object::Note, prelude::*};
 use actix_web::client::Client;
@@ -22,7 +29,9 @@ use lemmy_db::{
   post_view::PostView,
   user::{UserForm, User_},
   user_view::UserView,
-  Crud, Joinable, SearchType,
+  Crud,
+  Joinable,
+  SearchType,
 };
 use lemmy_utils::get_apub_protocol_string;
 use log::debug;
@@ -140,7 +149,7 @@ pub async fn search_by_apub_id(
     SearchAcceptedObjects::Person(p) => {
       let user_uri = p.inner.id(domain)?.unwrap();
 
-      let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
+      let user = get_or_fetch_and_upsert_user(&user_uri, client, pool).await?;
 
       response.users = vec![blocking(pool, move |conn| UserView::read(conn, user.id)).await??];
 
@@ -149,7 +158,7 @@ pub async fn search_by_apub_id(
     SearchAcceptedObjects::Group(g) => {
       let community_uri = g.inner.id(domain)?.unwrap();
 
-      let community = get_or_fetch_and_upsert_remote_community(community_uri, client, pool).await?;
+      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)?;
@@ -191,21 +200,21 @@ pub async fn search_by_apub_id(
   Ok(response)
 }
 
-pub async fn get_or_fetch_and_upsert_remote_actor(
+pub async fn get_or_fetch_and_upsert_actor(
   apub_id: &Url,
   client: &Client,
   pool: &DbPool,
 ) -> Result<Box<dyn ActorType>, LemmyError> {
-  let user = get_or_fetch_and_upsert_remote_user(apub_id, client, pool).await;
+  let user = get_or_fetch_and_upsert_user(apub_id, client, pool).await;
   let actor: Box<dyn ActorType> = match user {
     Ok(u) => Box::new(u),
-    Err(_) => Box::new(get_or_fetch_and_upsert_remote_community(apub_id, client, pool).await?),
+    Err(_) => Box::new(get_or_fetch_and_upsert_community(apub_id, client, pool).await?),
   };
   Ok(actor)
 }
 
 /// Check if a remote user exists, create if not found, if its too old update it.Fetch a user, insert/update it in the database and return the user.
-pub async fn get_or_fetch_and_upsert_remote_user(
+pub async fn get_or_fetch_and_upsert_user(
   apub_id: &Url,
   client: &Client,
   pool: &DbPool,
@@ -257,7 +266,7 @@ fn should_refetch_actor(last_refreshed: NaiveDateTime) -> bool {
 }
 
 /// Check if a remote community exists, create if not found, if its too old update it.Fetch a community, insert/update it in the database and return the community.
-pub async fn get_or_fetch_and_upsert_remote_community(
+pub async fn get_or_fetch_and_upsert_community(
   apub_id: &Url,
   client: &Client,
   pool: &DbPool,
@@ -299,7 +308,7 @@ pub async fn get_or_fetch_and_upsert_remote_community(
       let mut creator_and_moderators = Vec::new();
 
       for uri in creator_and_moderator_uris {
-        let c_or_m = get_or_fetch_and_upsert_remote_user(uri, client, pool).await?;
+        let c_or_m = get_or_fetch_and_upsert_user(uri, client, pool).await?;
 
         creator_and_moderators.push(c_or_m);
       }
@@ -333,7 +342,7 @@ fn upsert_post(post_form: &PostForm, conn: &PgConnection) -> Result<Post, LemmyE
   }
 }
 
-pub async fn get_or_fetch_and_insert_remote_post(
+pub async fn get_or_fetch_and_insert_post(
   post_ap_id: &Url,
   client: &Client,
   pool: &DbPool,
@@ -368,7 +377,7 @@ fn upsert_comment(comment_form: &CommentForm, conn: &PgConnection) -> Result<Com
   }
 }
 
-pub async fn get_or_fetch_and_insert_remote_comment(
+pub async fn get_or_fetch_and_insert_comment(
   comment_ap_id: &Url,
   client: &Client,
   pool: &DbPool,
index ae1351836d56d0be84e6c505e7ff2e8223d8b6e7..78a005fb17618a97e1cb0a5b05c70421a1f70696 100644 (file)
@@ -1,13 +1,19 @@
 use crate::{
   apub::inbox::{
     activities::{
-      create::receive_create, delete::receive_delete, dislike::receive_dislike, like::receive_like,
-      remove::receive_remove, undo::receive_undo, update::receive_update,
+      create::receive_create,
+      delete::receive_delete,
+      dislike::receive_dislike,
+      like::receive_like,
+      remove::receive_remove,
+      undo::receive_undo,
+      update::receive_update,
     },
     shared_inbox::receive_unhandled_activity,
   },
   routes::ChatServerParam,
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::{activity::*, base::AnyBase, prelude::ExtendsExt};
 use actix_web::{client::Client, HttpResponse};
index 4390b1a82da388b0e5b01dc13df991524c2c7d2b..da90bea53109a198d323052ddc6b74a8d8c04161 100644 (file)
@@ -5,9 +5,13 @@ use crate::{
   },
   apub::{
     inbox::shared_inbox::{
-      announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
+      announce_if_community_is_local,
+      get_user_from_activity,
+      receive_unhandled_activity,
     },
-    ActorType, FromApub, PageExt,
+    ActorType,
+    FromApub,
+    PageExt,
   },
   blocking,
   routes::ChatServerParam,
@@ -15,7 +19,8 @@ use crate::{
     server::{SendComment, SendPost},
     UserOperation,
   },
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::{activity::Create, base::AnyBase, object::Note, prelude::*};
 use actix_web::{client::Client, HttpResponse};
index 82078653991b3dca4064a1957fe2faf34bbf63de..09df0bc1ed4bcd9ce2efbee1db86dadea93b8770 100644 (file)
@@ -1,11 +1,16 @@
 use crate::{
   api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
   apub::{
-    fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
+    fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
     inbox::shared_inbox::{
-      announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
+      announce_if_community_is_local,
+      get_user_from_activity,
+      receive_unhandled_activity,
     },
-    ActorType, FromApub, GroupExt, PageExt,
+    ActorType,
+    FromApub,
+    GroupExt,
+    PageExt,
   },
   blocking,
   routes::ChatServerParam,
@@ -13,7 +18,8 @@ use crate::{
     server::{SendComment, SendCommunityRoomMessage, SendPost},
     UserOperation,
   },
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::{activity::Delete, base::AnyBase, object::Note, prelude::*};
 use actix_web::{client::Client, HttpResponse};
@@ -56,7 +62,7 @@ async fn receive_delete_post(
     .await?
     .get_ap_id()?;
 
-  let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
+  let post = get_or_fetch_and_insert_post(&post_ap_id, client, pool).await?;
 
   let post_form = PostForm {
     name: post.name.to_owned(),
@@ -110,7 +116,7 @@ async fn receive_delete_comment(
     .await?
     .get_ap_id()?;
 
-  let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
+  let comment = get_or_fetch_and_insert_comment(&comment_ap_id, client, pool).await?;
 
   let comment_form = CommentForm {
     content: comment.content.to_owned(),
index bbb868e7d8d7127e28e7668c801ea4633fe1ca1b..7135505e1a973e6bca9af9ab0f27e5c3bae73da2 100644 (file)
@@ -1,11 +1,15 @@
 use crate::{
   api::{comment::CommentResponse, post::PostResponse},
   apub::{
-    fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
+    fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
     inbox::shared_inbox::{
-      announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
+      announce_if_community_is_local,
+      get_user_from_activity,
+      receive_unhandled_activity,
     },
-    ActorType, FromApub, PageExt,
+    ActorType,
+    FromApub,
+    PageExt,
   },
   blocking,
   routes::ChatServerParam,
@@ -13,7 +17,8 @@ use crate::{
     server::{SendComment, SendPost},
     UserOperation,
   },
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::{activity::Dislike, base::AnyBase, object::Note, prelude::*};
 use actix_web::{client::Client, HttpResponse};
@@ -50,7 +55,7 @@ async fn receive_dislike_post(
 
   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)
+  let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool)
     .await?
     .id;
 
@@ -91,7 +96,7 @@ async fn receive_dislike_comment(
 
   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)
+  let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool)
     .await?
     .id;
 
index 893b68c31f4a5c8a695b62ec9ca73bc0c318fe19..36bdbfa8db0671815e2d3f7f7d518705f8dfa651 100644 (file)
@@ -1,11 +1,15 @@
 use crate::{
   api::{comment::CommentResponse, post::PostResponse},
   apub::{
-    fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
+    fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
     inbox::shared_inbox::{
-      announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
+      announce_if_community_is_local,
+      get_user_from_activity,
+      receive_unhandled_activity,
     },
-    ActorType, FromApub, PageExt,
+    ActorType,
+    FromApub,
+    PageExt,
   },
   blocking,
   routes::ChatServerParam,
@@ -13,7 +17,8 @@ use crate::{
     server::{SendComment, SendPost},
     UserOperation,
   },
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::{activity::Like, base::AnyBase, object::Note, prelude::*};
 use actix_web::{client::Client, HttpResponse};
@@ -50,7 +55,7 @@ async fn receive_like_post(
 
   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)
+  let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool)
     .await?
     .id;
 
@@ -91,7 +96,7 @@ async fn receive_like_comment(
 
   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)
+  let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool)
     .await?
     .id;
 
index 8b1630d80e8a970e486582b5d8cc803def331afe..1ae482d420aa8d4b69bb84e80bdc7210c71860a8 100644 (file)
@@ -1,11 +1,16 @@
 use crate::{
   api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
   apub::{
-    fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
+    fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
     inbox::shared_inbox::{
-      announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
+      announce_if_community_is_local,
+      get_user_from_activity,
+      receive_unhandled_activity,
     },
-    ActorType, FromApub, GroupExt, PageExt,
+    ActorType,
+    FromApub,
+    GroupExt,
+    PageExt,
   },
   blocking,
   routes::ChatServerParam,
@@ -13,7 +18,8 @@ use crate::{
     server::{SendComment, SendCommunityRoomMessage, SendPost},
     UserOperation,
   },
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::{activity::Remove, base::AnyBase, object::Note, prelude::*};
 use actix_web::{client::Client, HttpResponse};
@@ -56,7 +62,7 @@ async fn receive_remove_post(
     .await?
     .get_ap_id()?;
 
-  let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
+  let post = get_or_fetch_and_insert_post(&post_ap_id, client, pool).await?;
 
   let post_form = PostForm {
     name: post.name.to_owned(),
@@ -110,7 +116,7 @@ async fn receive_remove_comment(
     .await?
     .get_ap_id()?;
 
-  let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
+  let comment = get_or_fetch_and_insert_comment(&comment_ap_id, client, pool).await?;
 
   let comment_form = CommentForm {
     content: comment.content.to_owned(),
index ad62a8f6efe4f0d7304e6cf79eeea6e8ff9005d2..3634bd44d3a8625a11943b2497ca506d2bd20ff1 100644 (file)
@@ -1,11 +1,16 @@
 use crate::{
   api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
   apub::{
-    fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
+    fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
     inbox::shared_inbox::{
-      announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
+      announce_if_community_is_local,
+      get_user_from_activity,
+      receive_unhandled_activity,
     },
-    ActorType, FromApub, GroupExt, PageExt,
+    ActorType,
+    FromApub,
+    GroupExt,
+    PageExt,
   },
   blocking,
   routes::ChatServerParam,
@@ -13,7 +18,8 @@ use crate::{
     server::{SendComment, SendCommunityRoomMessage, SendPost},
     UserOperation,
   },
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::{activity::*, base::AnyBase, object::Note, prelude::*};
 use actix_web::{client::Client, HttpResponse};
@@ -25,7 +31,8 @@ use lemmy_db::{
   naive_now,
   post::{Post, PostForm, PostLike, PostLikeForm},
   post_view::PostView,
-  Crud, Likeable,
+  Crud,
+  Likeable,
 };
 
 pub async fn receive_undo(
@@ -120,7 +127,7 @@ async fn receive_undo_delete_comment(
     .await?
     .get_ap_id()?;
 
-  let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
+  let comment = get_or_fetch_and_insert_comment(&comment_ap_id, client, pool).await?;
 
   let comment_form = CommentForm {
     content: comment.content.to_owned(),
@@ -178,7 +185,7 @@ async fn receive_undo_remove_comment(
     .await?
     .get_ap_id()?;
 
-  let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
+  let comment = get_or_fetch_and_insert_comment(&comment_ap_id, client, pool).await?;
 
   let comment_form = CommentForm {
     content: comment.content.to_owned(),
@@ -236,7 +243,7 @@ async fn receive_undo_delete_post(
     .await?
     .get_ap_id()?;
 
-  let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
+  let post = get_or_fetch_and_insert_post(&post_ap_id, client, pool).await?;
 
   let post_form = PostForm {
     name: post.name.to_owned(),
@@ -291,7 +298,7 @@ async fn receive_undo_remove_post(
     .await?
     .get_ap_id()?;
 
-  let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
+  let post = get_or_fetch_and_insert_post(&post_ap_id, client, pool).await?;
 
   let post_form = PostForm {
     name: post.name.to_owned(),
@@ -472,7 +479,7 @@ async fn receive_undo_like_comment(
 
   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)
+  let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool)
     .await?
     .id;
 
@@ -518,7 +525,7 @@ async fn receive_undo_like_post(
 
   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)
+  let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool)
     .await?
     .id;
 
index 306d8ef71ea210a2d1129c5b1177e7423f2389ee..2d5d06606967dd1fdf43b4163029fbefde0d2a16 100644 (file)
@@ -4,11 +4,15 @@ use crate::{
     post::PostResponse,
   },
   apub::{
-    fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
+    fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
     inbox::shared_inbox::{
-      announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
+      announce_if_community_is_local,
+      get_user_from_activity,
+      receive_unhandled_activity,
     },
-    ActorType, FromApub, PageExt,
+    ActorType,
+    FromApub,
+    PageExt,
   },
   blocking,
   routes::ChatServerParam,
@@ -16,7 +20,8 @@ use crate::{
     server::{SendComment, SendPost},
     UserOperation,
   },
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::{activity::Update, base::AnyBase, object::Note, prelude::*};
 use actix_web::{client::Client, HttpResponse};
@@ -54,7 +59,7 @@ async fn receive_update_post(
 
   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)
+  let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool)
     .await?
     .id;
 
@@ -86,7 +91,7 @@ async fn receive_update_comment(
 
   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)
+  let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool)
     .await?
     .id;
 
index 44a1c949dfa8275d50e6a068ab57b87fd8cd8d49..8088ec5c356cd51d419a9d8434a78a53068d8afa 100644 (file)
@@ -1,8 +1,9 @@
 use crate::{
   apub::{
     extensions::signatures::verify,
-    fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
-    insert_activity, ActorType,
+    fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user},
+    insert_activity,
+    ActorType,
   },
   blocking,
   routes::{ChatServerParam, DbPoolParam},
@@ -71,8 +72,8 @@ pub async fn community_inbox(
   let user_uri = follow.actor()?.as_single_xsd_any_uri().unwrap();
   let community_uri = follow.object().as_single_xsd_any_uri().unwrap();
 
-  let user = get_or_fetch_and_upsert_remote_user(&user_uri, &client, &db).await?;
-  let community = get_or_fetch_and_upsert_remote_community(community_uri, &client, &db).await?;
+  let user = get_or_fetch_and_upsert_user(&user_uri, &client, &db).await?;
+  let community = get_or_fetch_and_upsert_community(community_uri, &client, &db).await?;
 
   verify(&request, &user)?;
 
index eb3d521bb3f3709b1c811a30a91730a6790898b4..3a2d1c43fbdc55e32edad775dcbb93aa0c467020 100644 (file)
@@ -3,18 +3,25 @@ use crate::{
     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,
+      get_or_fetch_and_upsert_actor,
+      get_or_fetch_and_upsert_community,
+      get_or_fetch_and_upsert_user,
     },
     inbox::activities::{
-      announce::receive_announce, create::receive_create, delete::receive_delete,
-      dislike::receive_dislike, like::receive_like, remove::receive_remove, undo::receive_undo,
+      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,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::{
   activity::{ActorAndObject, ActorAndObjectRef},
@@ -27,6 +34,7 @@ use lemmy_db::user::User_;
 use log::debug;
 use serde::Serialize;
 use std::fmt::Debug;
+use url::Url;
 
 #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize)]
 #[serde(rename_all = "PascalCase")]
@@ -61,7 +69,7 @@ pub async fn shared_inbox(
   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?;
+  let actor = get_or_fetch_and_upsert_actor(sender, &client, &pool).await?;
   verify(&request, actor.as_ref())?;
 
   insert_activity(actor.user_id(), activity.clone(), false, &pool).await?;
@@ -101,7 +109,7 @@ where
 {
   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
+  get_or_fetch_and_upsert_user(&user_uri, client, pool).await
 }
 
 pub(in crate::apub::inbox) async fn announce_if_community_is_local<T, Kind>(
@@ -118,8 +126,13 @@ where
 {
   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?;
+  let community_followers_uri = cc.first().unwrap().as_xsd_any_uri().unwrap();
+  // TODO: this is hacky but seems to be the only way to get the community ID
+  let community_uri = community_followers_uri
+    .to_string()
+    .replace("/followers", "");
+  let community =
+    get_or_fetch_and_upsert_community(&Url::parse(&community_uri)?, client, pool).await?;
 
   if community.local {
     do_announce(activity.into_any_base()?, &community, &user, client, pool).await?;
index 73916ee2cdaa8fd11c066b5f1dec5fa8a444b806..13d974e9af191664693eb45fbd3c992a75a828e9 100644 (file)
@@ -2,13 +2,15 @@ use crate::{
   api::user::PrivateMessageResponse,
   apub::{
     extensions::signatures::verify,
-    fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
-    insert_activity, FromApub,
+    fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user},
+    insert_activity,
+    FromApub,
   },
   blocking,
   routes::{ChatServerParam, DbPoolParam},
   websocket::{server::SendUserRoomMessage, UserOperation},
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::{
   activity::{Accept, Create, Delete, Undo, Update},
@@ -22,7 +24,8 @@ use lemmy_db::{
   private_message::{PrivateMessage, PrivateMessageForm},
   private_message_view::PrivateMessageView,
   user::User_,
-  Crud, Followable,
+  Crud,
+  Followable,
 };
 use log::debug;
 use serde::Deserialize;
@@ -79,7 +82,7 @@ async fn receive_accept(
 ) -> Result<HttpResponse, LemmyError> {
   let community_uri = accept.actor()?.to_owned().single_xsd_any_uri().unwrap();
 
-  let community = get_or_fetch_and_upsert_remote_community(&community_uri, client, pool).await?;
+  let community = get_or_fetch_and_upsert_community(&community_uri, client, pool).await?;
   verify(request, &community)?;
 
   let username = username.to_owned();
@@ -113,7 +116,7 @@ async fn receive_create_private_message(
   let user_uri = &create.actor()?.to_owned().single_xsd_any_uri().unwrap();
   let note = Note::from_any_base(create.object().as_one().unwrap().to_owned())?.unwrap();
 
-  let user = get_or_fetch_and_upsert_remote_user(user_uri, client, pool).await?;
+  let user = get_or_fetch_and_upsert_user(user_uri, client, pool).await?;
   verify(request, &user)?;
 
   insert_activity(user.id, create, false, pool).await?;
@@ -154,7 +157,7 @@ async fn receive_update_private_message(
   let user_uri = &update.actor()?.to_owned().single_xsd_any_uri().unwrap();
   let note = Note::from_any_base(update.object().as_one().unwrap().to_owned())?.unwrap();
 
-  let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
+  let user = get_or_fetch_and_upsert_user(&user_uri, client, pool).await?;
   verify(request, &user)?;
 
   insert_activity(user.id, update, false, pool).await?;
@@ -203,7 +206,7 @@ async fn receive_delete_private_message(
   let user_uri = &delete.actor()?.to_owned().single_xsd_any_uri().unwrap();
   let note = Note::from_any_base(delete.object().as_one().unwrap().to_owned())?.unwrap();
 
-  let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
+  let user = get_or_fetch_and_upsert_user(&user_uri, client, pool).await?;
   verify(request, &user)?;
 
   insert_activity(user.id, delete, false, pool).await?;
@@ -265,7 +268,7 @@ async fn receive_undo_delete_private_message(
   let note = Note::from_any_base(delete.object().as_one().unwrap().to_owned())?.unwrap();
   let user_uri = &delete.actor()?.to_owned().single_xsd_any_uri().unwrap();
 
-  let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
+  let user = get_or_fetch_and_upsert_user(&user_uri, client, pool).await?;
   verify(request, &user)?;
 
   insert_activity(user.id, delete, false, pool).await?;
index a5d8984c8a2cf4ac5044626722b098c37be7a9e4..47f01e315b38a9ee1f308ce856118cf07d567f9c 100644 (file)
@@ -17,7 +17,8 @@ use crate::{
   blocking,
   request::{retry, RecvError},
   routes::webfinger::WebFingerResponse,
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_ext::{Ext1, Ext2};
 use activitystreams_new::{
index 932ff8ce285337df9ad87e4906ca160039889b24..a4cf8e4ccdff2506dbfb050be825722317166467 100644 (file)
@@ -1,20 +1,34 @@
 use crate::{
   apub::{
     activities::{generate_activity_id, send_activity_to_community},
-    create_apub_response, create_apub_tombstone_response, create_tombstone,
+    create_apub_response,
+    create_apub_tombstone_response,
+    create_tombstone,
     extensions::page_extension::PageExtension,
-    fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
-    ActorType, ApubLikeableType, ApubObjectType, FromApub, PageExt, ToApub,
+    fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user},
+    ActorType,
+    ApubLikeableType,
+    ApubObjectType,
+    FromApub,
+    PageExt,
+    ToApub,
   },
   blocking,
   routes::DbPoolParam,
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_ext::Ext1;
 use activitystreams_new::{
   activity::{
     kind::{CreateType, DeleteType, DislikeType, LikeType, RemoveType, UndoType, UpdateType},
-    Create, Delete, Dislike, Like, Remove, Undo, Update,
+    Create,
+    Delete,
+    Dislike,
+    Like,
+    Remove,
+    Undo,
+    Update,
   },
   context,
   object::{kind::PageType, Image, Page, Tombstone},
@@ -151,7 +165,7 @@ impl FromApub for PostForm {
       .as_single_xsd_any_uri()
       .unwrap();
 
-    let creator = get_or_fetch_and_upsert_remote_user(creator_actor_id, client, pool).await?;
+    let creator = get_or_fetch_and_upsert_user(creator_actor_id, client, pool).await?;
 
     let community_actor_id = page
       .inner
@@ -161,8 +175,7 @@ impl FromApub for PostForm {
       .as_single_xsd_any_uri()
       .unwrap();
 
-    let community =
-      get_or_fetch_and_upsert_remote_community(community_actor_id, client, pool).await?;
+    let community = get_or_fetch_and_upsert_community(community_actor_id, client, pool).await?;
 
     let thumbnail_url = match &page.inner.image() {
       Some(any_image) => Image::from_any_base(any_image.to_owned().as_one().unwrap().to_owned())?
index b10f87b5504ee03aa73f5358266540d9a9db462e..5f8abca8e29bb3cb27b576196909c3de24529c36 100644 (file)
@@ -2,15 +2,23 @@ use crate::{
   apub::{
     activities::{generate_activity_id, send_activity},
     create_tombstone,
-    fetcher::get_or_fetch_and_upsert_remote_user,
-    insert_activity, ApubObjectType, FromApub, ToApub,
+    fetcher::get_or_fetch_and_upsert_user,
+    insert_activity,
+    ApubObjectType,
+    FromApub,
+    ToApub,
   },
-  blocking, DbPool, LemmyError,
+  blocking,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_new::{
   activity::{
     kind::{CreateType, DeleteType, UndoType, UpdateType},
-    Create, Delete, Undo, Update,
+    Create,
+    Delete,
+    Undo,
+    Update,
   },
   context,
   object::{kind::NoteType, Note, Tombstone},
@@ -76,11 +84,11 @@ impl FromApub for PrivateMessageForm {
       .single_xsd_any_uri()
       .unwrap();
 
-    let creator = get_or_fetch_and_upsert_remote_user(&creator_actor_id, client, pool).await?;
+    let creator = get_or_fetch_and_upsert_user(&creator_actor_id, client, pool).await?;
 
     let recipient_actor_id = note.to().unwrap().clone().single_xsd_any_uri().unwrap();
 
-    let recipient = get_or_fetch_and_upsert_remote_user(&recipient_actor_id, client, pool).await?;
+    let recipient = get_or_fetch_and_upsert_user(&recipient_actor_id, client, pool).await?;
 
     Ok(PrivateMessageForm {
       creator_id: creator.id,
index 8ec972dadb69d0b6db363fe9449c66f23aa8107f..9d8c9167ff0492e1d2e82b26e82fb3f08afca0e6 100644 (file)
@@ -1,17 +1,24 @@
 use crate::{
   apub::{
     activities::{generate_activity_id, send_activity},
-    create_apub_response, insert_activity, ActorType, FromApub, PersonExt, ToApub,
+    create_apub_response,
+    insert_activity,
+    ActorType,
+    FromApub,
+    PersonExt,
+    ToApub,
   },
   blocking,
   routes::DbPoolParam,
-  DbPool, LemmyError,
+  DbPool,
+  LemmyError,
 };
 use activitystreams_ext::Ext1;
 use activitystreams_new::{
   activity::{
     kind::{FollowType, UndoType},
-    Follow, Undo,
+    Follow,
+    Undo,
   },
   actor::{ApActor, Endpoints, Person},
   context,