From: Felix Ableitner Date: Fri, 5 Nov 2021 00:24:10 +0000 (+0100) Subject: Move ObjectId to library X-Git-Url: http://these/git/%22https:/nerdica.net/photo/contact/80/README.ja.md?a=commitdiff_plain;h=2edf8ba1576d67234d1129cd97b131c0654a54f7;p=lemmy.git Move ObjectId to library --- diff --git a/Cargo.lock b/Cargo.lock index d4127752..8fb76293 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/crates/api/src/comment_report.rs b/crates/api/src/comment_report.rs index 82ecc1f4..f1bf7023 100644 --- a/crates/api/src/comment_report.rs +++ b/crates/api/src/comment_report.rs @@ -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 { diff --git a/crates/api/src/post_report.rs b/crates/api/src/post_report.rs index 98b2f1c1..0e47f592 100644 --- a/crates/api/src/post_report.rs +++ b/crates/api/src/post_report.rs @@ -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 { diff --git a/crates/api_crud/src/community/create.rs b/crates/api_crud/src/community/create.rs index 523ccf00..b91cab43 100644 --- a/crates/api_crud/src/community/create.rs +++ b/crates/api_crud/src/community/create.rs @@ -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::{ diff --git a/crates/api_crud/src/community/read.rs b/crates/api_crud/src/community/read.rs index feaf110f..47c0058c 100644 --- a/crates/api_crud/src/community/read.rs +++ b/crates/api_crud/src/community/read.rs @@ -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, diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 99b67d2e..4b5c9e73 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -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::(updated_post.ap_id.clone().into(), url.clone().into())?; webmention.set_checked(true); match webmention.send().await { Ok(_) => {} diff --git a/crates/api_crud/src/user/read.rs b/crates/api_crud/src/user/read.rs index b649c8fb..41db9f99 100644 --- a/crates/api_crud/src/user/read.rs +++ b/crates/api_crud/src/user/read.rs @@ -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::{ diff --git a/crates/apub/src/activities/comment/create_or_update.rs b/crates/apub/src/activities/comment/create_or_update.rs index 84f6d3f2..0d12c4b3 100644 --- a/crates/apub/src/activities/comment/create_or_update.rs +++ b/crates/apub/src/activities/comment/create_or_update.rs @@ -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, }; diff --git a/crates/apub/src/activities/comment/mod.rs b/crates/apub/src/activities/comment/mod.rs index 9eb2bb44..1a3f7d3a 100644 --- a/crates/apub/src/activities/comment/mod.rs +++ b/crates/apub/src/activities/comment/mod.rs @@ -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}, diff --git a/crates/apub/src/activities/community/add_mod.rs b/crates/apub/src/activities/community/add_mod.rs index 11dc5a0b..8dad8609 100644 --- a/crates/apub/src/activities/community/add_mod.rs +++ b/crates/apub/src/activities/community/add_mod.rs @@ -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::{ diff --git a/crates/apub/src/activities/community/announce.rs b/crates/apub/src/activities/community/announce.rs index b245a1b8..1fcce837 100644 --- a/crates/apub/src/activities/community/announce.rs +++ b/crates/apub/src/activities/community/announce.rs @@ -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, diff --git a/crates/apub/src/activities/community/block_user.rs b/crates/apub/src/activities/community/block_user.rs index d756ed25..851c96fd 100644 --- a/crates/apub/src/activities/community/block_user.rs +++ b/crates/apub/src/activities/community/block_user.rs @@ -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::{ diff --git a/crates/apub/src/activities/community/mod.rs b/crates/apub/src/activities/community/mod.rs index 96e692d5..b63c8b65 100644 --- a/crates/apub/src/activities/community/mod.rs +++ b/crates/apub/src/activities/community/mod.rs @@ -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; diff --git a/crates/apub/src/activities/community/remove_mod.rs b/crates/apub/src/activities/community/remove_mod.rs index 1c79e70d..c5edf333 100644 --- a/crates/apub/src/activities/community/remove_mod.rs +++ b/crates/apub/src/activities/community/remove_mod.rs @@ -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::{ diff --git a/crates/apub/src/activities/community/report.rs b/crates/apub/src/activities/community/report.rs index 5b02490b..f0be3e0a 100644 --- a/crates/apub/src/activities/community/report.rs +++ b/crates/apub/src/activities/community/report.rs @@ -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::{ diff --git a/crates/apub/src/activities/community/undo_block_user.rs b/crates/apub/src/activities/community/undo_block_user.rs index 467237eb..bb4c0358 100644 --- a/crates/apub/src/activities/community/undo_block_user.rs +++ b/crates/apub/src/activities/community/undo_block_user.rs @@ -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::{ diff --git a/crates/apub/src/activities/community/update.rs b/crates/apub/src/activities/community/update.rs index 9acb8909..45b08e02 100644 --- a/crates/apub/src/activities/community/update.rs +++ b/crates/apub/src/activities/community/update.rs @@ -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::{ diff --git a/crates/apub/src/activities/deletion/delete.rs b/crates/apub/src/activities/deletion/delete.rs index 605daf8f..6e217498 100644 --- a/crates/apub/src/activities/deletion/delete.rs +++ b/crates/apub/src/activities/deletion/delete.rs @@ -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::{ diff --git a/crates/apub/src/activities/deletion/mod.rs b/crates/apub/src/activities/deletion/mod.rs index 1be3bccf..ddd607a7 100644 --- a/crates/apub/src/activities/deletion/mod.rs +++ b/crates/apub/src/activities/deletion/mod.rs @@ -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, }; diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index 93338a3f..b3e44af2 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -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}; diff --git a/crates/apub/src/activities/following/accept.rs b/crates/apub/src/activities/following/accept.rs index 68c8ca45..44d6009a 100644 --- a/crates/apub/src/activities/following/accept.rs +++ b/crates/apub/src/activities/following/accept.rs @@ -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, }; diff --git a/crates/apub/src/activities/following/follow.rs b/crates/apub/src/activities/following/follow.rs index 30c77fe8..22f3db4b 100644 --- a/crates/apub/src/activities/following/follow.rs +++ b/crates/apub/src/activities/following/follow.rs @@ -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, }; diff --git a/crates/apub/src/activities/following/undo_follow.rs b/crates/apub/src/activities/following/undo_follow.rs index bdc5a4b0..ac25fcd5 100644 --- a/crates/apub/src/activities/following/undo_follow.rs +++ b/crates/apub/src/activities/following/undo_follow.rs @@ -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, }; diff --git a/crates/apub/src/activities/mod.rs b/crates/apub/src/activities/mod.rs index e23926f8..920a531e 100644 --- a/crates/apub/src/activities/mod.rs +++ b/crates/apub/src/activities/mod.rs @@ -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(()) diff --git a/crates/apub/src/activities/post/create_or_update.rs b/crates/apub/src/activities/post/create_or_update.rs index e574dda9..925a778f 100644 --- a/crates/apub/src/activities/post/create_or_update.rs +++ b/crates/apub/src/activities/post/create_or_update.rs @@ -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}, }; diff --git a/crates/apub/src/activities/private_message/create_or_update.rs b/crates/apub/src/activities/private_message/create_or_update.rs index 52b6fa74..30599db8 100644 --- a/crates/apub/src/activities/private_message/create_or_update.rs +++ b/crates/apub/src/activities/private_message/create_or_update.rs @@ -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, }; diff --git a/crates/apub/src/activities/private_message/delete.rs b/crates/apub/src/activities/private_message/delete.rs index 4547b22b..46675442 100644 --- a/crates/apub/src/activities/private_message/delete.rs +++ b/crates/apub/src/activities/private_message/delete.rs @@ -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, }; diff --git a/crates/apub/src/activities/private_message/undo_delete.rs b/crates/apub/src/activities/private_message/undo_delete.rs index 1272328b..fbb8660c 100644 --- a/crates/apub/src/activities/private_message/undo_delete.rs +++ b/crates/apub/src/activities/private_message/undo_delete.rs @@ -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}, }; diff --git a/crates/apub/src/activities/voting/undo_vote.rs b/crates/apub/src/activities/voting/undo_vote.rs index 786d5119..0fe40b62 100644 --- a/crates/apub/src/activities/voting/undo_vote.rs +++ b/crates/apub/src/activities/voting/undo_vote.rs @@ -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, }; diff --git a/crates/apub/src/activities/voting/vote.rs b/crates/apub/src/activities/voting/vote.rs index 82b9b84e..6b9bfbd2 100644 --- a/crates/apub/src/activities/voting/vote.rs +++ b/crates/apub/src/activities/voting/vote.rs @@ -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::{ diff --git a/crates/apub/src/collections/community_moderators.rs b/crates/apub/src/collections/community_moderators.rs index d97affe2..3579ed38 100644 --- a/crates/apub/src/collections/community_moderators.rs +++ b/crates/apub/src/collections/community_moderators.rs @@ -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::::new(m.moderator.actor_id.clone().into_inner())) + .map(|m| ObjectId::::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 ¤t_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, diff --git a/crates/apub/src/collections/community_outbox.rs b/crates/apub/src/collections/community_outbox.rs index 451c3fa9..96d0892c 100644 --- a/crates/apub/src/collections/community_outbox.rs +++ b/crates/apub/src/collections/community_outbox.rs @@ -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); diff --git a/crates/apub/src/fetcher/mod.rs b/crates/apub/src/fetcher/mod.rs index 8246f4ce..d41ee4f7 100644 --- a/crates/apub/src/fetcher/mod.rs +++ b/crates/apub/src/fetcher/mod.rs @@ -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)) -} diff --git a/crates/apub/src/fetcher/search.rs b/crates/apub/src/fetcher/search.rs index 51699eb0..88027c56 100644 --- a/crates/apub/src/fetcher/search.rs +++ b/crates/apub/src/fetcher/search.rs @@ -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. /// diff --git a/crates/apub/src/http/community.rs b/crates/apub/src/http/community.rs index c208f71e..d9228ca5 100644 --- a/crates/apub/src/http/community.rs +++ b/crates/apub/src/http/community.rs @@ -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( diff --git a/crates/apub/src/http/mod.rs b/crates/apub/src/http/mod.rs index 450b937d..03b68b94 100644 --- a/crates/apub/src/http/mod.rs +++ b/crates/apub/src/http/mod.rs @@ -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, diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index 68240728..09270fec 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -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::::new(parent_comment.ap_id.into_inner()) + ObjectId::::new(parent_comment.ap_id) } else { - ObjectId::::new(post.ap_id.into_inner()) + ObjectId::::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); diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 8fd245dc..851563ab 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -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::::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 { - 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 = 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() diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index 652ef622..f1da6550 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -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 { - 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); diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index b29bdb80..0ba80724 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -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); diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs index 5c4befb0..00b3a26c 100644 --- a/crates/apub/src/objects/private_message.rs +++ b/crates/apub/src/objects/private_message.rs @@ -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); diff --git a/crates/apub/src/protocol/activities/community/add_mod.rs b/crates/apub/src/protocol/activities/community/add_mod.rs index 6938f01d..75571bea 100644 --- a/crates/apub/src/protocol/activities/community/add_mod.rs +++ b/crates/apub/src/protocol/activities/community/add_mod.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/community/announce.rs b/crates/apub/src/protocol/activities/community/announce.rs index 07fbda63..2dd09404 100644 --- a/crates/apub/src/protocol/activities/community/announce.rs +++ b/crates/apub/src/protocol/activities/community/announce.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/community/block_user.rs b/crates/apub/src/protocol/activities/community/block_user.rs index ec95e6e9..0b974f69 100644 --- a/crates/apub/src/protocol/activities/community/block_user.rs +++ b/crates/apub/src/protocol/activities/community/block_user.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/community/remove_mod.rs b/crates/apub/src/protocol/activities/community/remove_mod.rs index cca26354..6e3e5458 100644 --- a/crates/apub/src/protocol/activities/community/remove_mod.rs +++ b/crates/apub/src/protocol/activities/community/remove_mod.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/community/report.rs b/crates/apub/src/protocol/activities/community/report.rs index d10a9d28..fbf21ec8 100644 --- a/crates/apub/src/protocol/activities/community/report.rs +++ b/crates/apub/src/protocol/activities/community/report.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/community/undo_block_user.rs b/crates/apub/src/protocol/activities/community/undo_block_user.rs index 24356fab..538a7e25 100644 --- a/crates/apub/src/protocol/activities/community/undo_block_user.rs +++ b/crates/apub/src/protocol/activities/community/undo_block_user.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/community/update.rs b/crates/apub/src/protocol/activities/community/update.rs index 686938aa..b9877338 100644 --- a/crates/apub/src/protocol/activities/community/update.rs +++ b/crates/apub/src/protocol/activities/community/update.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/create_or_update/comment.rs b/crates/apub/src/protocol/activities/create_or_update/comment.rs index 4e5b412d..6e90dedb 100644 --- a/crates/apub/src/protocol/activities/create_or_update/comment.rs +++ b/crates/apub/src/protocol/activities/create_or_update/comment.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/create_or_update/post.rs b/crates/apub/src/protocol/activities/create_or_update/post.rs index b1851c0d..e64e4840 100644 --- a/crates/apub/src/protocol/activities/create_or_update/post.rs +++ b/crates/apub/src/protocol/activities/create_or_update/post.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/deletion/delete.rs b/crates/apub/src/protocol/activities/deletion/delete.rs index af502279..7e227515 100644 --- a/crates/apub/src/protocol/activities/deletion/delete.rs +++ b/crates/apub/src/protocol/activities/deletion/delete.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/deletion/undo_delete.rs b/crates/apub/src/protocol/activities/deletion/undo_delete.rs index 8a30546e..aa851cbc 100644 --- a/crates/apub/src/protocol/activities/deletion/undo_delete.rs +++ b/crates/apub/src/protocol/activities/deletion/undo_delete.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/following/accept.rs b/crates/apub/src/protocol/activities/following/accept.rs index 7eeb3a41..0c5988bc 100644 --- a/crates/apub/src/protocol/activities/following/accept.rs +++ b/crates/apub/src/protocol/activities/following/accept.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/following/follow.rs b/crates/apub/src/protocol/activities/following/follow.rs index 651ab1d2..9d3f6a82 100644 --- a/crates/apub/src/protocol/activities/following/follow.rs +++ b/crates/apub/src/protocol/activities/following/follow.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/following/undo_follow.rs b/crates/apub/src/protocol/activities/following/undo_follow.rs index 3abeabd2..5e9c5894 100644 --- a/crates/apub/src/protocol/activities/following/undo_follow.rs +++ b/crates/apub/src/protocol/activities/following/undo_follow.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/private_message/create_or_update.rs b/crates/apub/src/protocol/activities/private_message/create_or_update.rs index 5092a164..756bfd5e 100644 --- a/crates/apub/src/protocol/activities/private_message/create_or_update.rs +++ b/crates/apub/src/protocol/activities/private_message/create_or_update.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/private_message/delete.rs b/crates/apub/src/protocol/activities/private_message/delete.rs index 87da3c31..f9ad29fd 100644 --- a/crates/apub/src/protocol/activities/private_message/delete.rs +++ b/crates/apub/src/protocol/activities/private_message/delete.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/private_message/undo_delete.rs b/crates/apub/src/protocol/activities/private_message/undo_delete.rs index 16d82492..951f14d4 100644 --- a/crates/apub/src/protocol/activities/private_message/undo_delete.rs +++ b/crates/apub/src/protocol/activities/private_message/undo_delete.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/voting/undo_vote.rs b/crates/apub/src/protocol/activities/voting/undo_vote.rs index 05606dbe..c6c8f0b0 100644 --- a/crates/apub/src/protocol/activities/voting/undo_vote.rs +++ b/crates/apub/src/protocol/activities/voting/undo_vote.rs @@ -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; diff --git a/crates/apub/src/protocol/activities/voting/vote.rs b/crates/apub/src/protocol/activities/voting/vote.rs index 6d82ccc4..977a549d 100644 --- a/crates/apub/src/protocol/activities/voting/vote.rs +++ b/crates/apub/src/protocol/activities/voting/vote.rs @@ -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; diff --git a/crates/apub/src/protocol/collections/group_followers.rs b/crates/apub/src/protocol/collections/group_followers.rs index d3df5e22..55b92a76 100644 --- a/crates/apub/src/protocol/collections/group_followers.rs +++ b/crates/apub/src/protocol/collections/group_followers.rs @@ -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![], diff --git a/crates/apub/src/protocol/collections/group_moderators.rs b/crates/apub/src/protocol/collections/group_moderators.rs index d37751a1..9b849484 100644 --- a/crates/apub/src/protocol/collections/group_moderators.rs +++ b/crates/apub/src/protocol/collections/group_moderators.rs @@ -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; diff --git a/crates/apub/src/protocol/collections/person_outbox.rs b/crates/apub/src/protocol/collections/person_outbox.rs index 6ec75840..c8af0173 100644 --- a/crates/apub/src/protocol/collections/person_outbox.rs +++ b/crates/apub/src/protocol/collections/person_outbox.rs @@ -18,7 +18,7 @@ impl PersonOutbox { pub(crate) async fn new(user: Person) -> Result { 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, }) diff --git a/crates/apub/src/protocol/objects/chat_message.rs b/crates/apub/src/protocol/objects/chat_message.rs index e9677758..3a019967 100644 --- a/crates/apub/src/protocol/objects/chat_message.rs +++ b/crates/apub/src/protocol/objects/chat_message.rs @@ -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}; diff --git a/crates/apub/src/protocol/objects/group.rs b/crates/apub/src/protocol/objects/group.rs index 921a5dc8..dbc82374 100644 --- a/crates/apub/src/protocol/objects/group.rs +++ b/crates/apub/src/protocol/objects/group.rs @@ -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, diff --git a/crates/apub/src/protocol/objects/note.rs b/crates/apub/src/protocol/objects/note.rs index 58b164a7..34cb6bed 100644 --- a/crates/apub/src/protocol/objects/note.rs +++ b/crates/apub/src/protocol/objects/note.rs @@ -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}, diff --git a/crates/apub/src/protocol/objects/page.rs b/crates/apub/src/protocol/objects/page.rs index 0cd00479..285a0e04 100644 --- a/crates/apub/src/protocol/objects/page.rs +++ b/crates/apub/src/protocol/objects/page.rs @@ -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}; diff --git a/crates/apub/src/protocol/objects/person.rs b/crates/apub/src/protocol/objects/person.rs index 720e7de0..cf9c10b1 100644 --- a/crates/apub/src/protocol/objects/person.rs +++ b/crates/apub/src/protocol/objects/person.rs @@ -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; diff --git a/crates/apub_lib/Cargo.toml b/crates/apub_lib/Cargo.toml index c3835a12..f3ef989c 100644 --- a/crates/apub_lib/Cargo.toml +++ b/crates/apub_lib/Cargo.toml @@ -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" diff --git a/crates/apub_lib/src/lib.rs b/crates/apub_lib/src/lib.rs index a35f5441..c65baee5 100644 --- a/crates/apub_lib/src/lib.rs +++ b/crates/apub_lib/src/lib.rs @@ -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; diff --git a/crates/apub/src/fetcher/object_id.rs b/crates/apub_lib/src/object_id.rs similarity index 74% rename from crates/apub/src/fetcher/object_id.rs rename to crates/apub_lib/src/object_id.rs index 5c5c518f..fe55a44a 100644 --- a/crates/apub/src/fetcher/object_id.rs +++ b/crates/apub_lib/src/object_id.rs @@ -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 Display for ObjectId where Kind: ApubObject + Send + 'static, for<'de2> ::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 From> for DbUrl -where - Kind: ApubObject + Send + 'static, - for<'de2> ::ApubType: serde::Deserialize<'de2>, -{ - fn from(id: ObjectId) -> 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)); } } diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index 21212835..025f590d 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -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"] } diff --git a/crates/db_schema/src/newtypes.rs b/crates/db_schema/src/newtypes.rs index 3042d35e..9219d77f 100644 --- a/crates/db_schema/src/newtypes.rs +++ b/crates/db_schema/src/newtypes.rs @@ -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 for Url { - fn from(url: DbUrl) -> Self { - url.0 +// the project doesnt compile with From +#[allow(clippy::from_over_into)] +impl Into for Url { + fn into(self) -> DbUrl { + DbUrl(self) + } +} +#[allow(clippy::from_over_into)] +impl Into for DbUrl { + fn into(self) -> Url { + self.0 } } -impl From for DbUrl { - fn from(url: Url) -> Self { - DbUrl(url) +impl From> for DbUrl +where + Kind: ApubObject + Send + 'static, + for<'de2> ::ApubType: serde::Deserialize<'de2>, +{ + fn from(id: ObjectId) -> Self { + DbUrl(id.into()) } }