mirror of https://github.com/LemmyNet/lemmy.git
rewrite person fetch to use new fetcher
parent
0ed466dfdd
commit
27e409442a
|
@ -1,4 +1,4 @@
|
||||||
use crate::{fetcher::person::get_or_fetch_and_upsert_person, ActorType};
|
use crate::{fetcher::new_fetcher::dereference, ActorType};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
base::BaseExt,
|
base::BaseExt,
|
||||||
link::{LinkExt, Mention},
|
link::{LinkExt, Mention},
|
||||||
|
@ -33,7 +33,7 @@ async fn get_notif_recipients(
|
||||||
) -> Result<Vec<LocalUserId>, LemmyError> {
|
) -> Result<Vec<LocalUserId>, LemmyError> {
|
||||||
let post_id = comment.post_id;
|
let post_id = comment.post_id;
|
||||||
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
||||||
let actor = get_or_fetch_and_upsert_person(actor, context, request_counter).await?;
|
let actor = dereference::<Person>(actor, context, request_counter).await?;
|
||||||
|
|
||||||
// Note:
|
// Note:
|
||||||
// Although mentions could be gotten from the post tags (they are included there), or the ccs,
|
// Although mentions could be gotten from the post tags (they are included there), or the ccs,
|
||||||
|
@ -79,7 +79,7 @@ pub async fn collect_non_local_mentions(
|
||||||
debug!("mention actor_id: {}", actor_id);
|
debug!("mention actor_id: {}", actor_id);
|
||||||
addressed_ccs.push(actor_id.to_owned().to_string().parse()?);
|
addressed_ccs.push(actor_id.to_owned().to_string().parse()?);
|
||||||
|
|
||||||
let mention_person = get_or_fetch_and_upsert_person(&actor_id, context, &mut 0).await?;
|
let mention_person = dereference::<Person>(&actor_id, context, &mut 0).await?;
|
||||||
inboxes.push(mention_person.get_shared_inbox_or_inbox_url());
|
inboxes.push(mention_person.get_shared_inbox_or_inbox_url());
|
||||||
|
|
||||||
let mut mention_tag = Mention::new();
|
let mut mention_tag = Mention::new();
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
activity_queue::send_to_community_new,
|
activity_queue::send_to_community_new,
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
|
fetcher::{community::get_or_fetch_and_upsert_community, new_fetcher::dereference},
|
||||||
generate_moderators_url,
|
generate_moderators_url,
|
||||||
ActorType,
|
ActorType,
|
||||||
};
|
};
|
||||||
|
@ -95,7 +95,7 @@ impl ActivityHandler for AddMod {
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let community =
|
let community =
|
||||||
get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
|
get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
|
||||||
let new_mod = get_or_fetch_and_upsert_person(&self.object, context, request_counter).await?;
|
let new_mod = dereference::<Person>(&self.object, context, request_counter).await?;
|
||||||
|
|
||||||
// If we had to refetch the community while parsing the activity, then the new mod has already
|
// If we had to refetch the community while parsing the activity, then the new mod has already
|
||||||
// been added. Skip it here as it would result in a duplicate key error.
|
// been added. Skip it here as it would result in a duplicate key error.
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
activity_queue::send_to_community_new,
|
activity_queue::send_to_community_new,
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
|
fetcher::{community::get_or_fetch_and_upsert_community, new_fetcher::dereference},
|
||||||
ActorType,
|
ActorType,
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -104,8 +104,7 @@ impl ActivityHandler for BlockUserFromCommunity {
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let community =
|
let community =
|
||||||
get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
|
get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
|
||||||
let blocked_user =
|
let blocked_user = dereference::<Person>(&self.object, context, request_counter).await?;
|
||||||
get_or_fetch_and_upsert_person(&self.object, context, request_counter).await?;
|
|
||||||
|
|
||||||
let community_user_ban_form = CommunityPersonBanForm {
|
let community_user_ban_form = CommunityPersonBanForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
activity_queue::send_to_community_new,
|
activity_queue::send_to_community_new,
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
|
fetcher::{community::get_or_fetch_and_upsert_community, new_fetcher::dereference},
|
||||||
generate_moderators_url,
|
generate_moderators_url,
|
||||||
ActorType,
|
ActorType,
|
||||||
};
|
};
|
||||||
|
@ -110,8 +110,7 @@ impl ActivityHandler for RemoveMod {
|
||||||
if self.target.is_some() {
|
if self.target.is_some() {
|
||||||
let community =
|
let community =
|
||||||
get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
|
get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
|
||||||
let remove_mod =
|
let remove_mod = dereference::<Person>(&self.object, context, request_counter).await?;
|
||||||
get_or_fetch_and_upsert_person(&self.object, context, request_counter).await?;
|
|
||||||
|
|
||||||
let form = CommunityModeratorForm {
|
let form = CommunityModeratorForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
activity_queue::send_to_community_new,
|
activity_queue::send_to_community_new,
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
|
fetcher::{community::get_or_fetch_and_upsert_community, new_fetcher::dereference},
|
||||||
ActorType,
|
ActorType,
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -93,8 +93,7 @@ impl ActivityHandler for UndoBlockUserFromCommunity {
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let community =
|
let community =
|
||||||
get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
|
get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
|
||||||
let blocked_user =
|
let blocked_user = dereference::<Person>(&self.object.object, context, request_counter).await?;
|
||||||
get_or_fetch_and_upsert_person(&self.object.object, context, request_counter).await?;
|
|
||||||
|
|
||||||
let community_user_ban_form = CommunityPersonBanForm {
|
let community_user_ban_form = CommunityPersonBanForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
activity_queue::send_to_community_new,
|
activity_queue::send_to_community_new,
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::person::get_or_fetch_and_upsert_person,
|
fetcher::new_fetcher::dereference,
|
||||||
ActorType,
|
ActorType,
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -171,7 +171,7 @@ pub(in crate::activities) async fn receive_remove_action(
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let actor = get_or_fetch_and_upsert_person(actor, context, request_counter).await?;
|
let actor = dereference::<Person>(actor, context, request_counter).await?;
|
||||||
use UserOperationCrud::*;
|
use UserOperationCrud::*;
|
||||||
match DeletableObjects::read_from_db(object, context).await? {
|
match DeletableObjects::read_from_db(object, context).await? {
|
||||||
DeletableObjects::Community(community) => {
|
DeletableObjects::Community(community) => {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
verify_mod_action,
|
verify_mod_action,
|
||||||
verify_person_in_community,
|
verify_person_in_community,
|
||||||
},
|
},
|
||||||
fetcher::person::get_or_fetch_and_upsert_person,
|
fetcher::new_fetcher::dereference,
|
||||||
ActorType,
|
ActorType,
|
||||||
};
|
};
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
|
@ -180,7 +180,7 @@ async fn receive_delete_action(
|
||||||
match DeletableObjects::read_from_db(object, context).await? {
|
match DeletableObjects::read_from_db(object, context).await? {
|
||||||
DeletableObjects::Community(community) => {
|
DeletableObjects::Community(community) => {
|
||||||
if community.local {
|
if community.local {
|
||||||
let mod_ = get_or_fetch_and_upsert_person(actor, context, request_counter).await?;
|
let mod_ = dereference::<Person>(actor, context, request_counter).await?;
|
||||||
let object = community.actor_id();
|
let object = community.actor_id();
|
||||||
send_apub_delete(&mod_, &community.clone(), object, true, context).await?;
|
send_apub_delete(&mod_, &community.clone(), object, true, context).await?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
activity_queue::send_activity_new,
|
activity_queue::send_activity_new,
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
|
fetcher::{community::get_or_fetch_and_upsert_community, new_fetcher::dereference},
|
||||||
ActorType,
|
ActorType,
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -91,7 +91,7 @@ impl ActivityHandler for AcceptFollowCommunity {
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let actor = get_or_fetch_and_upsert_community(&self.actor, context, request_counter).await?;
|
let actor = get_or_fetch_and_upsert_community(&self.actor, context, request_counter).await?;
|
||||||
let to = get_or_fetch_and_upsert_person(&self.to, context, request_counter).await?;
|
let to = dereference::<Person>(&self.to, context, request_counter).await?;
|
||||||
// This will throw an error if no follow was requested
|
// This will throw an error if no follow was requested
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
CommunityFollower::follow_accepted(conn, actor.id, to.id)
|
CommunityFollower::follow_accepted(conn, actor.id, to.id)
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
activity_queue::send_activity_new,
|
activity_queue::send_activity_new,
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
|
fetcher::{community::get_or_fetch_and_upsert_community, new_fetcher::dereference},
|
||||||
ActorType,
|
ActorType,
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -97,7 +97,7 @@ impl ActivityHandler for FollowCommunity {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let actor = get_or_fetch_and_upsert_person(&self.actor, context, request_counter).await?;
|
let actor = dereference::<Person>(&self.actor, context, request_counter).await?;
|
||||||
let community =
|
let community =
|
||||||
get_or_fetch_and_upsert_community(&self.object, context, request_counter).await?;
|
get_or_fetch_and_upsert_community(&self.object, context, request_counter).await?;
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
activity_queue::send_activity_new,
|
activity_queue::send_activity_new,
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
|
fetcher::{community::get_or_fetch_and_upsert_community, new_fetcher::dereference},
|
||||||
ActorType,
|
ActorType,
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -84,7 +84,7 @@ impl ActivityHandler for UndoFollowCommunity {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let actor = get_or_fetch_and_upsert_person(&self.actor, context, request_counter).await?;
|
let actor = dereference::<Person>(&self.actor, context, request_counter).await?;
|
||||||
let community = get_or_fetch_and_upsert_community(&self.to, context, request_counter).await?;
|
let community = get_or_fetch_and_upsert_community(&self.to, context, request_counter).await?;
|
||||||
|
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
check_community_or_site_ban,
|
check_community_or_site_ban,
|
||||||
check_is_apub_id_valid,
|
check_is_apub_id_valid,
|
||||||
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
|
fetcher::{community::get_or_fetch_and_upsert_community, new_fetcher::dereference},
|
||||||
generate_moderators_url,
|
generate_moderators_url,
|
||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
@ -43,7 +43,7 @@ async fn verify_person(
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let person = get_or_fetch_and_upsert_person(person_id, context, request_counter).await?;
|
let person = dereference::<Person>(person_id, context, request_counter).await?;
|
||||||
if person.banned {
|
if person.banned {
|
||||||
return Err(anyhow!("Person {} is banned", person_id).into());
|
return Err(anyhow!("Person {} is banned", person_id).into());
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ pub(crate) async fn verify_person_in_community(
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let community = get_or_fetch_and_upsert_community(community_id, context, request_counter).await?;
|
let community = get_or_fetch_and_upsert_community(community_id, context, request_counter).await?;
|
||||||
let person = get_or_fetch_and_upsert_person(person_id, context, request_counter).await?;
|
let person = dereference::<Person>(person_id, context, request_counter).await?;
|
||||||
check_community_or_site_ban(&person, community.id, context.pool()).await
|
check_community_or_site_ban(&person, community.id, context.pool()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
activity_queue::send_to_community_new,
|
activity_queue::send_to_community_new,
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::person::get_or_fetch_and_upsert_person,
|
fetcher::new_fetcher::dereference,
|
||||||
objects::{post::Page, FromApub, ToApub},
|
objects::{post::Page, FromApub, ToApub},
|
||||||
ActorType,
|
ActorType,
|
||||||
};
|
};
|
||||||
|
@ -121,7 +121,7 @@ impl ActivityHandler for CreateOrUpdatePost {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let actor = get_or_fetch_and_upsert_person(&self.actor, context, request_counter).await?;
|
let actor = dereference::<Person>(&self.actor, context, request_counter).await?;
|
||||||
let post = Post::from_apub(&self.object, context, &actor.actor_id(), request_counter).await?;
|
let post = Post::from_apub(&self.object, context, &actor.actor_id(), request_counter).await?;
|
||||||
|
|
||||||
let notif_type = match self.kind {
|
let notif_type = match self.kind {
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
activity_queue::send_to_community_new,
|
activity_queue::send_to_community_new,
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::{new_fetcher::dereference, person::get_or_fetch_and_upsert_person},
|
fetcher::new_fetcher::dereference,
|
||||||
ActorType,
|
ActorType,
|
||||||
PostOrComment,
|
PostOrComment,
|
||||||
};
|
};
|
||||||
|
@ -100,7 +100,7 @@ impl ActivityHandler for UndoVote {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let actor = get_or_fetch_and_upsert_person(&self.actor, context, request_counter).await?;
|
let actor = dereference::<Person>(&self.actor, context, request_counter).await?;
|
||||||
let object =
|
let object =
|
||||||
dereference::<PostOrComment>(&self.object.object, context, request_counter).await?;
|
dereference::<PostOrComment>(&self.object.object, context, request_counter).await?;
|
||||||
match object {
|
match object {
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
activity_queue::send_to_community_new,
|
activity_queue::send_to_community_new,
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::{new_fetcher::dereference, person::get_or_fetch_and_upsert_person},
|
fetcher::new_fetcher::dereference,
|
||||||
ActorType,
|
ActorType,
|
||||||
PostOrComment,
|
PostOrComment,
|
||||||
};
|
};
|
||||||
|
@ -126,7 +126,7 @@ impl ActivityHandler for Vote {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let actor = get_or_fetch_and_upsert_person(&self.actor, context, request_counter).await?;
|
let actor = dereference::<Person>(&self.actor, context, request_counter).await?;
|
||||||
let object = dereference::<PostOrComment>(&self.object, context, request_counter).await?;
|
let object = dereference::<PostOrComment>(&self.object, context, request_counter).await?;
|
||||||
match object {
|
match object {
|
||||||
PostOrComment::Post(p) => vote_post(&self.kind, actor, p.deref(), context).await,
|
PostOrComment::Post(p) => vote_post(&self.kind, actor, p.deref(), context).await,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
fetcher::{
|
fetcher::{
|
||||||
fetch::fetch_remote_object,
|
fetch::fetch_remote_object,
|
||||||
is_deleted,
|
is_deleted,
|
||||||
person::get_or_fetch_and_upsert_person,
|
new_fetcher::dereference,
|
||||||
should_refetch_actor,
|
should_refetch_actor,
|
||||||
},
|
},
|
||||||
objects::{community::Group, FromApub},
|
objects::{community::Group, FromApub},
|
||||||
|
@ -14,7 +14,10 @@ use diesel::result::Error::NotFound;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::ActivityHandler;
|
use lemmy_apub_lib::ActivityHandler;
|
||||||
use lemmy_db_queries::{source::community::Community_, ApubObject, Joinable};
|
use lemmy_db_queries::{source::community::Community_, ApubObject, Joinable};
|
||||||
use lemmy_db_schema::source::community::{Community, CommunityModerator, CommunityModeratorForm};
|
use lemmy_db_schema::source::{
|
||||||
|
community::{Community, CommunityModerator, CommunityModeratorForm},
|
||||||
|
person::Person,
|
||||||
|
};
|
||||||
use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
|
use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
|
||||||
use lemmy_utils::{location_info, LemmyError};
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
@ -114,7 +117,7 @@ async fn update_community_mods(
|
||||||
|
|
||||||
// Add new mods to database which have been added to moderators collection
|
// Add new mods to database which have been added to moderators collection
|
||||||
for mod_uri in new_moderators {
|
for mod_uri in new_moderators {
|
||||||
let mod_user = get_or_fetch_and_upsert_person(&mod_uri, context, request_counter).await?;
|
let mod_user = dereference::<Person>(&mod_uri, context, request_counter).await?;
|
||||||
|
|
||||||
if !current_moderators
|
if !current_moderators
|
||||||
.clone()
|
.clone()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
pub mod community;
|
pub mod community;
|
||||||
mod fetch;
|
mod fetch;
|
||||||
pub mod new_fetcher;
|
pub mod new_fetcher;
|
||||||
pub mod person;
|
|
||||||
pub mod post_or_comment;
|
pub mod post_or_comment;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
|
|
||||||
|
@ -9,13 +8,13 @@ use crate::{
|
||||||
fetcher::{
|
fetcher::{
|
||||||
community::get_or_fetch_and_upsert_community,
|
community::get_or_fetch_and_upsert_community,
|
||||||
fetch::FetchError,
|
fetch::FetchError,
|
||||||
person::get_or_fetch_and_upsert_person,
|
new_fetcher::dereference,
|
||||||
},
|
},
|
||||||
ActorType,
|
ActorType,
|
||||||
};
|
};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use lemmy_db_schema::naive_now;
|
use lemmy_db_schema::{naive_now, source::person::Person};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -51,7 +50,7 @@ pub(crate) async fn get_or_fetch_and_upsert_actor(
|
||||||
let community = get_or_fetch_and_upsert_community(apub_id, context, recursion_counter).await;
|
let community = get_or_fetch_and_upsert_community(apub_id, context, recursion_counter).await;
|
||||||
let actor: Box<dyn ActorType> = match community {
|
let actor: Box<dyn ActorType> = match community {
|
||||||
Ok(c) => Box::new(c),
|
Ok(c) => Box::new(c),
|
||||||
Err(_) => Box::new(get_or_fetch_and_upsert_person(apub_id, context, recursion_counter).await?),
|
Err(_) => Box::new(dereference::<Person>(apub_id, context, recursion_counter).await?),
|
||||||
};
|
};
|
||||||
Ok(actor)
|
Ok(actor)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use crate::{objects::FromApub, APUB_JSON_CONTENT_TYPE};
|
use crate::{fetcher::should_refetch_actor, objects::FromApub, APUB_JSON_CONTENT_TYPE};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use diesel::NotFound;
|
use diesel::NotFound;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_db_queries::{ApubObject, DbPool};
|
use lemmy_db_queries::{ApubObject, DbPool};
|
||||||
use lemmy_utils::{request::retry, settings::structs::Settings, LemmyError};
|
use lemmy_utils::{request::retry, settings::structs::Settings, LemmyError};
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
use log::debug;
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -23,11 +24,27 @@ where
|
||||||
Kind: FromApub + ApubObject + Send + 'static,
|
Kind: FromApub + ApubObject + Send + 'static,
|
||||||
for<'de> <Kind as FromApub>::ApubType: serde::Deserialize<'de>,
|
for<'de> <Kind as FromApub>::ApubType: serde::Deserialize<'de>,
|
||||||
{
|
{
|
||||||
let local_object = dereference_locally(id.clone(), context.pool()).await?;
|
let db_object = dereference_locally::<Kind>(id.clone(), context.pool()).await?;
|
||||||
if let Some(object) = local_object {
|
// if its a local object, only fetch it from the database and not over http
|
||||||
// TODO: for actors, also refetch after 24 hours
|
if id.domain() == Some(&Settings::get().get_hostname_without_port()?) {
|
||||||
|
dbg!("is local object", db_object.is_some());
|
||||||
|
return match db_object {
|
||||||
|
None => Err(NotFound {}.into()),
|
||||||
|
Some(o) => Ok(o),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(object) = db_object {
|
||||||
|
if let Some(last_refreshed_at) = object.last_refreshed_at() {
|
||||||
|
// TODO: rename to should_refetch_object()
|
||||||
|
if should_refetch_actor(last_refreshed_at) {
|
||||||
|
debug!("Refetching remote object {}", id);
|
||||||
|
return dereference_remotely(id, context, request_counter).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(object)
|
Ok(object)
|
||||||
} else {
|
} else {
|
||||||
|
debug!("Fetching remote object {}", id);
|
||||||
dereference_remotely(id, context, request_counter).await
|
dereference_remotely(id, context, request_counter).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
use crate::{
|
|
||||||
fetcher::{fetch::fetch_remote_object, is_deleted, should_refetch_actor},
|
|
||||||
objects::{person::Person as ApubPerson, FromApub},
|
|
||||||
};
|
|
||||||
use anyhow::anyhow;
|
|
||||||
use diesel::result::Error::NotFound;
|
|
||||||
use lemmy_api_common::blocking;
|
|
||||||
use lemmy_db_queries::{source::person::Person_, ApubObject};
|
|
||||||
use lemmy_db_schema::source::person::Person;
|
|
||||||
use lemmy_utils::LemmyError;
|
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
use log::debug;
|
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
/// Get a person from its apub ID.
|
|
||||||
///
|
|
||||||
/// If it exists locally and `!should_refetch_actor()`, it is returned directly from the database.
|
|
||||||
/// Otherwise it is fetched from the remote instance, stored and returned.
|
|
||||||
pub(crate) async fn get_or_fetch_and_upsert_person(
|
|
||||||
apub_id: &Url,
|
|
||||||
context: &LemmyContext,
|
|
||||||
recursion_counter: &mut i32,
|
|
||||||
) -> Result<Person, LemmyError> {
|
|
||||||
let apub_id_owned = apub_id.to_owned();
|
|
||||||
let person = blocking(context.pool(), move |conn| {
|
|
||||||
Person::read_from_apub_id(conn, &apub_id_owned.into())
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
match person {
|
|
||||||
// If its older than a day, re-fetch it
|
|
||||||
Ok(u) if !u.local && should_refetch_actor(u.last_refreshed_at) => {
|
|
||||||
debug!("Fetching and updating from remote person: {}", apub_id);
|
|
||||||
let person =
|
|
||||||
fetch_remote_object::<ApubPerson>(context.client(), apub_id, recursion_counter).await;
|
|
||||||
|
|
||||||
if is_deleted(&person) {
|
|
||||||
// TODO: use Person::update_deleted() once implemented
|
|
||||||
blocking(context.pool(), move |conn| {
|
|
||||||
Person::delete_account(conn, u.id)
|
|
||||||
})
|
|
||||||
.await??;
|
|
||||||
return Err(anyhow!("Person was deleted by remote instance").into());
|
|
||||||
} else if person.is_err() {
|
|
||||||
return Ok(u);
|
|
||||||
}
|
|
||||||
|
|
||||||
let person = Person::from_apub(&person?, context, apub_id, recursion_counter).await?;
|
|
||||||
|
|
||||||
let person_id = person.id;
|
|
||||||
blocking(context.pool(), move |conn| {
|
|
||||||
Person::mark_as_updated(conn, person_id)
|
|
||||||
})
|
|
||||||
.await??;
|
|
||||||
|
|
||||||
Ok(person)
|
|
||||||
}
|
|
||||||
Ok(u) => Ok(u),
|
|
||||||
Err(NotFound {}) => {
|
|
||||||
debug!("Fetching and creating remote person: {}", apub_id);
|
|
||||||
let person =
|
|
||||||
fetch_remote_object::<ApubPerson>(context.client(), apub_id, recursion_counter).await?;
|
|
||||||
|
|
||||||
let person = Person::from_apub(&person, context, apub_id, recursion_counter).await?;
|
|
||||||
|
|
||||||
Ok(person)
|
|
||||||
}
|
|
||||||
Err(e) => Err(e.into()),
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::objects::{comment::Note, post::Page, FromApub};
|
use crate::objects::{comment::Note, post::Page, FromApub};
|
||||||
|
use activitystreams::chrono::NaiveDateTime;
|
||||||
use diesel::{result::Error, PgConnection};
|
use diesel::{result::Error, PgConnection};
|
||||||
use lemmy_db_queries::ApubObject;
|
use lemmy_db_queries::ApubObject;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -33,6 +34,10 @@ pub enum PageOrNote {
|
||||||
impl ApubObject for PostOrComment {
|
impl ApubObject for PostOrComment {
|
||||||
type Form = PostOrCommentForm;
|
type Form = PostOrCommentForm;
|
||||||
|
|
||||||
|
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: this can probably be implemented using a single sql query
|
// TODO: this can probably be implemented using a single sql query
|
||||||
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error>
|
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
community::get_or_fetch_and_upsert_community,
|
community::get_or_fetch_and_upsert_community,
|
||||||
fetch::fetch_remote_object,
|
fetch::fetch_remote_object,
|
||||||
is_deleted,
|
is_deleted,
|
||||||
person::get_or_fetch_and_upsert_person,
|
new_fetcher::dereference,
|
||||||
},
|
},
|
||||||
find_object_by_id,
|
find_object_by_id,
|
||||||
objects::{comment::Note, community::Group, person::Person as ApubPerson, post::Page, FromApub},
|
objects::{comment::Note, community::Group, person::Person as ApubPerson, post::Page, FromApub},
|
||||||
|
@ -131,7 +131,7 @@ async fn build_response(
|
||||||
SearchAcceptedObjects::Person(p) => {
|
SearchAcceptedObjects::Person(p) => {
|
||||||
let person_uri = p.id(&query_url)?;
|
let person_uri = p.id(&query_url)?;
|
||||||
|
|
||||||
let person = get_or_fetch_and_upsert_person(person_uri, context, recursion_counter).await?;
|
let person = dereference::<Person>(person_uri, context, recursion_counter).await?;
|
||||||
ROR {
|
ROR {
|
||||||
person: blocking(context.pool(), move |conn| {
|
person: blocking(context.pool(), move |conn| {
|
||||||
PersonViewSafe::read(conn, person.id)
|
PersonViewSafe::read(conn, person.id)
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::new_fetcher::dereference,
|
fetcher::new_fetcher::dereference,
|
||||||
migrations::CommentInReplyToMigration,
|
migrations::CommentInReplyToMigration,
|
||||||
objects::{create_tombstone, get_or_fetch_and_upsert_person, FromApub, Source, ToApub},
|
objects::{create_tombstone, FromApub, Source, ToApub},
|
||||||
ActorType,
|
ActorType,
|
||||||
PostOrComment,
|
PostOrComment,
|
||||||
};
|
};
|
||||||
|
@ -216,8 +216,7 @@ impl FromApub for Comment {
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<Comment, LemmyError> {
|
) -> Result<Comment, LemmyError> {
|
||||||
let ap_id = Some(note.id(expected_domain)?.clone().into());
|
let ap_id = Some(note.id(expected_domain)?.clone().into());
|
||||||
let creator =
|
let creator = dereference::<Person>(¬e.attributed_to, context, request_counter).await?;
|
||||||
get_or_fetch_and_upsert_person(¬e.attributed_to, context, request_counter).await?;
|
|
||||||
let (post, parent_comment_id) = note.get_parents(context, request_counter).await?;
|
let (post, parent_comment_id) = note.get_parents(context, request_counter).await?;
|
||||||
if post.locked {
|
if post.locked {
|
||||||
return Err(anyhow!("Post is locked").into());
|
return Err(anyhow!("Post is locked").into());
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::fetcher::person::get_or_fetch_and_upsert_person;
|
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
base::BaseExt,
|
base::BaseExt,
|
||||||
object::{kind::ImageType, Tombstone, TombstoneExt},
|
object::{kind::ImageType, Tombstone, TombstoneExt},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::{extract_community, verify_person_in_community},
|
activities::{extract_community, verify_person_in_community},
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::person::get_or_fetch_and_upsert_person,
|
fetcher::new_fetcher::dereference,
|
||||||
objects::{create_tombstone, FromApub, ImageObject, Source, ToApub},
|
objects::{create_tombstone, FromApub, ImageObject, Source, ToApub},
|
||||||
ActorType,
|
ActorType,
|
||||||
};
|
};
|
||||||
|
@ -183,8 +183,7 @@ impl FromApub for Post {
|
||||||
page.id(expected_domain)?
|
page.id(expected_domain)?
|
||||||
};
|
};
|
||||||
let ap_id = Some(ap_id.clone().into());
|
let ap_id = Some(ap_id.clone().into());
|
||||||
let creator =
|
let creator = dereference::<Person>(&page.attributed_to, context, request_counter).await?;
|
||||||
get_or_fetch_and_upsert_person(&page.attributed_to, context, request_counter).await?;
|
|
||||||
let community = extract_community(&page.to, context, request_counter).await?;
|
let community = extract_community(&page.to, context, request_counter).await?;
|
||||||
|
|
||||||
let thumbnail_url: Option<Url> = page.image.clone().map(|i| i.url);
|
let thumbnail_url: Option<Url> = page.image.clone().map(|i| i.url);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::person::get_or_fetch_and_upsert_person,
|
fetcher::new_fetcher::dereference,
|
||||||
objects::{create_tombstone, FromApub, Source, ToApub},
|
objects::{create_tombstone, FromApub, Source, ToApub},
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -61,8 +61,7 @@ impl Note {
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_domains_match(&self.attributed_to, &self.id)?;
|
verify_domains_match(&self.attributed_to, &self.id)?;
|
||||||
let person =
|
let person = dereference::<Person>(&self.attributed_to, context, request_counter).await?;
|
||||||
get_or_fetch_and_upsert_person(&self.attributed_to, context, request_counter).await?;
|
|
||||||
if person.banned {
|
if person.banned {
|
||||||
return Err(anyhow!("Person is banned from site").into());
|
return Err(anyhow!("Person is banned from site").into());
|
||||||
}
|
}
|
||||||
|
@ -121,9 +120,8 @@ impl FromApub for PrivateMessage {
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<PrivateMessage, LemmyError> {
|
) -> Result<PrivateMessage, LemmyError> {
|
||||||
let ap_id = Some(note.id(expected_domain)?.clone().into());
|
let ap_id = Some(note.id(expected_domain)?.clone().into());
|
||||||
let creator =
|
let creator = dereference::<Person>(¬e.attributed_to, context, request_counter).await?;
|
||||||
get_or_fetch_and_upsert_person(¬e.attributed_to, context, request_counter).await?;
|
let recipient = dereference::<Person>(¬e.to, context, request_counter).await?;
|
||||||
let recipient = get_or_fetch_and_upsert_person(¬e.to, context, request_counter).await?;
|
|
||||||
|
|
||||||
let form = PrivateMessageForm {
|
let form = PrivateMessageForm {
|
||||||
creator_id: creator.id,
|
creator_id: creator.id,
|
||||||
|
|
|
@ -12,6 +12,7 @@ extern crate diesel_migrations;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate serial_test;
|
extern crate serial_test;
|
||||||
|
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{CommunityId, DbUrl, PersonId};
|
use lemmy_db_schema::{CommunityId, DbUrl, PersonId};
|
||||||
use lemmy_utils::ApiError;
|
use lemmy_utils::ApiError;
|
||||||
|
@ -147,6 +148,9 @@ pub trait DeleteableOrRemoveable {
|
||||||
|
|
||||||
pub trait ApubObject {
|
pub trait ApubObject {
|
||||||
type Form;
|
type Form;
|
||||||
|
/// If this object should be refetched after a certain interval, it should return the last refresh
|
||||||
|
/// time here. This is mainly used to update remote actors.
|
||||||
|
fn last_refreshed_at(&self) -> Option<NaiveDateTime>;
|
||||||
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error>
|
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::Crud;
|
use crate::Crud;
|
||||||
use diesel::{dsl::*, result::Error, sql_types::Text, *};
|
use diesel::{dsl::*, result::Error, sql_types::Text, *};
|
||||||
use lemmy_db_schema::{source::activity::*, DbUrl};
|
use lemmy_db_schema::{source::activity::*, DbUrl};
|
||||||
use log::debug;
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -72,7 +71,6 @@ impl Activity_ for Activity {
|
||||||
where
|
where
|
||||||
T: Serialize + Debug,
|
T: Serialize + Debug,
|
||||||
{
|
{
|
||||||
debug!("{}", serde_json::to_string_pretty(&data)?);
|
|
||||||
let activity_form = ActivityForm {
|
let activity_form = ActivityForm {
|
||||||
ap_id,
|
ap_id,
|
||||||
data: serde_json::to_value(&data)?,
|
data: serde_json::to_value(&data)?,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::{ApubObject, Crud, DeleteableOrRemoveable, Likeable, Saveable};
|
use crate::{ApubObject, Crud, DeleteableOrRemoveable, Likeable, Saveable};
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
naive_now,
|
naive_now,
|
||||||
|
@ -169,6 +170,11 @@ impl Crud for Comment {
|
||||||
|
|
||||||
impl ApubObject for Comment {
|
impl ApubObject for Comment {
|
||||||
type Form = CommentForm;
|
type Form = CommentForm;
|
||||||
|
|
||||||
|
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error> {
|
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::comment::dsl::*;
|
use lemmy_db_schema::schema::comment::dsl::*;
|
||||||
comment.filter(ap_id.eq(object_id)).first::<Self>(conn)
|
comment.filter(ap_id.eq(object_id)).first::<Self>(conn)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::{ApubObject, Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable};
|
use crate::{ApubObject, Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable};
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
naive_now,
|
naive_now,
|
||||||
|
@ -94,6 +95,11 @@ impl Crud for Community {
|
||||||
|
|
||||||
impl ApubObject for Community {
|
impl ApubObject for Community {
|
||||||
type Form = CommunityForm;
|
type Form = CommunityForm;
|
||||||
|
|
||||||
|
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
|
||||||
|
Some(self.last_refreshed_at)
|
||||||
|
}
|
||||||
|
|
||||||
fn read_from_apub_id(conn: &PgConnection, for_actor_id: &DbUrl) -> Result<Self, Error> {
|
fn read_from_apub_id(conn: &PgConnection, for_actor_id: &DbUrl) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::community::dsl::*;
|
use lemmy_db_schema::schema::community::dsl::*;
|
||||||
community
|
community
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::{ApubObject, Crud};
|
use crate::{ApubObject, Crud};
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
naive_now,
|
naive_now,
|
||||||
|
@ -182,6 +183,11 @@ impl Crud for Person {
|
||||||
|
|
||||||
impl ApubObject for Person {
|
impl ApubObject for Person {
|
||||||
type Form = PersonForm;
|
type Form = PersonForm;
|
||||||
|
|
||||||
|
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
|
||||||
|
Some(self.last_refreshed_at)
|
||||||
|
}
|
||||||
|
|
||||||
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error> {
|
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::person::dsl::*;
|
use lemmy_db_schema::schema::person::dsl::*;
|
||||||
person
|
person
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::{ApubObject, Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable};
|
use crate::{ApubObject, Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable};
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
naive_now,
|
naive_now,
|
||||||
|
@ -183,6 +184,11 @@ impl Post_ for Post {
|
||||||
|
|
||||||
impl ApubObject for Post {
|
impl ApubObject for Post {
|
||||||
type Form = PostForm;
|
type Form = PostForm;
|
||||||
|
|
||||||
|
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error> {
|
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::post::dsl::*;
|
use lemmy_db_schema::schema::post::dsl::*;
|
||||||
post.filter(ap_id.eq(object_id)).first::<Self>(conn)
|
post.filter(ap_id.eq(object_id)).first::<Self>(conn)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::{ApubObject, Crud, DeleteableOrRemoveable};
|
use crate::{ApubObject, Crud, DeleteableOrRemoveable};
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::{naive_now, source::private_message::*, DbUrl, PersonId, PrivateMessageId};
|
use lemmy_db_schema::{naive_now, source::private_message::*, DbUrl, PersonId, PrivateMessageId};
|
||||||
|
|
||||||
|
@ -31,6 +32,11 @@ impl Crud for PrivateMessage {
|
||||||
|
|
||||||
impl ApubObject for PrivateMessage {
|
impl ApubObject for PrivateMessage {
|
||||||
type Form = PrivateMessageForm;
|
type Form = PrivateMessageForm;
|
||||||
|
|
||||||
|
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error>
|
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
|
Loading…
Reference in New Issue