Support parsing like.object
either as URL or object
This commit is contained in:
parent
32f69775c3
commit
429b7f6e5c
13 changed files with 128 additions and 132 deletions
|
@ -1,6 +1,20 @@
|
||||||
use crate::{activities::receive::get_actor_as_user, objects::FromApub, ActorType, NoteExt};
|
use crate::{
|
||||||
|
activities::receive::{get_actor_as_user, get_like_object_id},
|
||||||
|
fetcher::get_or_fetch_and_insert_comment,
|
||||||
|
objects::FromApub,
|
||||||
|
ActorType,
|
||||||
|
NoteExt,
|
||||||
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{ActorAndObjectRefExt, Create, Dislike, Like, Remove, Update},
|
activity::{
|
||||||
|
kind::{DislikeType, LikeType},
|
||||||
|
ActorAndObjectRefExt,
|
||||||
|
Create,
|
||||||
|
Dislike,
|
||||||
|
Like,
|
||||||
|
Remove,
|
||||||
|
Update,
|
||||||
|
},
|
||||||
base::ExtendsExt,
|
base::ExtendsExt,
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
@ -23,7 +37,7 @@ pub(crate) async fn receive_create_comment(
|
||||||
let note = NoteExt::from_any_base(create.object().to_owned().one().context(location_info!())?)?
|
let note = NoteExt::from_any_base(create.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
let comment = Comment::from_apub(¬e, context, Some(user.actor_id()?), request_counter).await?;
|
let comment = Comment::from_apub(¬e, context, user.actor_id()?, request_counter).await?;
|
||||||
|
|
||||||
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??;
|
||||||
|
@ -66,7 +80,7 @@ pub(crate) async fn receive_update_comment(
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
let user = get_actor_as_user(&update, context, request_counter).await?;
|
let user = get_actor_as_user(&update, context, request_counter).await?;
|
||||||
|
|
||||||
let comment = Comment::from_apub(¬e, context, Some(user.actor_id()?), request_counter).await?;
|
let comment = Comment::from_apub(¬e, context, user.actor_id()?, request_counter).await?;
|
||||||
|
|
||||||
let comment_id = comment.id;
|
let comment_id = comment.id;
|
||||||
let post_id = comment.post_id;
|
let post_id = comment.post_id;
|
||||||
|
@ -102,11 +116,9 @@ pub(crate) async fn receive_like_comment(
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let note = NoteExt::from_any_base(like.object().to_owned().one().context(location_info!())?)?
|
|
||||||
.context(location_info!())?;
|
|
||||||
let user = get_actor_as_user(&like, context, request_counter).await?;
|
let user = get_actor_as_user(&like, context, request_counter).await?;
|
||||||
|
let comment_id = get_like_object_id::<Like, LikeType>(&like)?;
|
||||||
let comment = Comment::from_apub(¬e, context, None, request_counter).await?;
|
let comment = get_or_fetch_and_insert_comment(&comment_id, context, request_counter).await?;
|
||||||
|
|
||||||
let comment_id = comment.id;
|
let comment_id = comment.id;
|
||||||
let like_form = CommentLikeForm {
|
let like_form = CommentLikeForm {
|
||||||
|
@ -150,17 +162,9 @@ pub(crate) async fn receive_dislike_comment(
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let note = NoteExt::from_any_base(
|
|
||||||
dislike
|
|
||||||
.object()
|
|
||||||
.to_owned()
|
|
||||||
.one()
|
|
||||||
.context(location_info!())?,
|
|
||||||
)?
|
|
||||||
.context(location_info!())?;
|
|
||||||
let user = get_actor_as_user(&dislike, context, request_counter).await?;
|
let user = get_actor_as_user(&dislike, context, request_counter).await?;
|
||||||
|
let comment_id = get_like_object_id::<Dislike, DislikeType>(&dislike)?;
|
||||||
let comment = Comment::from_apub(¬e, context, None, request_counter).await?;
|
let comment = get_or_fetch_and_insert_comment(&comment_id, context, request_counter).await?;
|
||||||
|
|
||||||
let comment_id = comment.id;
|
let comment_id = comment.id;
|
||||||
let like_form = CommentLikeForm {
|
let like_form = CommentLikeForm {
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
use crate::{activities::receive::get_actor_as_user, objects::FromApub, NoteExt};
|
use crate::{
|
||||||
use activitystreams::{activity::*, prelude::*};
|
activities::receive::{get_actor_as_user, get_like_object_id},
|
||||||
use anyhow::Context;
|
fetcher::get_or_fetch_and_insert_comment,
|
||||||
|
};
|
||||||
|
use activitystreams::activity::{
|
||||||
|
kind::{DislikeType, LikeType},
|
||||||
|
*,
|
||||||
|
};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{Comment, CommentLike},
|
comment::{Comment, CommentLike},
|
||||||
comment_view::CommentView,
|
comment_view::CommentView,
|
||||||
Likeable,
|
Likeable,
|
||||||
};
|
};
|
||||||
use lemmy_structs::{blocking, comment::CommentResponse};
|
use lemmy_structs::{blocking, comment::CommentResponse};
|
||||||
use lemmy_utils::{location_info, LemmyError};
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
|
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
|
||||||
|
|
||||||
pub(crate) async fn receive_undo_like_comment(
|
pub(crate) async fn receive_undo_like_comment(
|
||||||
|
@ -16,10 +21,8 @@ pub(crate) async fn receive_undo_like_comment(
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let user = get_actor_as_user(like, context, request_counter).await?;
|
let user = get_actor_as_user(like, context, request_counter).await?;
|
||||||
let note = NoteExt::from_any_base(like.object().to_owned().one().context(location_info!())?)?
|
let comment_id = get_like_object_id::<Like, LikeType>(like)?;
|
||||||
.context(location_info!())?;
|
let comment = get_or_fetch_and_insert_comment(&comment_id, context, request_counter).await?;
|
||||||
|
|
||||||
let comment = Comment::from_apub(¬e, context, None, request_counter).await?;
|
|
||||||
|
|
||||||
let comment_id = comment.id;
|
let comment_id = comment.id;
|
||||||
let user_id = user.id;
|
let user_id = user.id;
|
||||||
|
@ -57,16 +60,8 @@ pub(crate) async fn receive_undo_dislike_comment(
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let user = get_actor_as_user(dislike, context, request_counter).await?;
|
let user = get_actor_as_user(dislike, context, request_counter).await?;
|
||||||
let note = NoteExt::from_any_base(
|
let comment_id = get_like_object_id::<Dislike, DislikeType>(dislike)?;
|
||||||
dislike
|
let comment = get_or_fetch_and_insert_comment(&comment_id, context, request_counter).await?;
|
||||||
.object()
|
|
||||||
.to_owned()
|
|
||||||
.one()
|
|
||||||
.context(location_info!())?,
|
|
||||||
)?
|
|
||||||
.context(location_info!())?;
|
|
||||||
|
|
||||||
let comment = Comment::from_apub(¬e, context, None, request_counter).await?;
|
|
||||||
|
|
||||||
let comment_id = comment.id;
|
let comment_id = comment.id;
|
||||||
let user_id = user.id;
|
let user_id = user.id;
|
||||||
|
|
|
@ -79,3 +79,28 @@ where
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(in crate::activities::receive) fn get_like_object_id<Activity, Kind>(
|
||||||
|
like_or_dislike: &Activity,
|
||||||
|
) -> Result<Url, LemmyError>
|
||||||
|
where
|
||||||
|
Activity: ActorAndObjectRefExt,
|
||||||
|
{
|
||||||
|
// For backwards compatibility with older Lemmy versions where like.object contains a full
|
||||||
|
// post/comment. This can be removed after some time, using
|
||||||
|
// `activity.oject().as_single_xsd_any_uri()` instead.
|
||||||
|
let object = like_or_dislike.object();
|
||||||
|
if let Some(xsd_uri) = object.as_single_xsd_any_uri() {
|
||||||
|
Ok(xsd_uri.to_owned())
|
||||||
|
} else {
|
||||||
|
Ok(
|
||||||
|
object
|
||||||
|
.to_owned()
|
||||||
|
.one()
|
||||||
|
.context(location_info!())?
|
||||||
|
.id()
|
||||||
|
.context(location_info!())?
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,19 @@
|
||||||
use crate::{activities::receive::get_actor_as_user, objects::FromApub, ActorType, PageExt};
|
use crate::{
|
||||||
|
activities::receive::{get_actor_as_user, get_like_object_id},
|
||||||
|
fetcher::get_or_fetch_and_insert_post,
|
||||||
|
objects::FromApub,
|
||||||
|
ActorType,
|
||||||
|
PageExt,
|
||||||
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{Create, Dislike, Like, Remove, Update},
|
activity::{
|
||||||
|
kind::{DislikeType, LikeType},
|
||||||
|
Create,
|
||||||
|
Dislike,
|
||||||
|
Like,
|
||||||
|
Remove,
|
||||||
|
Update,
|
||||||
|
},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
@ -22,7 +35,7 @@ pub(crate) async fn receive_create_post(
|
||||||
let page = PageExt::from_any_base(create.object().to_owned().one().context(location_info!())?)?
|
let page = PageExt::from_any_base(create.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
let post = Post::from_apub(&page, context, Some(user.actor_id()?), request_counter).await?;
|
let post = Post::from_apub(&page, context, user.actor_id()?, request_counter).await?;
|
||||||
|
|
||||||
// Refetch the view
|
// Refetch the view
|
||||||
let post_id = post.id;
|
let post_id = post.id;
|
||||||
|
@ -51,7 +64,7 @@ pub(crate) async fn receive_update_post(
|
||||||
let page = PageExt::from_any_base(update.object().to_owned().one().context(location_info!())?)?
|
let page = PageExt::from_any_base(update.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
let post = Post::from_apub(&page, context, Some(user.actor_id()?), request_counter).await?;
|
let post = Post::from_apub(&page, context, user.actor_id()?, request_counter).await?;
|
||||||
|
|
||||||
let post_id = post.id;
|
let post_id = post.id;
|
||||||
// Refetch the view
|
// Refetch the view
|
||||||
|
@ -77,10 +90,8 @@ pub(crate) async fn receive_like_post(
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let user = get_actor_as_user(&like, context, request_counter).await?;
|
let user = get_actor_as_user(&like, context, request_counter).await?;
|
||||||
let page = PageExt::from_any_base(like.object().to_owned().one().context(location_info!())?)?
|
let post_id = get_like_object_id::<Like, LikeType>(&like)?;
|
||||||
.context(location_info!())?;
|
let post = get_or_fetch_and_insert_post(&post_id, context, request_counter).await?;
|
||||||
|
|
||||||
let post = Post::from_apub(&page, context, None, request_counter).await?;
|
|
||||||
|
|
||||||
let post_id = post.id;
|
let post_id = post.id;
|
||||||
let like_form = PostLikeForm {
|
let like_form = PostLikeForm {
|
||||||
|
@ -118,16 +129,8 @@ pub(crate) async fn receive_dislike_post(
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let user = get_actor_as_user(&dislike, context, request_counter).await?;
|
let user = get_actor_as_user(&dislike, context, request_counter).await?;
|
||||||
let page = PageExt::from_any_base(
|
let post_id = get_like_object_id::<Dislike, DislikeType>(&dislike)?;
|
||||||
dislike
|
let post = get_or_fetch_and_insert_post(&post_id, context, request_counter).await?;
|
||||||
.object()
|
|
||||||
.to_owned()
|
|
||||||
.one()
|
|
||||||
.context(location_info!())?,
|
|
||||||
)?
|
|
||||||
.context(location_info!())?;
|
|
||||||
|
|
||||||
let post = Post::from_apub(&page, context, None, request_counter).await?;
|
|
||||||
|
|
||||||
let post_id = post.id;
|
let post_id = post.id;
|
||||||
let like_form = PostLikeForm {
|
let like_form = PostLikeForm {
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
use crate::{activities::receive::get_actor_as_user, objects::FromApub, PageExt};
|
use crate::{
|
||||||
use activitystreams::{activity::*, prelude::*};
|
activities::receive::{get_actor_as_user, get_like_object_id},
|
||||||
use anyhow::Context;
|
fetcher::get_or_fetch_and_insert_post,
|
||||||
|
};
|
||||||
|
use activitystreams::activity::{
|
||||||
|
kind::{DislikeType, LikeType},
|
||||||
|
*,
|
||||||
|
};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
post::{Post, PostLike},
|
post::{Post, PostLike},
|
||||||
post_view::PostView,
|
post_view::PostView,
|
||||||
Likeable,
|
Likeable,
|
||||||
};
|
};
|
||||||
use lemmy_structs::{blocking, post::PostResponse};
|
use lemmy_structs::{blocking, post::PostResponse};
|
||||||
use lemmy_utils::{location_info, LemmyError};
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
|
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
|
||||||
|
|
||||||
pub(crate) async fn receive_undo_like_post(
|
pub(crate) async fn receive_undo_like_post(
|
||||||
|
@ -16,10 +21,8 @@ pub(crate) async fn receive_undo_like_post(
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let user = get_actor_as_user(like, context, request_counter).await?;
|
let user = get_actor_as_user(like, context, request_counter).await?;
|
||||||
let page = PageExt::from_any_base(like.object().to_owned().one().context(location_info!())?)?
|
let post_id = get_like_object_id::<Like, LikeType>(&like)?;
|
||||||
.context(location_info!())?;
|
let post = get_or_fetch_and_insert_post(&post_id, context, request_counter).await?;
|
||||||
|
|
||||||
let post = Post::from_apub(&page, context, None, request_counter).await?;
|
|
||||||
|
|
||||||
let post_id = post.id;
|
let post_id = post.id;
|
||||||
let user_id = user.id;
|
let user_id = user.id;
|
||||||
|
@ -51,16 +54,8 @@ pub(crate) async fn receive_undo_dislike_post(
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let user = get_actor_as_user(dislike, context, request_counter).await?;
|
let user = get_actor_as_user(dislike, context, request_counter).await?;
|
||||||
let page = PageExt::from_any_base(
|
let post_id = get_like_object_id::<Dislike, DislikeType>(&dislike)?;
|
||||||
dislike
|
let post = get_or_fetch_and_insert_post(&post_id, context, request_counter).await?;
|
||||||
.object()
|
|
||||||
.to_owned()
|
|
||||||
.one()
|
|
||||||
.context(location_info!())?,
|
|
||||||
)?
|
|
||||||
.context(location_info!())?;
|
|
||||||
|
|
||||||
let post = Post::from_apub(&page, context, None, request_counter).await?;
|
|
||||||
|
|
||||||
let post_id = post.id;
|
let post_id = post.id;
|
||||||
let user_id = user.id;
|
let user_id = user.id;
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub(crate) async fn receive_create_private_message(
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
let private_message =
|
let private_message =
|
||||||
PrivateMessage::from_apub(¬e, context, Some(expected_domain), request_counter).await?;
|
PrivateMessage::from_apub(¬e, context, expected_domain, request_counter).await?;
|
||||||
|
|
||||||
let message = blocking(&context.pool(), move |conn| {
|
let message = blocking(&context.pool(), move |conn| {
|
||||||
PrivateMessageView::read(conn, private_message.id)
|
PrivateMessageView::read(conn, private_message.id)
|
||||||
|
@ -74,7 +74,7 @@ pub(crate) async fn receive_update_private_message(
|
||||||
let note = NoteExt::from_any_base(object)?.context(location_info!())?;
|
let note = NoteExt::from_any_base(object)?.context(location_info!())?;
|
||||||
|
|
||||||
let private_message =
|
let private_message =
|
||||||
PrivateMessage::from_apub(¬e, context, Some(expected_domain), request_counter).await?;
|
PrivateMessage::from_apub(¬e, context, expected_domain, request_counter).await?;
|
||||||
|
|
||||||
let private_message_id = private_message.id;
|
let private_message_id = private_message.id;
|
||||||
let message = blocking(&context.pool(), move |conn| {
|
let message = blocking(&context.pool(), move |conn| {
|
||||||
|
|
|
@ -184,7 +184,7 @@ pub async fn search_by_apub_id(
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
SearchAcceptedObjects::Page(p) => {
|
SearchAcceptedObjects::Page(p) => {
|
||||||
let p = Post::from_apub(&p, context, Some(query_url), recursion_counter).await?;
|
let p = Post::from_apub(&p, context, query_url, recursion_counter).await?;
|
||||||
|
|
||||||
response.posts =
|
response.posts =
|
||||||
vec![blocking(context.pool(), move |conn| PostView::read(conn, p.id, None)).await??];
|
vec![blocking(context.pool(), move |conn| PostView::read(conn, p.id, None)).await??];
|
||||||
|
@ -192,7 +192,7 @@ pub async fn search_by_apub_id(
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
SearchAcceptedObjects::Comment(c) => {
|
SearchAcceptedObjects::Comment(c) => {
|
||||||
let c = Comment::from_apub(&c, context, Some(query_url), recursion_counter).await?;
|
let c = Comment::from_apub(&c, context, query_url, recursion_counter).await?;
|
||||||
|
|
||||||
response.comments = vec![
|
response.comments = vec![
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
|
@ -252,13 +252,7 @@ pub(crate) async fn get_or_fetch_and_upsert_user(
|
||||||
return Ok(u);
|
return Ok(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = User_::from_apub(
|
let user = User_::from_apub(&person?, context, apub_id.to_owned(), recursion_counter).await?;
|
||||||
&person?,
|
|
||||||
context,
|
|
||||||
Some(apub_id.to_owned()),
|
|
||||||
recursion_counter,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let user_id = user.id;
|
let user_id = user.id;
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
|
@ -274,13 +268,7 @@ pub(crate) async fn get_or_fetch_and_upsert_user(
|
||||||
let person =
|
let person =
|
||||||
fetch_remote_object::<PersonExt>(context.client(), apub_id, recursion_counter).await?;
|
fetch_remote_object::<PersonExt>(context.client(), apub_id, recursion_counter).await?;
|
||||||
|
|
||||||
let user = User_::from_apub(
|
let user = User_::from_apub(&person, context, apub_id.to_owned(), recursion_counter).await?;
|
||||||
&person,
|
|
||||||
context,
|
|
||||||
Some(apub_id.to_owned()),
|
|
||||||
recursion_counter,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(user)
|
Ok(user)
|
||||||
}
|
}
|
||||||
|
@ -352,7 +340,7 @@ async fn fetch_remote_community(
|
||||||
|
|
||||||
let group = group?;
|
let group = group?;
|
||||||
let community =
|
let community =
|
||||||
Community::from_apub(&group, context, Some(apub_id.to_owned()), recursion_counter).await?;
|
Community::from_apub(&group, context, apub_id.to_owned(), recursion_counter).await?;
|
||||||
|
|
||||||
// Also add the community moderators too
|
// Also add the community moderators too
|
||||||
let attributed_to = group.inner.attributed_to().context(location_info!())?;
|
let attributed_to = group.inner.attributed_to().context(location_info!())?;
|
||||||
|
@ -402,13 +390,13 @@ async fn fetch_remote_community(
|
||||||
}
|
}
|
||||||
for o in outbox_items {
|
for o in outbox_items {
|
||||||
let page = PageExt::from_any_base(o)?.context(location_info!())?;
|
let page = PageExt::from_any_base(o)?.context(location_info!())?;
|
||||||
|
let page_id = page.id_unchecked().context(location_info!())?;
|
||||||
|
|
||||||
// The post creator may be from a blocked instance,
|
// The post creator may be from a blocked instance, if it errors, then skip it
|
||||||
// if it errors, then continue
|
if check_is_apub_id_valid(page_id).is_err() {
|
||||||
match Post::from_apub(&page, context, None, recursion_counter).await {
|
continue;
|
||||||
Ok(post) => post,
|
}
|
||||||
Err(_) => continue,
|
Post::from_apub(&page, context, page_id.to_owned(), recursion_counter).await?;
|
||||||
};
|
|
||||||
// TODO: we need to send a websocket update here
|
// TODO: we need to send a websocket update here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,13 +424,7 @@ pub(crate) async fn get_or_fetch_and_insert_post(
|
||||||
debug!("Fetching and creating remote post: {}", post_ap_id);
|
debug!("Fetching and creating remote post: {}", post_ap_id);
|
||||||
let page =
|
let page =
|
||||||
fetch_remote_object::<PageExt>(context.client(), post_ap_id, recursion_counter).await?;
|
fetch_remote_object::<PageExt>(context.client(), post_ap_id, recursion_counter).await?;
|
||||||
let post = Post::from_apub(
|
let post = Post::from_apub(&page, context, post_ap_id.to_owned(), recursion_counter).await?;
|
||||||
&page,
|
|
||||||
context,
|
|
||||||
Some(post_ap_id.to_owned()),
|
|
||||||
recursion_counter,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(post)
|
Ok(post)
|
||||||
}
|
}
|
||||||
|
@ -477,7 +459,7 @@ pub(crate) async fn get_or_fetch_and_insert_comment(
|
||||||
let comment = Comment::from_apub(
|
let comment = Comment::from_apub(
|
||||||
&comment,
|
&comment,
|
||||||
context,
|
context,
|
||||||
Some(comment_ap_id.to_owned()),
|
comment_ap_id.to_owned(),
|
||||||
recursion_counter,
|
recursion_counter,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -99,7 +99,7 @@ impl FromApub for Comment {
|
||||||
async fn from_apub(
|
async fn from_apub(
|
||||||
note: &NoteExt,
|
note: &NoteExt,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<Comment, LemmyError> {
|
) -> Result<Comment, LemmyError> {
|
||||||
check_object_for_community_or_site_ban(note, context, request_counter).await?;
|
check_object_for_community_or_site_ban(note, context, request_counter).await?;
|
||||||
|
@ -128,7 +128,7 @@ impl FromApubToForm<NoteExt> for CommentForm {
|
||||||
async fn from_apub(
|
async fn from_apub(
|
||||||
note: &NoteExt,
|
note: &NoteExt,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<CommentForm, LemmyError> {
|
) -> Result<CommentForm, LemmyError> {
|
||||||
let creator_actor_id = ¬e
|
let creator_actor_id = ¬e
|
||||||
|
|
|
@ -117,7 +117,7 @@ impl FromApub for Community {
|
||||||
async fn from_apub(
|
async fn from_apub(
|
||||||
group: &GroupExt,
|
group: &GroupExt,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<Community, LemmyError> {
|
) -> Result<Community, LemmyError> {
|
||||||
get_object_from_apub(group, context, expected_domain, request_counter).await
|
get_object_from_apub(group, context, expected_domain, request_counter).await
|
||||||
|
@ -129,7 +129,7 @@ impl FromApubToForm<GroupExt> for CommunityForm {
|
||||||
async fn from_apub(
|
async fn from_apub(
|
||||||
group: &GroupExt,
|
group: &GroupExt,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<Self, LemmyError> {
|
) -> Result<Self, LemmyError> {
|
||||||
let creator_and_moderator_uris = group.inner.attributed_to().context(location_info!())?;
|
let creator_and_moderator_uris = group.inner.attributed_to().context(location_info!())?;
|
||||||
|
|
|
@ -38,12 +38,11 @@ pub(crate) trait FromApub {
|
||||||
///
|
///
|
||||||
/// * `apub` The object to read from
|
/// * `apub` The object to read from
|
||||||
/// * `context` LemmyContext which holds DB pool, HTTP client etc
|
/// * `context` LemmyContext which holds DB pool, HTTP client etc
|
||||||
/// * `expected_domain` If present, ensure that the domains of this and of the apub object ID are
|
/// * `expected_domain` Domain where the object was received from
|
||||||
/// identical
|
|
||||||
async fn from_apub(
|
async fn from_apub(
|
||||||
apub: &Self::ApubType,
|
apub: &Self::ApubType,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<Self, LemmyError>
|
) -> Result<Self, LemmyError>
|
||||||
where
|
where
|
||||||
|
@ -55,7 +54,7 @@ pub(in crate::objects) trait FromApubToForm<ApubType> {
|
||||||
async fn from_apub(
|
async fn from_apub(
|
||||||
apub: &ApubType,
|
apub: &ApubType,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<Self, LemmyError>
|
) -> Result<Self, LemmyError>
|
||||||
where
|
where
|
||||||
|
@ -89,17 +88,13 @@ where
|
||||||
|
|
||||||
pub(in crate::objects) fn check_object_domain<T, Kind>(
|
pub(in crate::objects) fn check_object_domain<T, Kind>(
|
||||||
apub: &T,
|
apub: &T,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
) -> Result<String, LemmyError>
|
) -> Result<String, LemmyError>
|
||||||
where
|
where
|
||||||
T: Base + AsBase<Kind>,
|
T: Base + AsBase<Kind>,
|
||||||
{
|
{
|
||||||
let object_id = if let Some(url) = expected_domain {
|
let domain = expected_domain.domain().context(location_info!())?;
|
||||||
let domain = url.domain().context(location_info!())?;
|
let object_id = apub.id(domain)?.context(location_info!())?;
|
||||||
apub.id(domain)?.context(location_info!())?
|
|
||||||
} else {
|
|
||||||
apub.id_unchecked().context(location_info!())?
|
|
||||||
};
|
|
||||||
check_is_apub_id_valid(&object_id)?;
|
check_is_apub_id_valid(&object_id)?;
|
||||||
Ok(object_id.to_string())
|
Ok(object_id.to_string())
|
||||||
}
|
}
|
||||||
|
@ -180,7 +175,7 @@ pub(in crate::objects) fn check_is_markdown(mime: Option<&Mime>) -> Result<(), L
|
||||||
pub(in crate::objects) async fn get_object_from_apub<From, Kind, To, ToForm>(
|
pub(in crate::objects) async fn get_object_from_apub<From, Kind, To, ToForm>(
|
||||||
from: &From,
|
from: &From,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<To, LemmyError>
|
) -> Result<To, LemmyError>
|
||||||
where
|
where
|
||||||
|
@ -191,7 +186,7 @@ where
|
||||||
let object_id = from.id_unchecked().context(location_info!())?.to_owned();
|
let object_id = from.id_unchecked().context(location_info!())?.to_owned();
|
||||||
let domain = object_id.domain().context(location_info!())?;
|
let domain = object_id.domain().context(location_info!())?;
|
||||||
|
|
||||||
// if we already have the object in our database, return that directly
|
// if its a local object, return it directly from the database
|
||||||
if Settings::get().hostname == domain {
|
if Settings::get().hostname == domain {
|
||||||
let object = blocking(context.pool(), move |conn| {
|
let object = blocking(context.pool(), move |conn| {
|
||||||
To::read_from_apub_id(conn, object_id.as_str())
|
To::read_from_apub_id(conn, object_id.as_str())
|
||||||
|
@ -199,10 +194,7 @@ where
|
||||||
.await??;
|
.await??;
|
||||||
Ok(object)
|
Ok(object)
|
||||||
}
|
}
|
||||||
// if we dont have it, parse from apub and insert into database
|
// otherwise parse and insert, assuring that it comes from the right domain
|
||||||
// TODO: this is insecure, a `Like/Post` could result in a non-existent post from a different
|
|
||||||
// instance being inserted into our database. we should request the object over http in that
|
|
||||||
// case. this might happen exactly in the case where expected_domain = None, but i'm not sure.
|
|
||||||
else {
|
else {
|
||||||
let to_form = ToForm::from_apub(&from, context, expected_domain, request_counter).await?;
|
let to_form = ToForm::from_apub(&from, context, expected_domain, request_counter).await?;
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ impl FromApub for Post {
|
||||||
async fn from_apub(
|
async fn from_apub(
|
||||||
page: &PageExt,
|
page: &PageExt,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<Post, LemmyError> {
|
) -> Result<Post, LemmyError> {
|
||||||
check_object_for_community_or_site_ban(page, context, request_counter).await?;
|
check_object_for_community_or_site_ban(page, context, request_counter).await?;
|
||||||
|
@ -123,7 +123,7 @@ impl FromApubToForm<PageExt> for PostForm {
|
||||||
async fn from_apub(
|
async fn from_apub(
|
||||||
page: &PageExt,
|
page: &PageExt,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<PostForm, LemmyError> {
|
) -> Result<PostForm, LemmyError> {
|
||||||
let ext = &page.ext_one;
|
let ext = &page.ext_one;
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl FromApub for PrivateMessage {
|
||||||
async fn from_apub(
|
async fn from_apub(
|
||||||
note: &NoteExt,
|
note: &NoteExt,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<PrivateMessage, LemmyError> {
|
) -> Result<PrivateMessage, LemmyError> {
|
||||||
get_object_from_apub(note, context, expected_domain, request_counter).await
|
get_object_from_apub(note, context, expected_domain, request_counter).await
|
||||||
|
@ -83,7 +83,7 @@ impl FromApubToForm<NoteExt> for PrivateMessageForm {
|
||||||
async fn from_apub(
|
async fn from_apub(
|
||||||
note: &NoteExt,
|
note: &NoteExt,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<PrivateMessageForm, LemmyError> {
|
) -> Result<PrivateMessageForm, LemmyError> {
|
||||||
let creator_actor_id = note
|
let creator_actor_id = note
|
||||||
|
|
|
@ -95,7 +95,7 @@ impl FromApub for User_ {
|
||||||
async fn from_apub(
|
async fn from_apub(
|
||||||
person: &PersonExt,
|
person: &PersonExt,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<User_, LemmyError> {
|
) -> Result<User_, LemmyError> {
|
||||||
let user_id = person.id_unchecked().context(location_info!())?.to_owned();
|
let user_id = person.id_unchecked().context(location_info!())?.to_owned();
|
||||||
|
@ -120,7 +120,7 @@ impl FromApubToForm<PersonExt> for UserForm {
|
||||||
async fn from_apub(
|
async fn from_apub(
|
||||||
person: &PersonExt,
|
person: &PersonExt,
|
||||||
_context: &LemmyContext,
|
_context: &LemmyContext,
|
||||||
expected_domain: Option<Url>,
|
expected_domain: Url,
|
||||||
_request_counter: &mut i32,
|
_request_counter: &mut i32,
|
||||||
) -> Result<Self, LemmyError> {
|
) -> Result<Self, LemmyError> {
|
||||||
let avatar = match person.icon() {
|
let avatar = match person.icon() {
|
||||||
|
|
Loading…
Reference in a new issue