Move ObjectId to library

pull/1877/head
Felix Ableitner 2021-11-05 01:24:10 +01:00
parent bd3352423a
commit 2edf8ba157
73 changed files with 222 additions and 255 deletions

2
Cargo.lock generated
View File

@ -1869,6 +1869,7 @@ dependencies = [
"async-trait", "async-trait",
"background-jobs", "background-jobs",
"base64 0.13.0", "base64 0.13.0",
"diesel",
"http", "http",
"http-signature-normalization-actix", "http-signature-normalization-actix",
"http-signature-normalization-reqwest", "http-signature-normalization-reqwest",
@ -1904,6 +1905,7 @@ dependencies = [
"diesel-derive-newtype", "diesel-derive-newtype",
"diesel_migrations", "diesel_migrations",
"lazy_static", "lazy_static",
"lemmy_apub_lib",
"lemmy_utils", "lemmy_utils",
"log", "log",
"regex", "regex",

View File

@ -1,5 +1,5 @@
use crate::Perform;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{ use lemmy_api_common::{
blocking, blocking,
check_community_ban, check_community_ban,
@ -7,7 +7,8 @@ use lemmy_api_common::{
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
is_mod_or_admin, 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_schema::{source::comment_report::*, traits::Reportable};
use lemmy_db_views::{ use lemmy_db_views::{
comment_report_view::{CommentReportQueryBuilder, CommentReportView}, comment_report_view::{CommentReportQueryBuilder, CommentReportView},
@ -16,8 +17,6 @@ use lemmy_db_views::{
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation}; use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
use crate::Perform;
/// Creates a comment report and notifies the moderators of the community /// Creates a comment report and notifies the moderators of the community
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl Perform for CreateCommentReport { impl Perform for CreateCommentReport {

View File

@ -1,5 +1,5 @@
use crate::Perform;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{ use lemmy_api_common::{
blocking, blocking,
check_community_ban, check_community_ban,
@ -13,7 +13,8 @@ use lemmy_api_common::{
ResolvePostReport, 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::{ use lemmy_db_schema::{
source::post_report::{PostReport, PostReportForm}, source::post_report::{PostReport, PostReportForm},
traits::Reportable, traits::Reportable,
@ -25,8 +26,6 @@ use lemmy_db_views::{
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation}; use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
use crate::Perform;
/// Creates a post report and notifies the moderators of the community /// Creates a post report and notifies the moderators of the community
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl Perform for CreatePostReport { impl Perform for CreatePostReport {

View File

@ -7,7 +7,6 @@ use lemmy_api_common::{
is_admin, is_admin,
}; };
use lemmy_apub::{ use lemmy_apub::{
fetcher::object_id::ObjectId,
generate_followers_url, generate_followers_url,
generate_inbox_url, generate_inbox_url,
generate_local_apub_endpoint, generate_local_apub_endpoint,
@ -15,6 +14,7 @@ use lemmy_apub::{
objects::community::ApubCommunity, objects::community::ApubCommunity,
EndpointType, EndpointType,
}; };
use lemmy_apub_lib::object_id::ObjectId;
use lemmy_db_schema::{ use lemmy_db_schema::{
diesel_option_overwrite_to_url, diesel_option_overwrite_to_url,
source::{ source::{

View File

@ -1,12 +1,8 @@
use crate::PerformCrud; use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt_opt}; use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt_opt};
use lemmy_apub::{ use lemmy_apub::{get_actor_id_from_name, objects::community::ApubCommunity};
fetcher::object_id::ObjectId, use lemmy_apub_lib::{object_id::ObjectId, webfinger::WebfingerType};
get_actor_id_from_name,
objects::community::ApubCommunity,
};
use lemmy_apub_lib::webfinger::WebfingerType;
use lemmy_db_schema::{ use lemmy_db_schema::{
from_opt_str_to_opt_enum, from_opt_str_to_opt_enum,
traits::DeleteableOrRemoveable, traits::DeleteableOrRemoveable,

View File

@ -1,7 +1,5 @@
use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use log::warn;
use webmention::{Webmention, WebmentionError};
use lemmy_api_common::{ use lemmy_api_common::{
blocking, blocking,
check_community_ban, check_community_ban,
@ -33,8 +31,9 @@ use lemmy_utils::{
LemmyError, LemmyError,
}; };
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
use log::warn;
use crate::PerformCrud; use url::Url;
use webmention::{Webmention, WebmentionError};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for CreatePost { impl PerformCrud for CreatePost {
@ -136,10 +135,8 @@ impl PerformCrud for CreatePost {
mark_post_as_read(person_id, post_id, context.pool()).await?; mark_post_as_read(person_id, post_id, context.pool()).await?;
if let Some(url) = &updated_post.url { if let Some(url) = &updated_post.url {
let mut webmention = Webmention::new( let mut webmention =
updated_post.ap_id.clone().into_inner(), Webmention::new::<Url>(updated_post.ap_id.clone().into(), url.clone().into())?;
url.clone().into_inner(),
)?;
webmention.set_checked(true); webmention.set_checked(true);
match webmention.send().await { match webmention.send().await {
Ok(_) => {} Ok(_) => {}

View File

@ -1,12 +1,8 @@
use crate::PerformCrud; use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, person::*}; use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, person::*};
use lemmy_apub::{ use lemmy_apub::{get_actor_id_from_name, objects::person::ApubPerson};
fetcher::object_id::ObjectId, use lemmy_apub_lib::{object_id::ObjectId, webfinger::WebfingerType};
get_actor_id_from_name,
objects::person::ApubPerson,
};
use lemmy_apub_lib::webfinger::WebfingerType;
use lemmy_db_schema::{from_opt_str_to_opt_enum, SortType}; 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::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder};
use lemmy_db_views_actor::{ use lemmy_db_views_actor::{

View File

@ -9,7 +9,6 @@ use crate::{
verify_person_in_community, verify_person_in_community,
}, },
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson}, objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson},
protocol::activities::{create_or_update::comment::CreateOrUpdateComment, CreateOrUpdateType}, 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_api_common::{blocking, check_post_deleted_or_removed};
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType, ApubObject}, traits::{ActivityHandler, ActorType, ApubObject},
verify::verify_domains_match, verify::verify_domains_match,
}; };

View File

@ -1,7 +1,4 @@
use crate::{ use crate::objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson};
fetcher::object_id::ObjectId,
objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson},
};
use activitystreams::{ use activitystreams::{
base::BaseExt, base::BaseExt,
link::{LinkExt, Mention}, link::{LinkExt, Mention},
@ -9,7 +6,7 @@ use activitystreams::{
use anyhow::anyhow; use anyhow::anyhow;
use itertools::Itertools; use itertools::Itertools;
use lemmy_api_common::blocking; 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::{ use lemmy_db_schema::{
newtypes::LocalUserId, newtypes::LocalUserId,
source::{comment::Comment, person::Person, post::Post}, source::{comment::Comment, person::Person, post::Post},

View File

@ -9,7 +9,6 @@ use crate::{
verify_person_in_community, verify_person_in_community,
}, },
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
generate_moderators_url, generate_moderators_url,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::community::add_mod::AddMod, protocol::activities::community::add_mod::AddMod,
@ -18,6 +17,7 @@ use activitystreams::{activity::kind::AddType, public};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{

View File

@ -1,7 +1,6 @@
use crate::{ use crate::{
activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_is_public}, activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_is_public},
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
http::{is_activity_already_known, ActivityCommonFields}, http::{is_activity_already_known, ActivityCommonFields},
insert_activity, insert_activity,
objects::community::ApubCommunity, objects::community::ApubCommunity,
@ -10,6 +9,7 @@ use crate::{
use activitystreams::{activity::kind::AnnounceType, public}; use activitystreams::{activity::kind::AnnounceType, public};
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
@ -36,7 +36,7 @@ impl AnnounceActivity {
actor: ObjectId::new(community.actor_id()), actor: ObjectId::new(community.actor_id()),
to: vec![public()], to: vec![public()],
object, object,
cc: vec![community.followers_url.clone().into_inner()], cc: vec![community.followers_url.clone().into()],
kind: AnnounceType::Announce, kind: AnnounceType::Announce,
id: generate_activity_id( id: generate_activity_id(
&AnnounceType::Announce, &AnnounceType::Announce,

View File

@ -8,7 +8,6 @@ use crate::{
verify_person_in_community, verify_person_in_community,
}, },
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::community::block_user::BlockUserFromCommunity, protocol::activities::community::block_user::BlockUserFromCommunity,
}; };
@ -16,6 +15,7 @@ use activitystreams::{activity::kind::BlockType, public};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{

View File

@ -1,12 +1,11 @@
use crate::{ use crate::{
activities::send_lemmy_activity, activities::send_lemmy_activity,
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
insert_activity, insert_activity,
objects::community::ApubCommunity, objects::community::ApubCommunity,
protocol::activities::community::announce::AnnounceActivity, 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_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;

View File

@ -9,7 +9,6 @@ use crate::{
verify_person_in_community, verify_person_in_community,
}, },
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
generate_moderators_url, generate_moderators_url,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::community::remove_mod::RemoveMod, protocol::activities::community::remove_mod::RemoveMod,
@ -18,6 +17,7 @@ use activitystreams::{activity::kind::RemoveType, public};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{

View File

@ -5,7 +5,6 @@ use crate::{
verify_activity, verify_activity,
verify_person_in_community, verify_person_in_community,
}, },
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::community::report::Report, protocol::activities::community::report::Report,
PostOrComment, PostOrComment,
@ -14,6 +13,7 @@ use activitystreams::activity::kind::FlagType;
use lemmy_api_common::{blocking, comment::CommentReportResponse, post::PostReportResponse}; use lemmy_api_common::{blocking, comment::CommentReportResponse, post::PostReportResponse};
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{

View File

@ -8,7 +8,6 @@ use crate::{
verify_person_in_community, verify_person_in_community,
}, },
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::community::{ protocol::activities::community::{
block_user::BlockUserFromCommunity, block_user::BlockUserFromCommunity,
@ -19,6 +18,7 @@ use activitystreams::{activity::kind::UndoType, public};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{

View File

@ -8,7 +8,6 @@ use crate::{
verify_person_in_community, verify_person_in_community,
}, },
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::{activities::community::update::UpdateCommunity, objects::group::Group}, 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_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType, ApubObject}, traits::{ActivityHandler, ActorType, ApubObject},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{

View File

@ -1,17 +1,12 @@
use crate::{ use crate::{
activities::{ activities::{
community::{announce::GetCommunity, send_to_community}, community::{announce::GetCommunity, send_to_community},
deletion::{ deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
receive_delete_action,
verify_delete_activity,
DeletableObjects,
},
generate_activity_id, generate_activity_id,
verify_activity, verify_activity,
verify_is_public, verify_is_public,
}, },
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::deletion::delete::Delete, protocol::activities::deletion::delete::Delete,
}; };
@ -20,6 +15,7 @@ use anyhow::anyhow;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{

View File

@ -1,11 +1,11 @@
use crate::{ use crate::{
activities::{verify_mod_action, verify_person_in_community}, activities::{verify_mod_action, verify_person_in_community},
fetcher::object_id::ObjectId,
objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost}, objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete}, protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
}; };
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
object_id::ObjectId,
traits::{ActorType, ApubObject}, traits::{ActorType, ApubObject},
verify::verify_domains_match, verify::verify_domains_match,
}; };

View File

@ -7,7 +7,6 @@ use crate::{
verify_is_public, verify_is_public,
}, },
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete}, protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
}; };
@ -16,6 +15,7 @@ use anyhow::anyhow;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post}; use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};

View File

@ -1,12 +1,12 @@
use crate::{ use crate::{
activities::{generate_activity_id, send_lemmy_activity, verify_activity}, activities::{generate_activity_id, send_lemmy_activity, verify_activity},
fetcher::object_id::ObjectId,
protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity}, protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity},
}; };
use activitystreams::activity::kind::AcceptType; use activitystreams::activity::kind::AcceptType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
verify::verify_urls_match, verify::verify_urls_match,
}; };

View File

@ -6,7 +6,6 @@ use crate::{
verify_person, verify_person,
verify_person_in_community, verify_person_in_community,
}, },
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity}, protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity},
}; };
@ -14,6 +13,7 @@ use activitystreams::activity::kind::FollowType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
verify::verify_urls_match, verify::verify_urls_match,
}; };

View File

@ -1,6 +1,5 @@
use crate::{ use crate::{
activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person}, activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::following::{follow::FollowCommunity, undo_follow::UndoFollowCommunity}, protocol::activities::following::{follow::FollowCommunity, undo_follow::UndoFollowCommunity},
}; };
@ -8,6 +7,7 @@ use activitystreams::activity::kind::UndoType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
verify::verify_urls_match, verify::verify_urls_match,
}; };

View File

@ -1,7 +1,6 @@
use crate::{ use crate::{
check_is_apub_id_valid, check_is_apub_id_valid,
context::WithContext, context::WithContext,
fetcher::object_id::ObjectId,
generate_moderators_url, generate_moderators_url,
insert_activity, insert_activity,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
@ -11,6 +10,7 @@ use anyhow::anyhow;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
activity_queue::send_activity, activity_queue::send_activity,
object_id::ObjectId,
traits::ActorType, traits::ActorType,
verify::verify_domains_match, verify::verify_domains_match,
}; };
@ -110,7 +110,7 @@ fn verify_add_remove_moderator_target(
target: &Url, target: &Url,
community: &ApubCommunity, community: &ApubCommunity,
) -> Result<(), LemmyError> { ) -> 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()); return Err(anyhow!("Unkown target url").into());
} }
Ok(()) Ok(())

View File

@ -9,7 +9,6 @@ use crate::{
verify_person_in_community, verify_person_in_community,
}, },
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost}, objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType}, protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
}; };
@ -18,6 +17,7 @@ use anyhow::anyhow;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType, ApubObject}, traits::{ActivityHandler, ActorType, ApubObject},
verify::{verify_domains_match, verify_urls_match}, verify::{verify_domains_match, verify_urls_match},
}; };

View File

@ -1,6 +1,5 @@
use crate::{ use crate::{
activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person}, activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
fetcher::object_id::ObjectId,
objects::{person::ApubPerson, private_message::ApubPrivateMessage}, objects::{person::ApubPerson, private_message::ApubPrivateMessage},
protocol::activities::{ protocol::activities::{
private_message::create_or_update::CreateOrUpdatePrivateMessage, private_message::create_or_update::CreateOrUpdatePrivateMessage,
@ -10,6 +9,7 @@ use crate::{
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType, ApubObject}, traits::{ActivityHandler, ActorType, ApubObject},
verify::verify_domains_match, verify::verify_domains_match,
}; };

View File

@ -1,6 +1,5 @@
use crate::{ use crate::{
activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person}, activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
fetcher::object_id::ObjectId,
objects::{person::ApubPerson, private_message::ApubPrivateMessage}, objects::{person::ApubPerson, private_message::ApubPrivateMessage},
protocol::activities::private_message::delete::DeletePrivateMessage, protocol::activities::private_message::delete::DeletePrivateMessage,
}; };
@ -8,6 +7,7 @@ use activitystreams::activity::kind::DeleteType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
verify::verify_domains_match, verify::verify_domains_match,
}; };

View File

@ -1,6 +1,5 @@
use crate::{ use crate::{
activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person}, activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
fetcher::object_id::ObjectId,
objects::{person::ApubPerson, private_message::ApubPrivateMessage}, objects::{person::ApubPerson, private_message::ApubPrivateMessage},
protocol::activities::private_message::{ protocol::activities::private_message::{
delete::DeletePrivateMessage, delete::DeletePrivateMessage,
@ -11,6 +10,7 @@ use activitystreams::activity::kind::UndoType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
verify::{verify_domains_match, verify_urls_match}, verify::{verify_domains_match, verify_urls_match},
}; };

View File

@ -8,7 +8,6 @@ use crate::{
voting::{undo_vote_comment, undo_vote_post}, voting::{undo_vote_comment, undo_vote_post},
}, },
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::voting::{ protocol::activities::voting::{
undo_vote::UndoVote, undo_vote::UndoVote,
@ -20,6 +19,7 @@ use activitystreams::{activity::kind::UndoType, public};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
verify::verify_urls_match, verify::verify_urls_match,
}; };

View File

@ -8,7 +8,6 @@ use crate::{
voting::{vote_comment, vote_post}, voting::{vote_comment, vote_post},
}, },
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::voting::vote::{Vote, VoteType}, protocol::activities::voting::vote::{Vote, VoteType},
PostOrComment, PostOrComment,
@ -17,6 +16,7 @@ use activitystreams::public;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{

View File

@ -1,13 +1,12 @@
use crate::{ use crate::{
collections::CommunityContext, collections::CommunityContext,
fetcher::object_id::ObjectId,
generate_moderators_url, generate_moderators_url,
objects::person::ApubPerson, objects::person::ApubPerson,
protocol::collections::group_moderators::GroupModerators, protocol::collections::group_moderators::GroupModerators,
}; };
use activitystreams::{chrono::NaiveDateTime, collection::kind::OrderedCollectionType}; use activitystreams::{chrono::NaiveDateTime, collection::kind::OrderedCollectionType};
use lemmy_api_common::blocking; 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::{ use lemmy_db_schema::{
source::community::{CommunityModerator, CommunityModeratorForm}, source::community::{CommunityModerator, CommunityModeratorForm},
traits::Joinable, traits::Joinable,
@ -54,7 +53,7 @@ impl ApubObject for ApubCommunityModerators {
let ordered_items = self let ordered_items = self
.0 .0
.iter() .iter()
.map(|m| ObjectId::<ApubPerson>::new(m.moderator.actor_id.clone().into_inner())) .map(|m| ObjectId::<ApubPerson>::new(m.moderator.actor_id.clone()))
.collect(); .collect();
Ok(GroupModerators { Ok(GroupModerators {
r#type: OrderedCollectionType::OrderedCollection, r#type: OrderedCollectionType::OrderedCollection,
@ -81,7 +80,7 @@ impl ApubObject for ApubCommunityModerators {
.await??; .await??;
// Remove old mods from database which arent in the moderators collection anymore // Remove old mods from database which arent in the moderators collection anymore
for mod_user in &current_moderators { 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) { if !apub.ordered_items.contains(&mod_id) {
let community_moderator_form = CommunityModeratorForm { let community_moderator_form = CommunityModeratorForm {
community_id: mod_user.community.id, community_id: mod_user.community.id,

View 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 activitystreams::collection::kind::OrderedCollectionType;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use url::Url;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -13,16 +20,7 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use url::Url;
use crate::{
collections::CommunityContext,
generate_outbox_url,
objects::{person::ApubPerson, post::ApubPost},
protocol::{
activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
collections::group_outbox::GroupOutbox,
},
};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct ApubCommunityOutbox(Vec<ApubPost>); pub(crate) struct ApubCommunityOutbox(Vec<ApubPost>);

View File

@ -1,26 +1,3 @@
pub mod object_id;
pub mod post_or_comment; pub mod post_or_comment;
pub mod search; pub mod search;
pub mod user_or_community; 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))
}

View 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 anyhow::anyhow;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use itertools::Itertools; use itertools::Itertools;
use serde::Deserialize;
use url::Url;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
object_id::ObjectId,
traits::ApubObject, traits::ApubObject,
webfinger::{webfinger_resolve_actor, WebfingerType}, webfinger::{webfinger_resolve_actor, WebfingerType},
}; };
@ -15,12 +17,8 @@ use lemmy_db_schema::{
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::Deserialize;
use crate::{ use url::Url;
fetcher::object_id::ObjectId,
objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
protocol::objects::{group::Group, note::Note, page::Page, person::Person},
};
/// Attempt to parse the query as URL, and fetch an ActivityPub object from it. /// Attempt to parse the query as URL, and fetch an ActivityPub object from it.
/// ///

View File

@ -7,7 +7,6 @@ use crate::{
CommunityContext, CommunityContext,
}, },
context::WithContext, context::WithContext,
fetcher::object_id::ObjectId,
generate_outbox_url, generate_outbox_url,
http::{ http::{
create_apub_response, create_apub_response,
@ -24,7 +23,7 @@ use crate::{
}; };
use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse}; use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
use lemmy_api_common::blocking; 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_db_schema::source::community::Community;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
@ -116,7 +115,7 @@ pub(crate) async fn get_apub_community_outbox(
Community::read_from_name(conn, &info.community_name) Community::read_from_name(conn, &info.community_name)
}) })
.await??; .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_data = CommunityContext(community.into(), context.get_ref().clone());
let outbox: ApubCommunityOutbox = id.dereference(&outbox_data, &mut 0).await?; let outbox: ApubCommunityOutbox = id.dereference(&outbox_data, &mut 0).await?;
Ok(create_apub_response(&outbox.to_apub(&outbox_data).await?)) Ok(create_apub_response(&outbox.to_apub(&outbox_data).await?))
@ -131,7 +130,7 @@ pub(crate) async fn get_apub_community_moderators(
}) })
.await?? .await??
.into(); .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 outbox_data = CommunityContext(community, context.get_ref().clone());
let moderators: ApubCommunityModerators = id.dereference(&outbox_data, &mut 0).await?; let moderators: ApubCommunityModerators = id.dereference(&outbox_data, &mut 0).await?;
Ok(create_apub_response( Ok(create_apub_response(

View File

@ -2,7 +2,7 @@ use crate::{
activity_lists::SharedInboxActivities, activity_lists::SharedInboxActivities,
check_is_apub_id_valid, check_is_apub_id_valid,
context::WithContext, context::WithContext,
fetcher::{object_id::ObjectId, user_or_community::UserOrCommunity}, fetcher::user_or_community::UserOrCommunity,
http::{community::receive_group_inbox, person::receive_person_inbox}, http::{community::receive_group_inbox, person::receive_person_inbox},
insert_activity, insert_activity,
}; };
@ -19,6 +19,7 @@ use http::StatusCode;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
object_id::ObjectId,
signatures::verify_signature, signatures::verify_signature,
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
APUB_JSON_CONTENT_TYPE, APUB_JSON_CONTENT_TYPE,

View 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 activitystreams::{object::kind::NoteType, public};
use anyhow::anyhow; use anyhow::anyhow;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use html2md::parse_html; use html2md::parse_html;
use url::Url;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
object_id::ObjectId,
traits::ApubObject, traits::ApubObject,
values::{MediaTypeHtml, MediaTypeMarkdown}, values::{MediaTypeHtml, MediaTypeMarkdown},
verify::verify_domains_match,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{
@ -21,26 +31,12 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_utils::{ use lemmy_utils::{
utils::{convert_datetime, remove_slurs}, utils::{convert_datetime, markdown_to_html, remove_slurs},
LemmyError, LemmyError,
}; };
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use std::ops::Deref;
use crate::{ use url::Url;
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;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct ApubComment(Comment); 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 in_reply_to = if let Some(comment_id) = self.parent_id {
let parent_comment = let parent_comment =
blocking(context.pool(), move |conn| Comment::read(conn, comment_id)).await??; 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 { } else {
ObjectId::<PostOrComment>::new(post.ap_id.into_inner()) ObjectId::<PostOrComment>::new(post.ap_id)
}; };
let note = Note { let note = Note {
@ -235,7 +231,7 @@ pub(crate) mod tests {
.await .await
.unwrap(); .unwrap();
assert_eq!(comment.ap_id.clone().into_inner(), url); assert_eq!(comment.ap_id, url.into());
assert_eq!(comment.content.len(), 14); assert_eq!(comment.content.len(), 14);
assert!(!comment.local); assert!(!comment.local);
assert_eq!(request_counter, 0); assert_eq!(request_counter, 0);
@ -267,7 +263,7 @@ pub(crate) mod tests {
.await .await
.unwrap(); .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_eq!(comment.content.len(), 64);
assert!(!comment.local); assert!(!comment.local);
assert_eq!(request_counter, 0); assert_eq!(request_counter, 0);

View 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::{ use crate::{
check_is_apub_id_valid, check_is_apub_id_valid,
collections::{community_moderators::ApubCommunityModerators, CommunityContext}, collections::{community_moderators::ApubCommunityModerators, CommunityContext},
fetcher::object_id::ObjectId,
generate_moderators_url, generate_moderators_url,
generate_outbox_url, generate_outbox_url,
protocol::{ protocol::{
@ -20,8 +9,15 @@ use crate::{
Source, Source,
}, },
}; };
use activitystreams::{
actor::{kind::GroupType, Endpoints},
object::kind::ImageType,
};
use chrono::NaiveDateTime;
use itertools::Itertools;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
object_id::ObjectId,
traits::{ActorType, ApubObject}, traits::{ActorType, ApubObject},
values::MediaTypeMarkdown, values::MediaTypeMarkdown,
}; };
@ -32,6 +28,9 @@ use lemmy_utils::{
LemmyError, LemmyError,
}; };
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use log::debug;
use std::ops::Deref;
use url::Url;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct ApubCommunity(Community); pub struct ApubCommunity(Community);
@ -105,7 +104,7 @@ impl ApubObject for ApubCommunity {
image, image,
sensitive: Some(self.nsfw), sensitive: Some(self.nsfw),
moderators: Some(ObjectId::<ApubCommunityModerators>::new( 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(), inbox: self.inbox_url.clone().into(),
outbox: ObjectId::new(generate_outbox_url(&self.actor_id)?), outbox: ObjectId::new(generate_outbox_url(&self.actor_id)?),
@ -187,7 +186,7 @@ impl ActorType for ApubCommunity {
} }
fn shared_inbox_url(&self) -> Option<Url> { 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 let follower_inboxes: Vec<Url> = follows
.into_iter() .into_iter()
.filter(|f| !f.follower.local) .filter(|f| !f.follower.local)
.map(|f| f.follower.shared_inbox_url.unwrap_or(f.follower.inbox_url)) .map(|f| {
.map(|i| i.into_inner()) f.follower
.shared_inbox_url
.unwrap_or(f.follower.inbox_url)
.into()
})
.collect(); .collect();
let inboxes = vec![follower_inboxes, additional_inboxes] let inboxes = vec![follower_inboxes, additional_inboxes]
.into_iter() .into_iter()

View File

@ -1,6 +1,5 @@
use crate::{ use crate::{
check_is_apub_id_valid, check_is_apub_id_valid,
fetcher::object_id::ObjectId,
generate_outbox_url, generate_outbox_url,
objects::get_summary_from_string_or_source, objects::get_summary_from_string_or_source,
protocol::{ protocol::{
@ -13,6 +12,7 @@ use activitystreams::{actor::Endpoints, object::kind::ImageType};
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
object_id::ObjectId,
traits::{ActorType, ApubObject}, traits::{ActorType, ApubObject},
values::MediaTypeMarkdown, values::MediaTypeMarkdown,
verify::verify_domains_match, verify::verify_domains_match,
@ -181,7 +181,7 @@ impl ActorType for ApubPerson {
self.local self.local
} }
fn actor_id(&self) -> Url { fn actor_id(&self) -> Url {
self.actor_id.to_owned().into_inner() self.actor_id.to_owned().into()
} }
fn name(&self) -> String { fn name(&self) -> String {
self.name.clone() self.name.clone()
@ -200,7 +200,7 @@ impl ActorType for ApubPerson {
} }
fn shared_inbox_url(&self) -> Option<Url> { 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 .await
.unwrap(); .unwrap();
assert_eq!(person.actor_id.clone().into_inner(), url); assert_eq!(person.actor_id, url.into());
assert_eq!(person.name, "lanodan"); assert_eq!(person.name, "lanodan");
assert!(person.public_key.is_some()); assert!(person.public_key.is_some());
assert!(!person.local); assert!(!person.local);

View File

@ -1,7 +1,6 @@
use crate::{ use crate::{
activities::verify_person_in_community, activities::verify_person_in_community,
check_is_apub_id_valid, check_is_apub_id_valid,
fetcher::object_id::ObjectId,
protocol::{ protocol::{
objects::{page::Page, tombstone::Tombstone}, objects::{page::Page, tombstone::Tombstone},
ImageObject, ImageObject,
@ -15,6 +14,7 @@ use activitystreams::{
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
object_id::ObjectId,
traits::ApubObject, traits::ApubObject,
values::{MediaTypeHtml, MediaTypeMarkdown}, values::{MediaTypeHtml, MediaTypeMarkdown},
verify::verify_domains_match, verify::verify_domains_match,
@ -217,7 +217,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
assert_eq!(post.ap_id.clone().into_inner(), url); assert_eq!(post.ap_id, url.into());
assert_eq!(post.name, "Post title"); assert_eq!(post.name, "Post title");
assert!(post.body.is_some()); assert!(post.body.is_some());
assert_eq!(post.body.as_ref().unwrap().len(), 45); assert_eq!(post.body.as_ref().unwrap().len(), 45);

View File

@ -1,14 +1,12 @@
use crate::{ use crate::protocol::{
fetcher::object_id::ObjectId, objects::chat_message::{ChatMessage, ChatMessageType},
protocol::{ Source,
objects::chat_message::{ChatMessage, ChatMessageType},
Source,
},
}; };
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use html2md::parse_html; use html2md::parse_html;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
object_id::ObjectId,
traits::ApubObject, traits::ApubObject,
values::{MediaTypeHtml, MediaTypeMarkdown}, values::{MediaTypeHtml, MediaTypeMarkdown},
verify::verify_domains_match, verify::verify_domains_match,
@ -180,7 +178,7 @@ mod tests {
.await .await
.unwrap(); .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!(pm.content.len(), 20);
assert_eq!(request_counter, 0); assert_eq!(request_counter, 0);
@ -204,7 +202,7 @@ mod tests {
.await .await
.unwrap(); .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!(pm.content.len(), 3);
assert_eq!(request_counter, 0); assert_eq!(request_counter, 0);

View 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 activitystreams::{activity::kind::AddType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,9 +1,6 @@
use crate::{ use crate::{activity_lists::AnnouncableActivities, objects::community::ApubCommunity};
activity_lists::AnnouncableActivities,
fetcher::object_id::ObjectId,
objects::community::ApubCommunity,
};
use activitystreams::{activity::kind::AnnounceType, unparsed::Unparsed}; use activitystreams::{activity::kind::AnnounceType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,8 +1,6 @@
use crate::{ use crate::objects::{community::ApubCommunity, person::ApubPerson};
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson},
};
use activitystreams::{activity::kind::BlockType, unparsed::Unparsed}; use activitystreams::{activity::kind::BlockType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View 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 activitystreams::{activity::kind::RemoveType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,8 +1,9 @@
use crate::{ use crate::{
fetcher::{object_id::ObjectId, post_or_comment::PostOrComment}, fetcher::post_or_comment::PostOrComment,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
}; };
use activitystreams::{activity::kind::FlagType, unparsed::Unparsed}; use activitystreams::{activity::kind::FlagType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,9 +1,9 @@
use crate::{ use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson, objects::person::ApubPerson,
protocol::activities::community::block_user::BlockUserFromCommunity, protocol::activities::community::block_user::BlockUserFromCommunity,
}; };
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,9 +1,6 @@
use crate::{ use crate::{objects::person::ApubPerson, protocol::objects::group::Group};
fetcher::object_id::ObjectId,
objects::person::ApubPerson,
protocol::objects::group::Group,
};
use activitystreams::{activity::kind::UpdateType, unparsed::Unparsed}; use activitystreams::{activity::kind::UpdateType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,9 +1,9 @@
use crate::{ use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson, objects::person::ApubPerson,
protocol::{activities::CreateOrUpdateType, objects::note::Note}, protocol::{activities::CreateOrUpdateType, objects::note::Note},
}; };
use activitystreams::{link::Mention, unparsed::Unparsed}; use activitystreams::{link::Mention, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,9 +1,9 @@
use crate::{ use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson, objects::person::ApubPerson,
protocol::{activities::CreateOrUpdateType, objects::page::Page}, protocol::{activities::CreateOrUpdateType, objects::page::Page},
}; };
use activitystreams::unparsed::Unparsed; use activitystreams::unparsed::Unparsed;
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View 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 activitystreams::{activity::kind::DeleteType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
use url::Url; use url::Url;

View File

@ -1,9 +1,6 @@
use crate::{ use crate::{objects::person::ApubPerson, protocol::activities::deletion::delete::Delete};
fetcher::object_id::ObjectId,
objects::person::ApubPerson,
protocol::activities::deletion::delete::Delete,
};
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,9 +1,9 @@
use crate::{ use crate::{
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::following::follow::FollowCommunity, protocol::activities::following::follow::FollowCommunity,
}; };
use activitystreams::{activity::kind::AcceptType, unparsed::Unparsed}; use activitystreams::{activity::kind::AcceptType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,8 +1,6 @@
use crate::{ use crate::objects::{community::ApubCommunity, person::ApubPerson};
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson},
};
use activitystreams::{activity::kind::FollowType, unparsed::Unparsed}; use activitystreams::{activity::kind::FollowType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,9 +1,9 @@
use crate::{ use crate::{
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::following::follow::FollowCommunity, protocol::activities::following::follow::FollowCommunity,
}; };
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,9 +1,9 @@
use crate::{ use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson, objects::person::ApubPerson,
protocol::{activities::CreateOrUpdateType, objects::chat_message::ChatMessage}, protocol::{activities::CreateOrUpdateType, objects::chat_message::ChatMessage},
}; };
use activitystreams::unparsed::Unparsed; use activitystreams::unparsed::Unparsed;
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,8 +1,6 @@
use crate::{ use crate::objects::{person::ApubPerson, private_message::ApubPrivateMessage};
fetcher::object_id::ObjectId,
objects::{person::ApubPerson, private_message::ApubPrivateMessage},
};
use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed}; use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,9 +1,9 @@
use crate::{ use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson, objects::person::ApubPerson,
protocol::activities::private_message::delete::DeletePrivateMessage, protocol::activities::private_message::delete::DeletePrivateMessage,
}; };
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,9 +1,6 @@
use crate::{ use crate::{objects::person::ApubPerson, protocol::activities::voting::vote::Vote};
fetcher::object_id::ObjectId,
objects::person::ApubPerson,
protocol::activities::voting::vote::Vote,
};
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -1,9 +1,7 @@
use crate::{ use crate::{fetcher::post_or_comment::PostOrComment, objects::person::ApubPerson};
fetcher::{object_id::ObjectId, post_or_comment::PostOrComment},
objects::person::ApubPerson,
};
use activitystreams::unparsed::Unparsed; use activitystreams::unparsed::Unparsed;
use anyhow::anyhow; use anyhow::anyhow;
use lemmy_apub_lib::object_id::ObjectId;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -29,7 +29,7 @@ impl GroupFollowers {
.await??; .await??;
Ok(GroupFollowers { Ok(GroupFollowers {
id: generate_followers_url(&community.actor_id)?.into_inner(), id: generate_followers_url(&community.actor_id)?.into(),
r#type: CollectionType::Collection, r#type: CollectionType::Collection,
total_items: community_followers.len() as i32, total_items: community_followers.len() as i32,
items: vec![], items: vec![],

View 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 activitystreams::collection::kind::OrderedCollectionType;
use lemmy_apub_lib::object_id::ObjectId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View File

@ -18,7 +18,7 @@ impl PersonOutbox {
pub(crate) async fn new(user: Person) -> Result<PersonOutbox, LemmyError> { pub(crate) async fn new(user: Person) -> Result<PersonOutbox, LemmyError> {
Ok(PersonOutbox { Ok(PersonOutbox {
r#type: OrderedCollectionType::OrderedCollection, r#type: OrderedCollectionType::OrderedCollection,
id: generate_outbox_url(&user.actor_id)?.into_inner(), id: generate_outbox_url(&user.actor_id)?.into(),
ordered_items: vec![], ordered_items: vec![],
total_items: 0, total_items: 0,
}) })

View File

@ -1,5 +1,4 @@
use crate::{ use crate::{
fetcher::object_id::ObjectId,
objects::{person::ApubPerson, private_message::ApubPrivateMessage}, objects::{person::ApubPerson, private_message::ApubPrivateMessage},
protocol::Source, protocol::Source,
}; };
@ -8,7 +7,7 @@ use activitystreams::{
unparsed::Unparsed, unparsed::Unparsed,
}; };
use anyhow::anyhow; 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_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -4,7 +4,6 @@ use crate::{
community_moderators::ApubCommunityModerators, community_moderators::ApubCommunityModerators,
community_outbox::ApubCommunityOutbox, community_outbox::ApubCommunityOutbox,
}, },
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, get_summary_from_string_or_source}, objects::{community::ApubCommunity, get_summary_from_string_or_source},
protocol::{ImageObject, Source}, protocol::{ImageObject, Source},
}; };
@ -13,7 +12,7 @@ use activitystreams::{
unparsed::Unparsed, unparsed::Unparsed,
}; };
use chrono::{DateTime, FixedOffset}; 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_db_schema::{naive_now, source::community::CommunityForm};
use lemmy_utils::{ use lemmy_utils::{
settings::structs::Settings, settings::structs::Settings,
@ -73,6 +72,7 @@ impl Group {
check_slurs(&title, slur_regex)?; check_slurs(&title, slur_regex)?;
check_slurs_opt(&description, slur_regex)?; check_slurs_opt(&description, slur_regex)?;
// TODO: test_parse_lemmy_community_moderators() keeps failing here with stack overflow
Ok(CommunityForm { Ok(CommunityForm {
name, name,
title, title,

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
activities::{verify_is_public, verify_person_in_community}, 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}, objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
protocol::Source, protocol::Source,
}; };
@ -8,7 +8,7 @@ use activitystreams::{object::kind::NoteType, unparsed::Unparsed};
use anyhow::anyhow; use anyhow::anyhow;
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, FixedOffset};
use lemmy_api_common::blocking; 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::{ use lemmy_db_schema::{
newtypes::CommentId, newtypes::CommentId,
source::{community::Community, post::Post}, source::{community::Community, post::Post},

View File

@ -1,13 +1,12 @@
use crate::{ use crate::{
activities::{verify_is_public, verify_person_in_community}, activities::{verify_is_public, verify_person_in_community},
fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost}, objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
protocol::{ImageObject, Source}, protocol::{ImageObject, Source},
}; };
use activitystreams::{object::kind::PageType, unparsed::Unparsed}; use activitystreams::{object::kind::PageType, unparsed::Unparsed};
use anyhow::anyhow; use anyhow::anyhow;
use chrono::{DateTime, FixedOffset}; 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_utils::{utils::check_slurs, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,11 +1,10 @@
use crate::{ use crate::{
fetcher::object_id::ObjectId,
objects::person::ApubPerson, objects::person::ApubPerson,
protocol::{ImageObject, Source}, protocol::{ImageObject, Source},
}; };
use activitystreams::{actor::Endpoints, unparsed::Unparsed, url::Url}; use activitystreams::{actor::Endpoints, unparsed::Unparsed, url::Url};
use chrono::{DateTime, FixedOffset}; 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::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;

View 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-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"] } http-signature-normalization-reqwest = { version = "0.2.0", default-features = false, features = ["sha-2"] }
background-jobs = "0.9.1" background-jobs = "0.9.1"
diesel = "1.4.8"

View File

@ -3,6 +3,7 @@ extern crate lazy_static;
pub mod activity_queue; pub mod activity_queue;
pub mod data; pub mod data;
pub mod object_id;
pub mod signatures; pub mod signatures;
pub mod traits; pub mod traits;
pub mod values; pub mod values;

View 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 anyhow::anyhow;
use diesel::NotFound; use diesel::NotFound;
use lemmy_apub_lib::{traits::ApubObject, APUB_JSON_CONTENT_TYPE};
use lemmy_db_schema::newtypes::DbUrl;
use lemmy_utils::{ use lemmy_utils::{
request::{build_user_agent, retry}, request::{build_user_agent, retry},
settings::structs::Settings, 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> impl<Kind> Display for ObjectId<Kind>
where where
Kind: ApubObject + Send + 'static, Kind: ApubObject + Send + 'static,
for<'de2> <Kind as ApubObject>::ApubType: serde::Deserialize<'de2>, for<'de2> <Kind as ApubObject>::ApubType: serde::Deserialize<'de2>,
{ {
#[allow(clippy::to_string_in_display)]
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { 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()) write!(f, "{}", self.0.to_string())
} }
} }
@ -164,12 +185,17 @@ where
} }
} }
impl<Kind> From<ObjectId<Kind>> for DbUrl #[cfg(test)]
where mod tests {
Kind: ApubObject + Send + 'static, use super::*;
for<'de2> <Kind as ApubObject>::ApubType: serde::Deserialize<'de2>, use crate::object_id::should_refetch_object;
{
fn from(id: ObjectId<Kind>) -> Self { #[test]
id.0.into() 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));
} }
} }

View File

@ -12,6 +12,7 @@ doctest = false
[dependencies] [dependencies]
lemmy_utils = { version = "=0.13.5-rc.7", path = "../utils" } 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 = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] }
diesel_migrations = "1.4.0" diesel_migrations = "1.4.0"
chrono = { version = "0.4.19", features = ["serde"] } chrono = { version = "0.4.19", features = ["serde"] }

View File

@ -4,6 +4,7 @@ use diesel::{
serialize::{Output, ToSql}, serialize::{Output, ToSql},
sql_types::Text, sql_types::Text,
}; };
use lemmy_apub_lib::{object_id::ObjectId, traits::ApubObject};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{
fmt, 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 { impl Display for DbUrl {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.to_owned().0.fmt(f) self.to_owned().0.fmt(f)
} }
} }
impl From<DbUrl> for Url { // the project doesnt compile with From
fn from(url: DbUrl) -> Self { #[allow(clippy::from_over_into)]
url.0 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 { impl<Kind> From<ObjectId<Kind>> for DbUrl
fn from(url: Url) -> Self { where
DbUrl(url) Kind: ApubObject + Send + 'static,
for<'de2> <Kind as ApubObject>::ApubType: serde::Deserialize<'de2>,
{
fn from(id: ObjectId<Kind>) -> Self {
DbUrl(id.into())
} }
} }