rewrite person fetch to use new fetcher

rewrite-fetcher
Felix Ableitner 2021-09-22 15:58:34 +02:00
parent 0ed466dfdd
commit 27e409442a
31 changed files with 109 additions and 131 deletions

View File

@ -1,4 +1,4 @@
use crate::{fetcher::person::get_or_fetch_and_upsert_person, ActorType};
use crate::{fetcher::new_fetcher::dereference, ActorType};
use activitystreams::{
base::BaseExt,
link::{LinkExt, Mention},
@ -33,7 +33,7 @@ async fn get_notif_recipients(
) -> Result<Vec<LocalUserId>, LemmyError> {
let post_id = comment.post_id;
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:
// 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);
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());
let mut mention_tag = Mention::new();

View File

@ -9,7 +9,7 @@ use crate::{
},
activity_queue::send_to_community_new,
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,
ActorType,
};
@ -95,7 +95,7 @@ impl ActivityHandler for AddMod {
) -> Result<(), LemmyError> {
let community =
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
// been added. Skip it here as it would result in a duplicate key error.

View File

@ -8,7 +8,7 @@ use crate::{
},
activity_queue::send_to_community_new,
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,
};
use activitystreams::{
@ -104,8 +104,7 @@ impl ActivityHandler for BlockUserFromCommunity {
) -> Result<(), LemmyError> {
let community =
get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
let blocked_user =
get_or_fetch_and_upsert_person(&self.object, context, request_counter).await?;
let blocked_user = dereference::<Person>(&self.object, context, request_counter).await?;
let community_user_ban_form = CommunityPersonBanForm {
community_id: community.id,

View File

@ -10,7 +10,7 @@ use crate::{
},
activity_queue::send_to_community_new,
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,
ActorType,
};
@ -110,8 +110,7 @@ impl ActivityHandler for RemoveMod {
if self.target.is_some() {
let community =
get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
let remove_mod =
get_or_fetch_and_upsert_person(&self.object, context, request_counter).await?;
let remove_mod = dereference::<Person>(&self.object, context, request_counter).await?;
let form = CommunityModeratorForm {
community_id: community.id,

View File

@ -8,7 +8,7 @@ use crate::{
},
activity_queue::send_to_community_new,
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,
};
use activitystreams::{
@ -93,8 +93,7 @@ impl ActivityHandler for UndoBlockUserFromCommunity {
) -> Result<(), LemmyError> {
let community =
get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
let blocked_user =
get_or_fetch_and_upsert_person(&self.object.object, context, request_counter).await?;
let blocked_user = dereference::<Person>(&self.object.object, context, request_counter).await?;
let community_user_ban_form = CommunityPersonBanForm {
community_id: community.id,

View File

@ -12,7 +12,7 @@ use crate::{
},
activity_queue::send_to_community_new,
extensions::context::lemmy_context,
fetcher::person::get_or_fetch_and_upsert_person,
fetcher::new_fetcher::dereference,
ActorType,
};
use activitystreams::{
@ -171,7 +171,7 @@ pub(in crate::activities) async fn receive_remove_action(
context: &LemmyContext,
request_counter: &mut i32,
) -> 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::*;
match DeletableObjects::read_from_db(object, context).await? {
DeletableObjects::Community(community) => {

View File

@ -4,7 +4,7 @@ use crate::{
verify_mod_action,
verify_person_in_community,
},
fetcher::person::get_or_fetch_and_upsert_person,
fetcher::new_fetcher::dereference,
ActorType,
};
use lemmy_api_common::blocking;
@ -180,7 +180,7 @@ async fn receive_delete_action(
match DeletableObjects::read_from_db(object, context).await? {
DeletableObjects::Community(community) => {
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();
send_apub_delete(&mod_, &community.clone(), object, true, context).await?;
}

View File

@ -7,7 +7,7 @@ use crate::{
},
activity_queue::send_activity_new,
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,
};
use activitystreams::{
@ -91,7 +91,7 @@ impl ActivityHandler for AcceptFollowCommunity {
request_counter: &mut i32,
) -> Result<(), LemmyError> {
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
blocking(context.pool(), move |conn| {
CommunityFollower::follow_accepted(conn, actor.id, to.id)

View File

@ -7,7 +7,7 @@ use crate::{
},
activity_queue::send_activity_new,
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,
};
use activitystreams::{
@ -97,7 +97,7 @@ impl ActivityHandler for FollowCommunity {
context: &LemmyContext,
request_counter: &mut i32,
) -> 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.object, context, request_counter).await?;
let community_follower_form = CommunityFollowerForm {

View File

@ -7,7 +7,7 @@ use crate::{
},
activity_queue::send_activity_new,
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,
};
use activitystreams::{
@ -84,7 +84,7 @@ impl ActivityHandler for UndoFollowCommunity {
context: &LemmyContext,
request_counter: &mut i32,
) -> 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_follower_form = CommunityFollowerForm {

View File

@ -1,7 +1,7 @@
use crate::{
check_community_or_site_ban,
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,
};
use anyhow::anyhow;
@ -43,7 +43,7 @@ async fn verify_person(
context: &LemmyContext,
request_counter: &mut i32,
) -> 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 {
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,
) -> Result<(), LemmyError> {
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
}

View File

@ -10,7 +10,7 @@ use crate::{
},
activity_queue::send_to_community_new,
extensions::context::lemmy_context,
fetcher::person::get_or_fetch_and_upsert_person,
fetcher::new_fetcher::dereference,
objects::{post::Page, FromApub, ToApub},
ActorType,
};
@ -121,7 +121,7 @@ impl ActivityHandler for CreateOrUpdatePost {
context: &LemmyContext,
request_counter: &mut i32,
) -> 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 notif_type = match self.kind {

View File

@ -12,7 +12,7 @@ use crate::{
},
activity_queue::send_to_community_new,
extensions::context::lemmy_context,
fetcher::{new_fetcher::dereference, person::get_or_fetch_and_upsert_person},
fetcher::new_fetcher::dereference,
ActorType,
PostOrComment,
};
@ -100,7 +100,7 @@ impl ActivityHandler for UndoVote {
context: &LemmyContext,
request_counter: &mut i32,
) -> 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.object, context, request_counter).await?;
match object {

View File

@ -8,7 +8,7 @@ use crate::{
},
activity_queue::send_to_community_new,
extensions::context::lemmy_context,
fetcher::{new_fetcher::dereference, person::get_or_fetch_and_upsert_person},
fetcher::new_fetcher::dereference,
ActorType,
PostOrComment,
};
@ -126,7 +126,7 @@ impl ActivityHandler for Vote {
context: &LemmyContext,
request_counter: &mut i32,
) -> 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?;
match object {
PostOrComment::Post(p) => vote_post(&self.kind, actor, p.deref(), context).await,

View File

@ -3,7 +3,7 @@ use crate::{
fetcher::{
fetch::fetch_remote_object,
is_deleted,
person::get_or_fetch_and_upsert_person,
new_fetcher::dereference,
should_refetch_actor,
},
objects::{community::Group, FromApub},
@ -14,7 +14,10 @@ use diesel::result::Error::NotFound;
use lemmy_api_common::blocking;
use lemmy_apub_lib::ActivityHandler;
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_utils::{location_info, LemmyError};
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
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
.clone()

View File

@ -1,7 +1,6 @@
pub mod community;
mod fetch;
pub mod new_fetcher;
pub mod person;
pub mod post_or_comment;
pub mod search;
@ -9,13 +8,13 @@ use crate::{
fetcher::{
community::get_or_fetch_and_upsert_community,
fetch::FetchError,
person::get_or_fetch_and_upsert_person,
new_fetcher::dereference,
},
ActorType,
};
use chrono::NaiveDateTime;
use http::StatusCode;
use lemmy_db_schema::naive_now;
use lemmy_db_schema::{naive_now, source::person::Person};
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
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 actor: Box<dyn ActorType> = match community {
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)
}

View File

@ -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 diesel::NotFound;
use lemmy_api_common::blocking;
use lemmy_db_queries::{ApubObject, DbPool};
use lemmy_utils::{request::retry, settings::structs::Settings, LemmyError};
use lemmy_websocket::LemmyContext;
use log::debug;
use reqwest::StatusCode;
use std::time::Duration;
use url::Url;
@ -23,11 +24,27 @@ where
Kind: FromApub + ApubObject + Send + 'static,
for<'de> <Kind as FromApub>::ApubType: serde::Deserialize<'de>,
{
let local_object = dereference_locally(id.clone(), context.pool()).await?;
if let Some(object) = local_object {
// TODO: for actors, also refetch after 24 hours
let db_object = dereference_locally::<Kind>(id.clone(), context.pool()).await?;
// if its a local object, only fetch it from the database and not over http
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)
} else {
debug!("Fetching remote object {}", id);
dereference_remotely(id, context, request_counter).await
}
}

View File

@ -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()),
}
}

View File

@ -1,4 +1,5 @@
use crate::objects::{comment::Note, post::Page, FromApub};
use activitystreams::chrono::NaiveDateTime;
use diesel::{result::Error, PgConnection};
use lemmy_db_queries::ApubObject;
use lemmy_db_schema::{
@ -33,6 +34,10 @@ pub enum PageOrNote {
impl ApubObject for PostOrComment {
type Form = PostOrCommentForm;
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
None
}
// TODO: this can probably be implemented using a single sql query
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error>
where

View File

@ -3,7 +3,7 @@ use crate::{
community::get_or_fetch_and_upsert_community,
fetch::fetch_remote_object,
is_deleted,
person::get_or_fetch_and_upsert_person,
new_fetcher::dereference,
},
find_object_by_id,
objects::{comment::Note, community::Group, person::Person as ApubPerson, post::Page, FromApub},
@ -131,7 +131,7 @@ async fn build_response(
SearchAcceptedObjects::Person(p) => {
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 {
person: blocking(context.pool(), move |conn| {
PersonViewSafe::read(conn, person.id)

View File

@ -3,7 +3,7 @@ use crate::{
extensions::context::lemmy_context,
fetcher::new_fetcher::dereference,
migrations::CommentInReplyToMigration,
objects::{create_tombstone, get_or_fetch_and_upsert_person, FromApub, Source, ToApub},
objects::{create_tombstone, FromApub, Source, ToApub},
ActorType,
PostOrComment,
};
@ -216,8 +216,7 @@ impl FromApub for Comment {
request_counter: &mut i32,
) -> Result<Comment, LemmyError> {
let ap_id = Some(note.id(expected_domain)?.clone().into());
let creator =
get_or_fetch_and_upsert_person(&note.attributed_to, context, request_counter).await?;
let creator = dereference::<Person>(&note.attributed_to, context, request_counter).await?;
let (post, parent_comment_id) = note.get_parents(context, request_counter).await?;
if post.locked {
return Err(anyhow!("Post is locked").into());

View File

@ -1,4 +1,3 @@
use crate::fetcher::person::get_or_fetch_and_upsert_person;
use activitystreams::{
base::BaseExt,
object::{kind::ImageType, Tombstone, TombstoneExt},

View File

@ -1,7 +1,7 @@
use crate::{
activities::{extract_community, verify_person_in_community},
extensions::context::lemmy_context,
fetcher::person::get_or_fetch_and_upsert_person,
fetcher::new_fetcher::dereference,
objects::{create_tombstone, FromApub, ImageObject, Source, ToApub},
ActorType,
};
@ -183,8 +183,7 @@ impl FromApub for Post {
page.id(expected_domain)?
};
let ap_id = Some(ap_id.clone().into());
let creator =
get_or_fetch_and_upsert_person(&page.attributed_to, context, request_counter).await?;
let creator = dereference::<Person>(&page.attributed_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);

View File

@ -1,6 +1,6 @@
use crate::{
extensions::context::lemmy_context,
fetcher::person::get_or_fetch_and_upsert_person,
fetcher::new_fetcher::dereference,
objects::{create_tombstone, FromApub, Source, ToApub},
};
use activitystreams::{
@ -61,8 +61,7 @@ impl Note {
request_counter: &mut i32,
) -> Result<(), LemmyError> {
verify_domains_match(&self.attributed_to, &self.id)?;
let person =
get_or_fetch_and_upsert_person(&self.attributed_to, context, request_counter).await?;
let person = dereference::<Person>(&self.attributed_to, context, request_counter).await?;
if person.banned {
return Err(anyhow!("Person is banned from site").into());
}
@ -121,9 +120,8 @@ impl FromApub for PrivateMessage {
request_counter: &mut i32,
) -> Result<PrivateMessage, LemmyError> {
let ap_id = Some(note.id(expected_domain)?.clone().into());
let creator =
get_or_fetch_and_upsert_person(&note.attributed_to, context, request_counter).await?;
let recipient = get_or_fetch_and_upsert_person(&note.to, context, request_counter).await?;
let creator = dereference::<Person>(&note.attributed_to, context, request_counter).await?;
let recipient = dereference::<Person>(&note.to, context, request_counter).await?;
let form = PrivateMessageForm {
creator_id: creator.id,

View File

@ -12,6 +12,7 @@ extern crate diesel_migrations;
#[cfg(test)]
extern crate serial_test;
use chrono::NaiveDateTime;
use diesel::{result::Error, *};
use lemmy_db_schema::{CommunityId, DbUrl, PersonId};
use lemmy_utils::ApiError;
@ -147,6 +148,9 @@ pub trait DeleteableOrRemoveable {
pub trait ApubObject {
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>
where
Self: Sized;

View File

@ -1,7 +1,6 @@
use crate::Crud;
use diesel::{dsl::*, result::Error, sql_types::Text, *};
use lemmy_db_schema::{source::activity::*, DbUrl};
use log::debug;
use serde::Serialize;
use serde_json::Value;
use std::{
@ -72,7 +71,6 @@ impl Activity_ for Activity {
where
T: Serialize + Debug,
{
debug!("{}", serde_json::to_string_pretty(&data)?);
let activity_form = ActivityForm {
ap_id,
data: serde_json::to_value(&data)?,

View File

@ -1,4 +1,5 @@
use crate::{ApubObject, Crud, DeleteableOrRemoveable, Likeable, Saveable};
use chrono::NaiveDateTime;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{
naive_now,
@ -169,6 +170,11 @@ impl Crud for Comment {
impl ApubObject for Comment {
type Form = CommentForm;
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
None
}
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error> {
use lemmy_db_schema::schema::comment::dsl::*;
comment.filter(ap_id.eq(object_id)).first::<Self>(conn)

View File

@ -1,4 +1,5 @@
use crate::{ApubObject, Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable};
use chrono::NaiveDateTime;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{
naive_now,
@ -94,6 +95,11 @@ impl Crud for Community {
impl ApubObject for Community {
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> {
use lemmy_db_schema::schema::community::dsl::*;
community

View File

@ -1,4 +1,5 @@
use crate::{ApubObject, Crud};
use chrono::NaiveDateTime;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{
naive_now,
@ -182,6 +183,11 @@ impl Crud for Person {
impl ApubObject for Person {
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> {
use lemmy_db_schema::schema::person::dsl::*;
person

View File

@ -1,4 +1,5 @@
use crate::{ApubObject, Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable};
use chrono::NaiveDateTime;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{
naive_now,
@ -183,6 +184,11 @@ impl Post_ for Post {
impl ApubObject for Post {
type Form = PostForm;
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
None
}
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error> {
use lemmy_db_schema::schema::post::dsl::*;
post.filter(ap_id.eq(object_id)).first::<Self>(conn)

View File

@ -1,4 +1,5 @@
use crate::{ApubObject, Crud, DeleteableOrRemoveable};
use chrono::NaiveDateTime;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{naive_now, source::private_message::*, DbUrl, PersonId, PrivateMessageId};
@ -31,6 +32,11 @@ impl Crud for PrivateMessage {
impl ApubObject for PrivateMessage {
type Form = PrivateMessageForm;
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
None
}
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error>
where
Self: Sized,