Move ObjectId to library
authorFelix Ableitner <me@nutomic.com>
Fri, 5 Nov 2021 00:24:10 +0000 (01:24 +0100)
committerFelix Ableitner <me@nutomic.com>
Fri, 5 Nov 2021 20:37:46 +0000 (21:37 +0100)
73 files changed:
Cargo.lock
crates/api/src/comment_report.rs
crates/api/src/post_report.rs
crates/api_crud/src/community/create.rs
crates/api_crud/src/community/read.rs
crates/api_crud/src/post/create.rs
crates/api_crud/src/user/read.rs
crates/apub/src/activities/comment/create_or_update.rs
crates/apub/src/activities/comment/mod.rs
crates/apub/src/activities/community/add_mod.rs
crates/apub/src/activities/community/announce.rs
crates/apub/src/activities/community/block_user.rs
crates/apub/src/activities/community/mod.rs
crates/apub/src/activities/community/remove_mod.rs
crates/apub/src/activities/community/report.rs
crates/apub/src/activities/community/undo_block_user.rs
crates/apub/src/activities/community/update.rs
crates/apub/src/activities/deletion/delete.rs
crates/apub/src/activities/deletion/mod.rs
crates/apub/src/activities/deletion/undo_delete.rs
crates/apub/src/activities/following/accept.rs
crates/apub/src/activities/following/follow.rs
crates/apub/src/activities/following/undo_follow.rs
crates/apub/src/activities/mod.rs
crates/apub/src/activities/post/create_or_update.rs
crates/apub/src/activities/private_message/create_or_update.rs
crates/apub/src/activities/private_message/delete.rs
crates/apub/src/activities/private_message/undo_delete.rs
crates/apub/src/activities/voting/undo_vote.rs
crates/apub/src/activities/voting/vote.rs
crates/apub/src/collections/community_moderators.rs
crates/apub/src/collections/community_outbox.rs
crates/apub/src/fetcher/mod.rs
crates/apub/src/fetcher/search.rs
crates/apub/src/http/community.rs
crates/apub/src/http/mod.rs
crates/apub/src/objects/comment.rs
crates/apub/src/objects/community.rs
crates/apub/src/objects/person.rs
crates/apub/src/objects/post.rs
crates/apub/src/objects/private_message.rs
crates/apub/src/protocol/activities/community/add_mod.rs
crates/apub/src/protocol/activities/community/announce.rs
crates/apub/src/protocol/activities/community/block_user.rs
crates/apub/src/protocol/activities/community/remove_mod.rs
crates/apub/src/protocol/activities/community/report.rs
crates/apub/src/protocol/activities/community/undo_block_user.rs
crates/apub/src/protocol/activities/community/update.rs
crates/apub/src/protocol/activities/create_or_update/comment.rs
crates/apub/src/protocol/activities/create_or_update/post.rs
crates/apub/src/protocol/activities/deletion/delete.rs
crates/apub/src/protocol/activities/deletion/undo_delete.rs
crates/apub/src/protocol/activities/following/accept.rs
crates/apub/src/protocol/activities/following/follow.rs
crates/apub/src/protocol/activities/following/undo_follow.rs
crates/apub/src/protocol/activities/private_message/create_or_update.rs
crates/apub/src/protocol/activities/private_message/delete.rs
crates/apub/src/protocol/activities/private_message/undo_delete.rs
crates/apub/src/protocol/activities/voting/undo_vote.rs
crates/apub/src/protocol/activities/voting/vote.rs
crates/apub/src/protocol/collections/group_followers.rs
crates/apub/src/protocol/collections/group_moderators.rs
crates/apub/src/protocol/collections/person_outbox.rs
crates/apub/src/protocol/objects/chat_message.rs
crates/apub/src/protocol/objects/group.rs
crates/apub/src/protocol/objects/note.rs
crates/apub/src/protocol/objects/page.rs
crates/apub/src/protocol/objects/person.rs
crates/apub_lib/Cargo.toml
crates/apub_lib/src/lib.rs
crates/apub_lib/src/object_id.rs [moved from crates/apub/src/fetcher/object_id.rs with 74% similarity]
crates/db_schema/Cargo.toml
crates/db_schema/src/newtypes.rs

index d412775203b77b271f203450f3a76af4ffa49759..8fb7629396d1f7f3cd27c8cb6f4a0b07d6985033 100644 (file)
@@ -1869,6 +1869,7 @@ dependencies = [
  "async-trait",
  "background-jobs",
  "base64 0.13.0",
+ "diesel",
  "http",
  "http-signature-normalization-actix",
  "http-signature-normalization-reqwest",
@@ -1904,6 +1905,7 @@ dependencies = [
  "diesel-derive-newtype",
  "diesel_migrations",
  "lazy_static",
+ "lemmy_apub_lib",
  "lemmy_utils",
  "log",
  "regex",
index 82ecc1f445db4704a9b9029bb311d37049ae314b..f1bf7023c39a4f056c5d0505e4b9037f46bf500e 100644 (file)
@@ -1,5 +1,5 @@
+use crate::Perform;
 use actix_web::web::Data;
-
 use lemmy_api_common::{
   blocking,
   check_community_ban,
@@ -7,7 +7,8 @@ use lemmy_api_common::{
   get_local_user_view_from_jwt,
   is_mod_or_admin,
 };
-use lemmy_apub::{fetcher::object_id::ObjectId, protocol::activities::community::report::Report};
+use lemmy_apub::protocol::activities::community::report::Report;
+use lemmy_apub_lib::object_id::ObjectId;
 use lemmy_db_schema::{source::comment_report::*, traits::Reportable};
 use lemmy_db_views::{
   comment_report_view::{CommentReportQueryBuilder, CommentReportView},
@@ -16,8 +17,6 @@ use lemmy_db_views::{
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
 
-use crate::Perform;
-
 /// Creates a comment report and notifies the moderators of the community
 #[async_trait::async_trait(?Send)]
 impl Perform for CreateCommentReport {
index 98b2f1c119b2ffb3cdc2fa54b09cf96f72ce4ffb..0e47f592d06433da3ef98a5f38886be449e8f5ce 100644 (file)
@@ -1,5 +1,5 @@
+use crate::Perform;
 use actix_web::web::Data;
-
 use lemmy_api_common::{
   blocking,
   check_community_ban,
@@ -13,7 +13,8 @@ use lemmy_api_common::{
     ResolvePostReport,
   },
 };
-use lemmy_apub::{fetcher::object_id::ObjectId, protocol::activities::community::report::Report};
+use lemmy_apub::protocol::activities::community::report::Report;
+use lemmy_apub_lib::object_id::ObjectId;
 use lemmy_db_schema::{
   source::post_report::{PostReport, PostReportForm},
   traits::Reportable,
@@ -25,8 +26,6 @@ use lemmy_db_views::{
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
 
-use crate::Perform;
-
 /// Creates a post report and notifies the moderators of the community
 #[async_trait::async_trait(?Send)]
 impl Perform for CreatePostReport {
index 523ccf00dd66aa0ff31c7ad043cd38d27ac80b49..b91cab433538d9f3f798693ab8536f4d097819f7 100644 (file)
@@ -7,7 +7,6 @@ use lemmy_api_common::{
   is_admin,
 };
 use lemmy_apub::{
-  fetcher::object_id::ObjectId,
   generate_followers_url,
   generate_inbox_url,
   generate_local_apub_endpoint,
@@ -15,6 +14,7 @@ use lemmy_apub::{
   objects::community::ApubCommunity,
   EndpointType,
 };
+use lemmy_apub_lib::object_id::ObjectId;
 use lemmy_db_schema::{
   diesel_option_overwrite_to_url,
   source::{
index feaf110fb743dd1ab09b819a73377a2feb984546..47c0058c95d3de192b4e5b73c10b9cc22fa8ddc7 100644 (file)
@@ -1,12 +1,8 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt_opt};
-use lemmy_apub::{
-  fetcher::object_id::ObjectId,
-  get_actor_id_from_name,
-  objects::community::ApubCommunity,
-};
-use lemmy_apub_lib::webfinger::WebfingerType;
+use lemmy_apub::{get_actor_id_from_name, objects::community::ApubCommunity};
+use lemmy_apub_lib::{object_id::ObjectId, webfinger::WebfingerType};
 use lemmy_db_schema::{
   from_opt_str_to_opt_enum,
   traits::DeleteableOrRemoveable,
index 99b67d2eaf46c63debdad966f96bc08b5bf5b4c6..4b5c9e73dfc934cef70dd1f1b029ce7cf8825bf1 100644 (file)
@@ -1,7 +1,5 @@
+use crate::PerformCrud;
 use actix_web::web::Data;
-use log::warn;
-use webmention::{Webmention, WebmentionError};
-
 use lemmy_api_common::{
   blocking,
   check_community_ban,
@@ -33,8 +31,9 @@ use lemmy_utils::{
   LemmyError,
 };
 use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
-
-use crate::PerformCrud;
+use log::warn;
+use url::Url;
+use webmention::{Webmention, WebmentionError};
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for CreatePost {
@@ -136,10 +135,8 @@ impl PerformCrud for CreatePost {
     mark_post_as_read(person_id, post_id, context.pool()).await?;
 
     if let Some(url) = &updated_post.url {
-      let mut webmention = Webmention::new(
-        updated_post.ap_id.clone().into_inner(),
-        url.clone().into_inner(),
-      )?;
+      let mut webmention =
+        Webmention::new::<Url>(updated_post.ap_id.clone().into(), url.clone().into())?;
       webmention.set_checked(true);
       match webmention.send().await {
         Ok(_) => {}
index b649c8fbb28581c73cec1c76f08aeed1274c8296..41db9f99b551b74d6e67974c35ed2dd756d32fe8 100644 (file)
@@ -1,12 +1,8 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, person::*};
-use lemmy_apub::{
-  fetcher::object_id::ObjectId,
-  get_actor_id_from_name,
-  objects::person::ApubPerson,
-};
-use lemmy_apub_lib::webfinger::WebfingerType;
+use lemmy_apub::{get_actor_id_from_name, objects::person::ApubPerson};
+use lemmy_apub_lib::{object_id::ObjectId, webfinger::WebfingerType};
 use lemmy_db_schema::{from_opt_str_to_opt_enum, SortType};
 use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder};
 use lemmy_db_views_actor::{
index 84f6d3f280b5e7b172c7233eb05f1ee154fa141b..0d12c4b398e83e415fae2dde147f892ec801af35 100644 (file)
@@ -9,7 +9,6 @@ use crate::{
     verify_person_in_community,
   },
   activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
   objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson},
   protocol::activities::{create_or_update::comment::CreateOrUpdateComment, CreateOrUpdateType},
 };
@@ -17,6 +16,7 @@ use activitystreams::public;
 use lemmy_api_common::{blocking, check_post_deleted_or_removed};
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType, ApubObject},
   verify::verify_domains_match,
 };
index 9eb2bb447b38d9588d1fb571cedfae7e58f1a078..1a3f7d3a0e99a7584358f5575d326c211cdc59e5 100644 (file)
@@ -1,7 +1,4 @@
-use crate::{
-  fetcher::object_id::ObjectId,
-  objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson},
-};
+use crate::objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson};
 use activitystreams::{
   base::BaseExt,
   link::{LinkExt, Mention},
@@ -9,7 +6,7 @@ use activitystreams::{
 use anyhow::anyhow;
 use itertools::Itertools;
 use lemmy_api_common::blocking;
-use lemmy_apub_lib::{traits::ActorType, webfinger::WebfingerResponse};
+use lemmy_apub_lib::{object_id::ObjectId, traits::ActorType, webfinger::WebfingerResponse};
 use lemmy_db_schema::{
   newtypes::LocalUserId,
   source::{comment::Comment, person::Person, post::Post},
index 11dc5a0b9e382d10cad6651f567bdd7897b685b0..8dad860964d8b078379a2b7822109e035e8cda78 100644 (file)
@@ -9,7 +9,6 @@ use crate::{
     verify_person_in_community,
   },
   activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
   generate_moderators_url,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::community::add_mod::AddMod,
@@ -18,6 +17,7 @@ use activitystreams::{activity::kind::AddType, public};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
index b245a1b88ab73aef673ab129ac0c5b7d8203c579..1fcce83774845d1a4f6da5d7877138007eb89ae5 100644 (file)
@@ -1,7 +1,6 @@
 use crate::{
   activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_is_public},
   activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
   http::{is_activity_already_known, ActivityCommonFields},
   insert_activity,
   objects::community::ApubCommunity,
@@ -10,6 +9,7 @@ use crate::{
 use activitystreams::{activity::kind::AnnounceType, public};
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
 };
 use lemmy_utils::LemmyError;
@@ -36,7 +36,7 @@ impl AnnounceActivity {
       actor: ObjectId::new(community.actor_id()),
       to: vec![public()],
       object,
-      cc: vec![community.followers_url.clone().into_inner()],
+      cc: vec![community.followers_url.clone().into()],
       kind: AnnounceType::Announce,
       id: generate_activity_id(
         &AnnounceType::Announce,
index d756ed2512e7cf1728b7aeb772002e004826a364..851c96fd0f9dd5680ea6709f70b3f58d8ed09882 100644 (file)
@@ -8,7 +8,6 @@ use crate::{
     verify_person_in_community,
   },
   activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::community::block_user::BlockUserFromCommunity,
 };
@@ -16,6 +15,7 @@ use activitystreams::{activity::kind::BlockType, public};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
index 96e692d58c587e4d15ee26346de76ceb73baa369..b63c8b65605400c9f8ccbfce470ccdf640f82c91 100644 (file)
@@ -1,12 +1,11 @@
 use crate::{
   activities::send_lemmy_activity,
   activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
   insert_activity,
   objects::community::ApubCommunity,
   protocol::activities::community::announce::AnnounceActivity,
 };
-use lemmy_apub_lib::traits::ActorType;
+use lemmy_apub_lib::{object_id::ObjectId, traits::ActorType};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
 use url::Url;
index 1c79e70d2d83ab136d3b6db9e2ad0f216f8358a1..c5edf333b5e807d41bbb18199f18d018f27e37aa 100644 (file)
@@ -9,7 +9,6 @@ use crate::{
     verify_person_in_community,
   },
   activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
   generate_moderators_url,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::community::remove_mod::RemoveMod,
@@ -18,6 +17,7 @@ use activitystreams::{activity::kind::RemoveType, public};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
index 5b02490b0071d246d3b8c5046a0d2040054ee428..f0be3e0a04d913f1f1c3734a396a1d686d87d9d5 100644 (file)
@@ -5,7 +5,6 @@ use crate::{
     verify_activity,
     verify_person_in_community,
   },
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::community::report::Report,
   PostOrComment,
@@ -14,6 +13,7 @@ use activitystreams::activity::kind::FlagType;
 use lemmy_api_common::{blocking, comment::CommentReportResponse, post::PostReportResponse};
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
index 467237eb8b70125bbe203107188b74b6d6f44e19..bb4c0358737a34072939650c3e54d0f80ec70155 100644 (file)
@@ -8,7 +8,6 @@ use crate::{
     verify_person_in_community,
   },
   activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::community::{
     block_user::BlockUserFromCommunity,
@@ -19,6 +18,7 @@ use activitystreams::{activity::kind::UndoType, public};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
index 9acb89098b0ff6cc7d90a4e288736d5cb4bfecf6..45b08e02fe9c0a89257cd763061ccad0f61a3f8c 100644 (file)
@@ -8,7 +8,6 @@ use crate::{
     verify_person_in_community,
   },
   activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::{activities::community::update::UpdateCommunity, objects::group::Group},
 };
@@ -16,6 +15,7 @@ use activitystreams::{activity::kind::UpdateType, public};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType, ApubObject},
 };
 use lemmy_db_schema::{
index 605daf8ffaaf7385101699e8d139205c077420b9..6e2174982fbcda2725188f3414f8a2897eb881c8 100644 (file)
@@ -1,17 +1,12 @@
 use crate::{
   activities::{
     community::{announce::GetCommunity, send_to_community},
-    deletion::{
-      receive_delete_action,
-      verify_delete_activity,
-      DeletableObjects,
-    },
+    deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
     generate_activity_id,
     verify_activity,
     verify_is_public,
   },
   activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::deletion::delete::Delete,
 };
@@ -20,6 +15,7 @@ use anyhow::anyhow;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
index 1be3bccf65478bfaf3d74a5373b8756978c3fcee..ddd607a7c1128618f37b8abd79ec585367a140fb 100644 (file)
@@ -1,11 +1,11 @@
 use crate::{
   activities::{verify_mod_action, verify_person_in_community},
-  fetcher::object_id::ObjectId,
   objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
   protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
 };
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
+  object_id::ObjectId,
   traits::{ActorType, ApubObject},
   verify::verify_domains_match,
 };
index 93338a3f3f42584dc4a043facd10cdf38f47bc14..b3e44af293fb1a1250aeb69ae5ec1dc75bf1103b 100644 (file)
@@ -7,7 +7,6 @@ use crate::{
     verify_is_public,
   },
   activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
 };
@@ -16,6 +15,7 @@ use anyhow::anyhow;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
index 68c8ca45407eae85dd43b88fe99eb2e6dcd1905a..44d6009a299dfd5d6bfb57bd1faf7e20d87ec8a5 100644 (file)
@@ -1,12 +1,12 @@
 use crate::{
   activities::{generate_activity_id, send_lemmy_activity, verify_activity},
-  fetcher::object_id::ObjectId,
   protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity},
 };
 use activitystreams::activity::kind::AcceptType;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
   verify::verify_urls_match,
 };
index 30c77fe8161f3906673a5796bc59e9ef5837ee88..22f3db4ba6154590284699debb66b241d7311abf 100644 (file)
@@ -6,7 +6,6 @@ use crate::{
     verify_person,
     verify_person_in_community,
   },
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity},
 };
@@ -14,6 +13,7 @@ use activitystreams::activity::kind::FollowType;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
   verify::verify_urls_match,
 };
index bdc5a4b09f5368b3a9589c1e2fa4b45437d031aa..ac25fcd5c1bcdd8b3e5e938ecfc543ab8544d962 100644 (file)
@@ -1,6 +1,5 @@
 use crate::{
   activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::following::{follow::FollowCommunity, undo_follow::UndoFollowCommunity},
 };
@@ -8,6 +7,7 @@ use activitystreams::activity::kind::UndoType;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
   verify::verify_urls_match,
 };
index e23926f8cdb18953a504d4369cf1da69c047bcfa..920a531e98bcc0c346fde60c1ba80a038c1ba46b 100644 (file)
@@ -1,7 +1,6 @@
 use crate::{
   check_is_apub_id_valid,
   context::WithContext,
-  fetcher::object_id::ObjectId,
   generate_moderators_url,
   insert_activity,
   objects::{community::ApubCommunity, person::ApubPerson},
@@ -11,6 +10,7 @@ use anyhow::anyhow;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   activity_queue::send_activity,
+  object_id::ObjectId,
   traits::ActorType,
   verify::verify_domains_match,
 };
@@ -110,7 +110,7 @@ fn verify_add_remove_moderator_target(
   target: &Url,
   community: &ApubCommunity,
 ) -> Result<(), LemmyError> {
-  if target != &generate_moderators_url(&community.actor_id)?.into_inner() {
+  if target != &generate_moderators_url(&community.actor_id)?.into() {
     return Err(anyhow!("Unkown target url").into());
   }
   Ok(())
index e574dda9699f77fe62a610ef5d4b4a9213590432..925a778f2713745008df4bd20a9a9c399f179294 100644 (file)
@@ -9,7 +9,6 @@ use crate::{
     verify_person_in_community,
   },
   activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
   protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
 };
@@ -18,6 +17,7 @@ use anyhow::anyhow;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType, ApubObject},
   verify::{verify_domains_match, verify_urls_match},
 };
index 52b6fa74c3dfb83ee12567e52b1541258309f418..30599db8817fdb76901fa658f57cc6d50c4c6567 100644 (file)
@@ -1,6 +1,5 @@
 use crate::{
   activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
-  fetcher::object_id::ObjectId,
   objects::{person::ApubPerson, private_message::ApubPrivateMessage},
   protocol::activities::{
     private_message::create_or_update::CreateOrUpdatePrivateMessage,
@@ -10,6 +9,7 @@ use crate::{
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType, ApubObject},
   verify::verify_domains_match,
 };
index 4547b22b8125079173dd23f7a62fbfb2b3cafad5..46675442fe77650c5c375f56c6fe0b521a690975 100644 (file)
@@ -1,6 +1,5 @@
 use crate::{
   activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
-  fetcher::object_id::ObjectId,
   objects::{person::ApubPerson, private_message::ApubPrivateMessage},
   protocol::activities::private_message::delete::DeletePrivateMessage,
 };
@@ -8,6 +7,7 @@ use activitystreams::activity::kind::DeleteType;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
   verify::verify_domains_match,
 };
index 1272328b1fce828bd742b7c607f97ee059decd23..fbb8660c34ccc3301948da04f99cb2d02d9138ef 100644 (file)
@@ -1,6 +1,5 @@
 use crate::{
   activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
-  fetcher::object_id::ObjectId,
   objects::{person::ApubPerson, private_message::ApubPrivateMessage},
   protocol::activities::private_message::{
     delete::DeletePrivateMessage,
@@ -11,6 +10,7 @@ use activitystreams::activity::kind::UndoType;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
   verify::{verify_domains_match, verify_urls_match},
 };
index 786d51192a97b78995b6838240e32b6bcc64cf16..0fe40b628dc939308f6df67536a54a4b3f8d450c 100644 (file)
@@ -8,7 +8,6 @@ use crate::{
     voting::{undo_vote_comment, undo_vote_post},
   },
   activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::voting::{
     undo_vote::UndoVote,
@@ -20,6 +19,7 @@ use activitystreams::{activity::kind::UndoType, public};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
   verify::verify_urls_match,
 };
index 82b9b84e95e34d033fa24ce0427957c19e25963c..6b9bfbd2fc6859ad1a0fa18f212b9eb8404602f0 100644 (file)
@@ -8,7 +8,6 @@ use crate::{
     voting::{vote_comment, vote_post},
   },
   activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::voting::vote::{Vote, VoteType},
   PostOrComment,
@@ -17,6 +16,7 @@ use activitystreams::public;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
index d97affe2c169a4ca125d202c8f503974fdd30107..3579ed38ff84e18680b4dbfd7509348680c65d8f 100644 (file)
@@ -1,13 +1,12 @@
 use crate::{
   collections::CommunityContext,
-  fetcher::object_id::ObjectId,
   generate_moderators_url,
   objects::person::ApubPerson,
   protocol::collections::group_moderators::GroupModerators,
 };
 use activitystreams::{chrono::NaiveDateTime, collection::kind::OrderedCollectionType};
 use lemmy_api_common::blocking;
-use lemmy_apub_lib::{traits::ApubObject, verify::verify_domains_match};
+use lemmy_apub_lib::{object_id::ObjectId, traits::ApubObject, verify::verify_domains_match};
 use lemmy_db_schema::{
   source::community::{CommunityModerator, CommunityModeratorForm},
   traits::Joinable,
@@ -54,7 +53,7 @@ impl ApubObject for ApubCommunityModerators {
     let ordered_items = self
       .0
       .iter()
-      .map(|m| ObjectId::<ApubPerson>::new(m.moderator.actor_id.clone().into_inner()))
+      .map(|m| ObjectId::<ApubPerson>::new(m.moderator.actor_id.clone()))
       .collect();
     Ok(GroupModerators {
       r#type: OrderedCollectionType::OrderedCollection,
@@ -81,7 +80,7 @@ impl ApubObject for ApubCommunityModerators {
     .await??;
     // Remove old mods from database which arent in the moderators collection anymore
     for mod_user in &current_moderators {
-      let mod_id = ObjectId::new(mod_user.moderator.actor_id.clone().into_inner());
+      let mod_id = ObjectId::new(mod_user.moderator.actor_id.clone());
       if !apub.ordered_items.contains(&mod_id) {
         let community_moderator_form = CommunityModeratorForm {
           community_id: mod_user.community.id,
index 451c3fa941043727138cc7e5687ae18c11b1a413..96d0892cbfd3be22953ef5b4fd6fba13af1b7a8c 100644 (file)
@@ -1,7 +1,14 @@
+use crate::{
+  collections::CommunityContext,
+  generate_outbox_url,
+  objects::{person::ApubPerson, post::ApubPost},
+  protocol::{
+    activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
+    collections::group_outbox::GroupOutbox,
+  },
+};
 use activitystreams::collection::kind::OrderedCollectionType;
 use chrono::NaiveDateTime;
-use url::Url;
-
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
@@ -13,16 +20,7 @@ use lemmy_db_schema::{
   traits::Crud,
 };
 use lemmy_utils::LemmyError;
-
-use crate::{
-  collections::CommunityContext,
-  generate_outbox_url,
-  objects::{person::ApubPerson, post::ApubPost},
-  protocol::{
-    activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
-    collections::group_outbox::GroupOutbox,
-  },
-};
+use url::Url;
 
 #[derive(Clone, Debug)]
 pub(crate) struct ApubCommunityOutbox(Vec<ApubPost>);
index 8246f4ce6f48192e2ccd2b5574ff5c53c53ad876..d41ee4f71c140e9c6b5a0fb490241a2cb73f9886 100644 (file)
@@ -1,26 +1,3 @@
-pub mod object_id;
 pub mod post_or_comment;
 pub mod search;
 pub mod user_or_community;
-
-use chrono::NaiveDateTime;
-use lemmy_db_schema::naive_now;
-
-static ACTOR_REFETCH_INTERVAL_SECONDS: i64 = 24 * 60 * 60;
-static ACTOR_REFETCH_INTERVAL_SECONDS_DEBUG: i64 = 10;
-
-/// Determines when a remote actor should be refetched from its instance. In release builds, this is
-/// `ACTOR_REFETCH_INTERVAL_SECONDS` after the last refetch, in debug builds
-/// `ACTOR_REFETCH_INTERVAL_SECONDS_DEBUG`.
-///
-/// TODO it won't pick up new avatars, summaries etc until a day after.
-/// Actors need an "update" activity pushed to other servers to fix this.
-fn should_refetch_object(last_refreshed: NaiveDateTime) -> bool {
-  let update_interval = if cfg!(debug_assertions) {
-    // avoid infinite loop when fetching community outbox
-    chrono::Duration::seconds(ACTOR_REFETCH_INTERVAL_SECONDS_DEBUG)
-  } else {
-    chrono::Duration::seconds(ACTOR_REFETCH_INTERVAL_SECONDS)
-  };
-  last_refreshed.lt(&(naive_now() - update_interval))
-}
index 51699eb04d946c9f13566c1805fdd139c1126441..88027c5619aecce8c8b2fd1ec55e0481404131d8 100644 (file)
@@ -1,11 +1,13 @@
+use crate::{
+  objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
+  protocol::objects::{group::Group, note::Note, page::Page, person::Person},
+};
 use anyhow::anyhow;
 use chrono::NaiveDateTime;
 use itertools::Itertools;
-use serde::Deserialize;
-use url::Url;
-
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
+  object_id::ObjectId,
   traits::ApubObject,
   webfinger::{webfinger_resolve_actor, WebfingerType},
 };
@@ -15,12 +17,8 @@ use lemmy_db_schema::{
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
-
-use crate::{
-  fetcher::object_id::ObjectId,
-  objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
-  protocol::objects::{group::Group, note::Note, page::Page, person::Person},
-};
+use serde::Deserialize;
+use url::Url;
 
 /// Attempt to parse the query as URL, and fetch an ActivityPub object from it.
 ///
index c208f71edd191e60e54d85140c90951bfe4493f5..d9228ca53abbaa98a05c994c5bd08a3c6e51b3ea 100644 (file)
@@ -7,7 +7,6 @@ use crate::{
     CommunityContext,
   },
   context::WithContext,
-  fetcher::object_id::ObjectId,
   generate_outbox_url,
   http::{
     create_apub_response,
@@ -24,7 +23,7 @@ use crate::{
 };
 use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
 use lemmy_api_common::blocking;
-use lemmy_apub_lib::traits::ApubObject;
+use lemmy_apub_lib::{object_id::ObjectId, traits::ApubObject};
 use lemmy_db_schema::source::community::Community;
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
@@ -116,7 +115,7 @@ pub(crate) async fn get_apub_community_outbox(
     Community::read_from_name(conn, &info.community_name)
   })
   .await??;
-  let id = ObjectId::new(generate_outbox_url(&community.actor_id)?.into_inner());
+  let id = ObjectId::new(generate_outbox_url(&community.actor_id)?);
   let outbox_data = CommunityContext(community.into(), context.get_ref().clone());
   let outbox: ApubCommunityOutbox = id.dereference(&outbox_data, &mut 0).await?;
   Ok(create_apub_response(&outbox.to_apub(&outbox_data).await?))
@@ -131,7 +130,7 @@ pub(crate) async fn get_apub_community_moderators(
   })
   .await??
   .into();
-  let id = ObjectId::new(generate_outbox_url(&community.actor_id)?.into_inner());
+  let id = ObjectId::new(generate_outbox_url(&community.actor_id)?);
   let outbox_data = CommunityContext(community, context.get_ref().clone());
   let moderators: ApubCommunityModerators = id.dereference(&outbox_data, &mut 0).await?;
   Ok(create_apub_response(
index 450b937d58bd1fb88a9d29b27e2bf785f6bb23a2..03b68b94b8437057e71f87063434b320af9fc5f0 100644 (file)
@@ -2,7 +2,7 @@ use crate::{
   activity_lists::SharedInboxActivities,
   check_is_apub_id_valid,
   context::WithContext,
-  fetcher::{object_id::ObjectId, user_or_community::UserOrCommunity},
+  fetcher::user_or_community::UserOrCommunity,
   http::{community::receive_group_inbox, person::receive_person_inbox},
   insert_activity,
 };
@@ -19,6 +19,7 @@ use http::StatusCode;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
+  object_id::ObjectId,
   signatures::verify_signature,
   traits::{ActivityHandler, ActorType},
   APUB_JSON_CONTENT_TYPE,
index 68240728a670712c2523749c39a63fffda9aa395..09270fec8954442ece9749679bfa4586c6203791 100644 (file)
@@ -1,15 +1,25 @@
-use std::ops::Deref;
-
+use crate::{
+  activities::verify_person_in_community,
+  check_is_apub_id_valid,
+  protocol::{
+    objects::{
+      note::{Note, SourceCompat},
+      tombstone::Tombstone,
+    },
+    Source,
+  },
+  PostOrComment,
+};
 use activitystreams::{object::kind::NoteType, public};
 use anyhow::anyhow;
 use chrono::NaiveDateTime;
 use html2md::parse_html;
-use url::Url;
-
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
+  object_id::ObjectId,
   traits::ApubObject,
   values::{MediaTypeHtml, MediaTypeMarkdown},
+  verify::verify_domains_match,
 };
 use lemmy_db_schema::{
   source::{
@@ -21,26 +31,12 @@ use lemmy_db_schema::{
   traits::Crud,
 };
 use lemmy_utils::{
-  utils::{convert_datetime, remove_slurs},
+  utils::{convert_datetime, markdown_to_html, remove_slurs},
   LemmyError,
 };
 use lemmy_websocket::LemmyContext;
-
-use crate::{
-  activities::verify_person_in_community,
-  check_is_apub_id_valid,
-  fetcher::object_id::ObjectId,
-  protocol::{
-    objects::{
-      note::{Note, SourceCompat},
-      tombstone::Tombstone,
-    },
-    Source,
-  },
-  PostOrComment,
-};
-use lemmy_apub_lib::verify::verify_domains_match;
-use lemmy_utils::utils::markdown_to_html;
+use std::ops::Deref;
+use url::Url;
 
 #[derive(Clone, Debug)]
 pub struct ApubComment(Comment);
@@ -101,9 +97,9 @@ impl ApubObject for ApubComment {
     let in_reply_to = if let Some(comment_id) = self.parent_id {
       let parent_comment =
         blocking(context.pool(), move |conn| Comment::read(conn, comment_id)).await??;
-      ObjectId::<PostOrComment>::new(parent_comment.ap_id.into_inner())
+      ObjectId::<PostOrComment>::new(parent_comment.ap_id)
     } else {
-      ObjectId::<PostOrComment>::new(post.ap_id.into_inner())
+      ObjectId::<PostOrComment>::new(post.ap_id)
     };
 
     let note = Note {
@@ -235,7 +231,7 @@ pub(crate) mod tests {
       .await
       .unwrap();
 
-    assert_eq!(comment.ap_id.clone().into_inner(), url);
+    assert_eq!(comment.ap_id, url.into());
     assert_eq!(comment.content.len(), 14);
     assert!(!comment.local);
     assert_eq!(request_counter, 0);
@@ -267,7 +263,7 @@ pub(crate) mod tests {
       .await
       .unwrap();
 
-    assert_eq!(comment.ap_id.clone().into_inner(), pleroma_url);
+    assert_eq!(comment.ap_id, pleroma_url.into());
     assert_eq!(comment.content.len(), 64);
     assert!(!comment.local);
     assert_eq!(request_counter, 0);
index 8fd245dc231a271c512ce1b075b528e499d38f85..851563ab841eba2752941a38351cc2ee15ba92a0 100644 (file)
@@ -1,17 +1,6 @@
-use activitystreams::{
-  actor::{kind::GroupType, Endpoints},
-  object::kind::ImageType,
-};
-use chrono::NaiveDateTime;
-use itertools::Itertools;
-use log::debug;
-use std::ops::Deref;
-use url::Url;
-
 use crate::{
   check_is_apub_id_valid,
   collections::{community_moderators::ApubCommunityModerators, CommunityContext},
-  fetcher::object_id::ObjectId,
   generate_moderators_url,
   generate_outbox_url,
   protocol::{
@@ -20,8 +9,15 @@ use crate::{
     Source,
   },
 };
+use activitystreams::{
+  actor::{kind::GroupType, Endpoints},
+  object::kind::ImageType,
+};
+use chrono::NaiveDateTime;
+use itertools::Itertools;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
+  object_id::ObjectId,
   traits::{ActorType, ApubObject},
   values::MediaTypeMarkdown,
 };
@@ -32,6 +28,9 @@ use lemmy_utils::{
   LemmyError,
 };
 use lemmy_websocket::LemmyContext;
+use log::debug;
+use std::ops::Deref;
+use url::Url;
 
 #[derive(Clone, Debug)]
 pub struct ApubCommunity(Community);
@@ -105,7 +104,7 @@ impl ApubObject for ApubCommunity {
       image,
       sensitive: Some(self.nsfw),
       moderators: Some(ObjectId::<ApubCommunityModerators>::new(
-        generate_moderators_url(&self.actor_id)?.into_inner(),
+        generate_moderators_url(&self.actor_id)?,
       )),
       inbox: self.inbox_url.clone().into(),
       outbox: ObjectId::new(generate_outbox_url(&self.actor_id)?),
@@ -187,7 +186,7 @@ impl ActorType for ApubCommunity {
   }
 
   fn shared_inbox_url(&self) -> Option<Url> {
-    self.shared_inbox_url.clone().map(|s| s.into_inner())
+    self.shared_inbox_url.clone().map(|s| s.into())
   }
 }
 
@@ -207,8 +206,12 @@ impl ApubCommunity {
     let follower_inboxes: Vec<Url> = follows
       .into_iter()
       .filter(|f| !f.follower.local)
-      .map(|f| f.follower.shared_inbox_url.unwrap_or(f.follower.inbox_url))
-      .map(|i| i.into_inner())
+      .map(|f| {
+        f.follower
+          .shared_inbox_url
+          .unwrap_or(f.follower.inbox_url)
+          .into()
+      })
       .collect();
     let inboxes = vec![follower_inboxes, additional_inboxes]
       .into_iter()
index 652ef62205469717785850940225c93abf0ed755..f1da655080b1482a79995351f0c984f5d14b273b 100644 (file)
@@ -1,6 +1,5 @@
 use crate::{
   check_is_apub_id_valid,
-  fetcher::object_id::ObjectId,
   generate_outbox_url,
   objects::get_summary_from_string_or_source,
   protocol::{
@@ -13,6 +12,7 @@ use activitystreams::{actor::Endpoints, object::kind::ImageType};
 use chrono::NaiveDateTime;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
+  object_id::ObjectId,
   traits::{ActorType, ApubObject},
   values::MediaTypeMarkdown,
   verify::verify_domains_match,
@@ -181,7 +181,7 @@ impl ActorType for ApubPerson {
     self.local
   }
   fn actor_id(&self) -> Url {
-    self.actor_id.to_owned().into_inner()
+    self.actor_id.to_owned().into()
   }
   fn name(&self) -> String {
     self.name.clone()
@@ -200,7 +200,7 @@ impl ActorType for ApubPerson {
   }
 
   fn shared_inbox_url(&self) -> Option<Url> {
-    self.shared_inbox_url.clone().map(|s| s.into_inner())
+    self.shared_inbox_url.clone().map(|s| s.into())
   }
 }
 
@@ -247,7 +247,7 @@ pub(crate) mod tests {
       .await
       .unwrap();
 
-    assert_eq!(person.actor_id.clone().into_inner(), url);
+    assert_eq!(person.actor_id, url.into());
     assert_eq!(person.name, "lanodan");
     assert!(person.public_key.is_some());
     assert!(!person.local);
index b29bdb8017516b88727c4534a594d928b0cbe8ab..0ba80724d2829e9eb64dea7fcdb547301c636615 100644 (file)
@@ -1,7 +1,6 @@
 use crate::{
   activities::verify_person_in_community,
   check_is_apub_id_valid,
-  fetcher::object_id::ObjectId,
   protocol::{
     objects::{page::Page, tombstone::Tombstone},
     ImageObject,
@@ -15,6 +14,7 @@ use activitystreams::{
 use chrono::NaiveDateTime;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
+  object_id::ObjectId,
   traits::ApubObject,
   values::{MediaTypeHtml, MediaTypeMarkdown},
   verify::verify_domains_match,
@@ -217,7 +217,7 @@ mod tests {
       .await
       .unwrap();
 
-    assert_eq!(post.ap_id.clone().into_inner(), url);
+    assert_eq!(post.ap_id, url.into());
     assert_eq!(post.name, "Post title");
     assert!(post.body.is_some());
     assert_eq!(post.body.as_ref().unwrap().len(), 45);
index 5c4befb05c480778428686be50180b0bc03b73cf..00b3a26cb2470f6c3d8e871ebf27fcf902905fe6 100644 (file)
@@ -1,14 +1,12 @@
-use crate::{
-  fetcher::object_id::ObjectId,
-  protocol::{
-    objects::chat_message::{ChatMessage, ChatMessageType},
-    Source,
-  },
+use crate::protocol::{
+  objects::chat_message::{ChatMessage, ChatMessageType},
+  Source,
 };
 use chrono::NaiveDateTime;
 use html2md::parse_html;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
+  object_id::ObjectId,
   traits::ApubObject,
   values::{MediaTypeHtml, MediaTypeMarkdown},
   verify::verify_domains_match,
@@ -180,7 +178,7 @@ mod tests {
       .await
       .unwrap();
 
-    assert_eq!(pm.ap_id.clone().into_inner(), url);
+    assert_eq!(pm.ap_id.clone(), url.into());
     assert_eq!(pm.content.len(), 20);
     assert_eq!(request_counter, 0);
 
@@ -204,7 +202,7 @@ mod tests {
       .await
       .unwrap();
 
-    assert_eq!(pm.ap_id.clone().into_inner(), pleroma_url);
+    assert_eq!(pm.ap_id, pleroma_url.into());
     assert_eq!(pm.content.len(), 3);
     assert_eq!(request_counter, 0);
 
index 6938f01d456f8d21ec38474c1399b96c97f24084..75571bea8f07b49b0956d817ef25e4026527352d 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{fetcher::object_id::ObjectId, objects::person::ApubPerson};
+use crate::objects::person::ApubPerson;
 use activitystreams::{activity::kind::AddType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 07fbda635f533b33277913b16d1956b5ae62b4e0..2dd094041768c30af3c9f6a5db312281e249a255 100644 (file)
@@ -1,9 +1,6 @@
-use crate::{
-  activity_lists::AnnouncableActivities,
-  fetcher::object_id::ObjectId,
-  objects::community::ApubCommunity,
-};
+use crate::{activity_lists::AnnouncableActivities, objects::community::ApubCommunity};
 use activitystreams::{activity::kind::AnnounceType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index ec95e6e9b0696dc068112a90a848e8e5cc8725f0..0b974f697fcef17ff8c6d5a5bc9ca024320019e8 100644 (file)
@@ -1,8 +1,6 @@
-use crate::{
-  fetcher::object_id::ObjectId,
-  objects::{community::ApubCommunity, person::ApubPerson},
-};
+use crate::objects::{community::ApubCommunity, person::ApubPerson};
 use activitystreams::{activity::kind::BlockType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index cca263549676f24c303fb23c5d123e127501a2ee..6e3e5458c14b6b581afd6f90ff77aeab42ac1172 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{fetcher::object_id::ObjectId, objects::person::ApubPerson};
+use crate::objects::person::ApubPerson;
 use activitystreams::{activity::kind::RemoveType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index d10a9d285a41c413e210a1cbea8568d0fa1728bf..fbf21ec8d344a90ff04819e4d36e02d1a7a8a594 100644 (file)
@@ -1,8 +1,9 @@
 use crate::{
-  fetcher::{object_id::ObjectId, post_or_comment::PostOrComment},
+  fetcher::post_or_comment::PostOrComment,
   objects::{community::ApubCommunity, person::ApubPerson},
 };
 use activitystreams::{activity::kind::FlagType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 24356fab28856151602dbc85e022c63a99d94303..538a7e25c51b60bb4ac3f0371ba0f4338f3d62c7 100644 (file)
@@ -1,9 +1,9 @@
 use crate::{
-  fetcher::object_id::ObjectId,
   objects::person::ApubPerson,
   protocol::activities::community::block_user::BlockUserFromCommunity,
 };
 use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 686938aa487f8df649a4245429130fc3b7cee00b..b9877338a6bf425b075b9ec2d6a05797e69757bc 100644 (file)
@@ -1,9 +1,6 @@
-use crate::{
-  fetcher::object_id::ObjectId,
-  objects::person::ApubPerson,
-  protocol::objects::group::Group,
-};
+use crate::{objects::person::ApubPerson, protocol::objects::group::Group};
 use activitystreams::{activity::kind::UpdateType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 4e5b412d7db530f7f428ff77e5fb33f4977a30fc..6e90dedb0de1bb270c08d90d0b6646d2f3501997 100644 (file)
@@ -1,9 +1,9 @@
 use crate::{
-  fetcher::object_id::ObjectId,
   objects::person::ApubPerson,
   protocol::{activities::CreateOrUpdateType, objects::note::Note},
 };
 use activitystreams::{link::Mention, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index b1851c0d9d2af6be7bec457edf765d2a5ab183c0..e64e48408b6ec9a3b7ff637254c2b0d9cb797dbc 100644 (file)
@@ -1,9 +1,9 @@
 use crate::{
-  fetcher::object_id::ObjectId,
   objects::person::ApubPerson,
   protocol::{activities::CreateOrUpdateType, objects::page::Page},
 };
 use activitystreams::unparsed::Unparsed;
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index af50227994df63e2aa905dcd8d8b7d58c7b129e6..7e2275153f23a51ee2661c083b5798f0e567a628 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{fetcher::object_id::ObjectId, objects::person::ApubPerson};
+use crate::objects::person::ApubPerson;
 use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use serde_with::skip_serializing_none;
 use url::Url;
index 8a30546e56ec064926a526380baf32c0b9569d2d..aa851cbc73db30ebdecb5d376ffcdc3b3f560c9e 100644 (file)
@@ -1,9 +1,6 @@
-use crate::{
-  fetcher::object_id::ObjectId,
-  objects::person::ApubPerson,
-  protocol::activities::deletion::delete::Delete,
-};
+use crate::{objects::person::ApubPerson, protocol::activities::deletion::delete::Delete};
 use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 7eeb3a41843258d4450122bd89bd9fb93373b7e3..0c5988bc7a15263bbe84203227f0ea03cb16ed9c 100644 (file)
@@ -1,9 +1,9 @@
 use crate::{
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::following::follow::FollowCommunity,
 };
 use activitystreams::{activity::kind::AcceptType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 651ab1d2d223cf5db7a9681c3089078b9b334622..9d3f6a823032eecf089df11685e51251a9464007 100644 (file)
@@ -1,8 +1,6 @@
-use crate::{
-  fetcher::object_id::ObjectId,
-  objects::{community::ApubCommunity, person::ApubPerson},
-};
+use crate::objects::{community::ApubCommunity, person::ApubPerson};
 use activitystreams::{activity::kind::FollowType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 3abeabd296b708a6709d3f9d3372298e28186bee..5e9c58946ead996f933403c1103cd50115e830d2 100644 (file)
@@ -1,9 +1,9 @@
 use crate::{
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::following::follow::FollowCommunity,
 };
 use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 5092a1640f3124dd57de59823c0af20dc2ba80db..756bfd5e908b59e3d0c19980e6835acbde094676 100644 (file)
@@ -1,9 +1,9 @@
 use crate::{
-  fetcher::object_id::ObjectId,
   objects::person::ApubPerson,
   protocol::{activities::CreateOrUpdateType, objects::chat_message::ChatMessage},
 };
 use activitystreams::unparsed::Unparsed;
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 87da3c310ab5b05441762244748230df4c6096b8..f9ad29fdefaa92f8b6388a24d664622ab272eeef 100644 (file)
@@ -1,8 +1,6 @@
-use crate::{
-  fetcher::object_id::ObjectId,
-  objects::{person::ApubPerson, private_message::ApubPrivateMessage},
-};
+use crate::objects::{person::ApubPerson, private_message::ApubPrivateMessage};
 use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 16d82492c2b3703e6da1bff56c94273d607c58cc..951f14d4a9fd71f0a30e0d9b2780047adf1a9242 100644 (file)
@@ -1,9 +1,9 @@
 use crate::{
-  fetcher::object_id::ObjectId,
   objects::person::ApubPerson,
   protocol::activities::private_message::delete::DeletePrivateMessage,
 };
 use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 05606dbe99062b083b3e34fca8180c563529ee27..c6c8f0b030a1e6f55ec9aa880b7c94660b21a757 100644 (file)
@@ -1,9 +1,6 @@
-use crate::{
-  fetcher::object_id::ObjectId,
-  objects::person::ApubPerson,
-  protocol::activities::voting::vote::Vote,
-};
+use crate::{objects::person::ApubPerson, protocol::activities::voting::vote::Vote};
 use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 6d82ccc42c6ae4d841b343f7065781face728f59..977a549dbc58ace61f41bb702ed1bc1f7fa75a02 100644 (file)
@@ -1,9 +1,7 @@
-use crate::{
-  fetcher::{object_id::ObjectId, post_or_comment::PostOrComment},
-  objects::person::ApubPerson,
-};
+use crate::{fetcher::post_or_comment::PostOrComment, objects::person::ApubPerson};
 use activitystreams::unparsed::Unparsed;
 use anyhow::anyhow;
+use lemmy_apub_lib::object_id::ObjectId;
 use lemmy_utils::LemmyError;
 use serde::{Deserialize, Serialize};
 use std::convert::TryFrom;
index d3df5e22b1a84ba7dd9b7aec95162485f27dd6f4..55b92a76cbf0a95eb0d7b0f6a38617a9c96fbc05 100644 (file)
@@ -29,7 +29,7 @@ impl GroupFollowers {
     .await??;
 
     Ok(GroupFollowers {
-      id: generate_followers_url(&community.actor_id)?.into_inner(),
+      id: generate_followers_url(&community.actor_id)?.into(),
       r#type: CollectionType::Collection,
       total_items: community_followers.len() as i32,
       items: vec![],
index d37751a1685b46e5a8c243185943839da8847cb2..9b8494849f9a91e4355e81f2feecbd73a4fdd0a9 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{fetcher::object_id::ObjectId, objects::person::ApubPerson};
+use crate::objects::person::ApubPerson;
 use activitystreams::collection::kind::OrderedCollectionType;
+use lemmy_apub_lib::object_id::ObjectId;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 6ec758403ca6325bb4e1e17057a7934da03d1aa4..c8af0173baf1f222c6ee1d88ef0b82d97253a079 100644 (file)
@@ -18,7 +18,7 @@ impl PersonOutbox {
   pub(crate) async fn new(user: Person) -> Result<PersonOutbox, LemmyError> {
     Ok(PersonOutbox {
       r#type: OrderedCollectionType::OrderedCollection,
-      id: generate_outbox_url(&user.actor_id)?.into_inner(),
+      id: generate_outbox_url(&user.actor_id)?.into(),
       ordered_items: vec![],
       total_items: 0,
     })
index e9677758cbae55bedfc38f17553ae805d49eb11f..3a019967e944249a221ae4d0686bdd701dde9103 100644 (file)
@@ -1,5 +1,4 @@
 use crate::{
-  fetcher::object_id::ObjectId,
   objects::{person::ApubPerson, private_message::ApubPrivateMessage},
   protocol::Source,
 };
@@ -8,7 +7,7 @@ use activitystreams::{
   unparsed::Unparsed,
 };
 use anyhow::anyhow;
-use lemmy_apub_lib::{values::MediaTypeHtml, verify::verify_domains_match};
+use lemmy_apub_lib::{object_id::ObjectId, values::MediaTypeHtml, verify::verify_domains_match};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
 use serde::{Deserialize, Serialize};
index 921a5dc8d48222c99284388dc1f16b9404f78934..dbc823748bcbef77c89223053d383d1ba34e8e90 100644 (file)
@@ -4,7 +4,6 @@ use crate::{
     community_moderators::ApubCommunityModerators,
     community_outbox::ApubCommunityOutbox,
   },
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, get_summary_from_string_or_source},
   protocol::{ImageObject, Source},
 };
@@ -13,7 +12,7 @@ use activitystreams::{
   unparsed::Unparsed,
 };
 use chrono::{DateTime, FixedOffset};
-use lemmy_apub_lib::{signatures::PublicKey, verify::verify_domains_match};
+use lemmy_apub_lib::{object_id::ObjectId, signatures::PublicKey, verify::verify_domains_match};
 use lemmy_db_schema::{naive_now, source::community::CommunityForm};
 use lemmy_utils::{
   settings::structs::Settings,
@@ -73,6 +72,7 @@ impl Group {
     check_slurs(&title, slur_regex)?;
     check_slurs_opt(&description, slur_regex)?;
 
+    // TODO: test_parse_lemmy_community_moderators() keeps failing here with stack overflow
     Ok(CommunityForm {
       name,
       title,
index 58b164a7da9be845a4dd95870d734a5f55a086c9..34cb6bed0c52bc5e8256edb92c4bd8f2e5812a36 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   activities::{verify_is_public, verify_person_in_community},
-  fetcher::{object_id::ObjectId, post_or_comment::PostOrComment},
+  fetcher::post_or_comment::PostOrComment,
   objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
   protocol::Source,
 };
@@ -8,7 +8,7 @@ use activitystreams::{object::kind::NoteType, unparsed::Unparsed};
 use anyhow::anyhow;
 use chrono::{DateTime, FixedOffset};
 use lemmy_api_common::blocking;
-use lemmy_apub_lib::{values::MediaTypeHtml, verify::verify_domains_match};
+use lemmy_apub_lib::{object_id::ObjectId, values::MediaTypeHtml, verify::verify_domains_match};
 use lemmy_db_schema::{
   newtypes::CommentId,
   source::{community::Community, post::Post},
index 0cd004799b2701a689ec0bcbae6c494d558bc1ac..285a0e04eb043a29daa450b847c414bb0e93d8b1 100644 (file)
@@ -1,13 +1,12 @@
 use crate::{
   activities::{verify_is_public, verify_person_in_community},
-  fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
   protocol::{ImageObject, Source},
 };
 use activitystreams::{object::kind::PageType, unparsed::Unparsed};
 use anyhow::anyhow;
 use chrono::{DateTime, FixedOffset};
-use lemmy_apub_lib::{values::MediaTypeHtml, verify::verify_domains_match};
+use lemmy_apub_lib::{object_id::ObjectId, values::MediaTypeHtml, verify::verify_domains_match};
 use lemmy_utils::{utils::check_slurs, LemmyError};
 use lemmy_websocket::LemmyContext;
 use serde::{Deserialize, Serialize};
index 720e7de00383b072e95719d7ae6bfe19adca2dd5..cf9c10b1f941fb52d9ef92558848a4013d43eb00 100644 (file)
@@ -1,11 +1,10 @@
 use crate::{
-  fetcher::object_id::ObjectId,
   objects::person::ApubPerson,
   protocol::{ImageObject, Source},
 };
 use activitystreams::{actor::Endpoints, unparsed::Unparsed, url::Url};
 use chrono::{DateTime, FixedOffset};
-use lemmy_apub_lib::signatures::PublicKey;
+use lemmy_apub_lib::{object_id::ObjectId, signatures::PublicKey};
 use serde::{Deserialize, Serialize};
 use serde_with::skip_serializing_none;
 
index c3835a12e8f86ed4475b83893dcf95cee0561603..f3ef989cfd1cb3c68ef3dcc416c248b081aa0d84 100644 (file)
@@ -27,3 +27,4 @@ actix-web = { version = "4.0.0-beta.9", default-features = false }
 http-signature-normalization-actix = { version = "0.5.0-beta.10", default-features = false, features = ["server", "sha-2"] }
 http-signature-normalization-reqwest = { version = "0.2.0", default-features = false, features = ["sha-2"] }
 background-jobs = "0.9.1"
+diesel = "1.4.8"
index a35f54415699891de093a946c2524f525faf29ea..c65baee53ebbd07e9e73d15cc86743e297b4dfcd 100644 (file)
@@ -3,6 +3,7 @@ extern crate lazy_static;
 
 pub mod activity_queue;
 pub mod data;
+pub mod object_id;
 pub mod signatures;
 pub mod traits;
 pub mod values;
similarity index 74%
rename from crates/apub/src/fetcher/object_id.rs
rename to crates/apub_lib/src/object_id.rs
index 5c5c518f4b85afe6e5afa2272fc0093bd8c1d94b..fe55a44aa92b35960a68033764434bde02a1e3f2 100644 (file)
@@ -1,8 +1,7 @@
-use crate::fetcher::should_refetch_object;
+use crate::{traits::ApubObject, APUB_JSON_CONTENT_TYPE};
+use activitystreams::chrono::{Duration as ChronoDuration, NaiveDateTime, Utc};
 use anyhow::anyhow;
 use diesel::NotFound;
-use lemmy_apub_lib::{traits::ApubObject, APUB_JSON_CONTENT_TYPE};
-use lemmy_db_schema::newtypes::DbUrl;
 use lemmy_utils::{
   request::{build_user_agent, retry},
   settings::structs::Settings,
@@ -144,12 +143,34 @@ where
   }
 }
 
+static ACTOR_REFETCH_INTERVAL_SECONDS: i64 = 24 * 60 * 60;
+static ACTOR_REFETCH_INTERVAL_SECONDS_DEBUG: i64 = 10;
+
+/// Determines when a remote actor should be refetched from its instance. In release builds, this is
+/// `ACTOR_REFETCH_INTERVAL_SECONDS` after the last refetch, in debug builds
+/// `ACTOR_REFETCH_INTERVAL_SECONDS_DEBUG`.
+///
+/// TODO it won't pick up new avatars, summaries etc until a day after.
+/// Actors need an "update" activity pushed to other servers to fix this.
+fn should_refetch_object(last_refreshed: NaiveDateTime) -> bool {
+  let update_interval = if cfg!(debug_assertions) {
+    // avoid infinite loop when fetching community outbox
+    ChronoDuration::seconds(ACTOR_REFETCH_INTERVAL_SECONDS_DEBUG)
+  } else {
+    ChronoDuration::seconds(ACTOR_REFETCH_INTERVAL_SECONDS)
+  };
+  let refresh_limit = Utc::now().naive_utc() - update_interval;
+  last_refreshed.lt(&refresh_limit)
+}
+
 impl<Kind> Display for ObjectId<Kind>
 where
   Kind: ApubObject + Send + 'static,
   for<'de2> <Kind as ApubObject>::ApubType: serde::Deserialize<'de2>,
 {
+  #[allow(clippy::to_string_in_display)]
   fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+    // Use to_string here because Url.display is not useful for us
     write!(f, "{}", self.0.to_string())
   }
 }
@@ -164,12 +185,17 @@ where
   }
 }
 
-impl<Kind> From<ObjectId<Kind>> for DbUrl
-where
-  Kind: ApubObject + Send + 'static,
-  for<'de2> <Kind as ApubObject>::ApubType: serde::Deserialize<'de2>,
-{
-  fn from(id: ObjectId<Kind>) -> Self {
-    id.0.into()
+#[cfg(test)]
+mod tests {
+  use super::*;
+  use crate::object_id::should_refetch_object;
+
+  #[test]
+  fn test_should_refetch_object() {
+    let one_second_ago = Utc::now().naive_utc() - ChronoDuration::seconds(1);
+    assert!(!should_refetch_object(one_second_ago));
+
+    let two_days_ago = Utc::now().naive_utc() - ChronoDuration::days(2);
+    assert!(should_refetch_object(two_days_ago));
   }
 }
index 21212835f957fd8fccdb8a89bac06773316b39bb..025f590d47976807e450e513cfd6f0174ce1c4fa 100644 (file)
@@ -12,6 +12,7 @@ doctest = false
 
 [dependencies]
 lemmy_utils = { version = "=0.13.5-rc.7", path = "../utils" }
+lemmy_apub_lib = { version = "=0.13.5-rc.7", path = "../apub_lib" }
 diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] }
 diesel_migrations = "1.4.0"
 chrono = { version = "0.4.19", features = ["serde"] }
index 3042d35e71bf492f803db2fb1cf52af342e6de61..9219d77f9797fc63874fab9da293fea2007a6836 100644 (file)
@@ -4,6 +4,7 @@ use diesel::{
   serialize::{Output, ToSql},
   sql_types::Text,
 };
+use lemmy_apub_lib::{object_id::ObjectId, traits::ApubObject};
 use serde::{Deserialize, Serialize};
 use std::{
   fmt,
@@ -93,27 +94,32 @@ where
   }
 }
 
-impl DbUrl {
-  // TODO: remove this method and just use into()
-  pub fn into_inner(self) -> Url {
-    self.0
-  }
-}
-
 impl Display for DbUrl {
   fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
     self.to_owned().0.fmt(f)
   }
 }
 
-impl From<DbUrl> for Url {
-  fn from(url: DbUrl) -> Self {
-    url.0
+// the project doesnt compile with From
+#[allow(clippy::from_over_into)]
+impl Into<DbUrl> for Url {
+  fn into(self) -> DbUrl {
+    DbUrl(self)
+  }
+}
+#[allow(clippy::from_over_into)]
+impl Into<Url> for DbUrl {
+  fn into(self) -> Url {
+    self.0
   }
 }
 
-impl From<Url> for DbUrl {
-  fn from(url: Url) -> Self {
-    DbUrl(url)
+impl<Kind> From<ObjectId<Kind>> for DbUrl
+where
+  Kind: ApubObject + Send + 'static,
+  for<'de2> <Kind as ApubObject>::ApubType: serde::Deserialize<'de2>,
+{
+  fn from(id: ObjectId<Kind>) -> Self {
+    DbUrl(id.into())
   }
 }