From 8ad43789602db4701e00253aa2e87524d8324b1d Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 29 Jul 2020 13:58:39 +0200 Subject: [PATCH] Disable ID domain check in FromApub until we figure it out properly --- server/src/apub/comment.rs | 3 +-- server/src/apub/community.rs | 13 ++----------- server/src/apub/fetcher.rs | 18 +++++++++--------- server/src/apub/inbox/activities/create.rs | 5 ++--- server/src/apub/inbox/activities/delete.rs | 7 +++---- server/src/apub/inbox/activities/dislike.rs | 5 ++--- server/src/apub/inbox/activities/like.rs | 5 ++--- server/src/apub/inbox/activities/remove.rs | 7 +++---- server/src/apub/inbox/activities/undo.rs | 17 ++++++++--------- server/src/apub/inbox/activities/update.rs | 5 ++--- server/src/apub/inbox/user_inbox.rs | 8 ++++---- server/src/apub/mod.rs | 1 - server/src/apub/post.rs | 7 +------ server/src/apub/private_message.rs | 3 +-- server/src/apub/user.rs | 9 ++------- 15 files changed, 42 insertions(+), 71 deletions(-) diff --git a/server/src/apub/comment.rs b/server/src/apub/comment.rs index 269e7fc25..650c60577 100644 --- a/server/src/apub/comment.rs +++ b/server/src/apub/comment.rs @@ -131,7 +131,6 @@ impl FromApub for CommentForm { note: &Note, client: &Client, pool: &DbPool, - actor_id: &Url, ) -> Result { let creator_actor_id = ¬e .attributed_to() @@ -182,7 +181,7 @@ impl FromApub for CommentForm { published: note.published().map(|u| u.to_owned().naive_local()), updated: note.updated().map(|u| u.to_owned().naive_local()), deleted: None, - ap_id: note.id(actor_id.domain().unwrap())?.unwrap().to_string(), + ap_id: note.id_unchecked().unwrap().to_string(), local: false, }) } diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs index b60059aa3..112b6e851 100644 --- a/server/src/apub/community.rs +++ b/server/src/apub/community.rs @@ -321,12 +321,7 @@ impl FromApub for CommunityForm { type ApubType = GroupExt; /// Parse an ActivityPub group received from another instance into a Lemmy community. - async fn from_apub( - group: &GroupExt, - client: &Client, - pool: &DbPool, - actor_id: &Url, - ) -> Result { + async fn from_apub(group: &GroupExt, client: &Client, pool: &DbPool) -> Result { let creator_and_moderator_uris = group.inner.attributed_to().unwrap(); let creator_uri = creator_and_moderator_uris .as_many() @@ -363,11 +358,7 @@ impl FromApub for CommunityForm { updated: group.inner.updated().map(|u| u.to_owned().naive_local()), deleted: None, nsfw: group.ext_one.sensitive, - actor_id: group - .inner - .id(actor_id.domain().unwrap())? - .unwrap() - .to_string(), + actor_id: group.inner.id_unchecked().unwrap().to_string(), local: false, private_key: None, public_key: Some(group.ext_two.to_owned().public_key.public_key_pem), diff --git a/server/src/apub/fetcher.rs b/server/src/apub/fetcher.rs index ff1ec11b7..c10426d14 100644 --- a/server/src/apub/fetcher.rs +++ b/server/src/apub/fetcher.rs @@ -172,7 +172,7 @@ pub async fn search_by_apub_id( response } SearchAcceptedObjects::Page(p) => { - let post_form = PostForm::from_apub(&p, client, pool, &query_url).await?; + let post_form = PostForm::from_apub(&p, client, pool).await?; let p = blocking(pool, move |conn| upsert_post(&post_form, conn)).await??; response.posts = vec![blocking(pool, move |conn| PostView::read(conn, p.id, None)).await??]; @@ -185,8 +185,8 @@ pub async fn search_by_apub_id( // TODO: also fetch parent comments if any let x = post_url.first().unwrap().as_xsd_any_uri().unwrap(); let post = fetch_remote_object(client, x).await?; - let post_form = PostForm::from_apub(&post, client, pool, &query_url).await?; - let comment_form = CommentForm::from_apub(&c, client, pool, &query_url).await?; + let post_form = PostForm::from_apub(&post, client, pool).await?; + let comment_form = CommentForm::from_apub(&c, client, pool).await?; blocking(pool, move |conn| upsert_post(&post_form, conn)).await??; let c = blocking(pool, move |conn| upsert_comment(&comment_form, conn)).await??; @@ -231,7 +231,7 @@ pub async fn get_or_fetch_and_upsert_user( debug!("Fetching and updating from remote user: {}", apub_id); let person = fetch_remote_object::(client, apub_id).await?; - let mut uf = UserForm::from_apub(&person, client, pool, apub_id).await?; + let mut uf = UserForm::from_apub(&person, client, pool).await?; uf.last_refreshed_at = Some(naive_now()); let user = blocking(pool, move |conn| User_::update(conn, u.id, &uf)).await??; @@ -242,7 +242,7 @@ pub async fn get_or_fetch_and_upsert_user( debug!("Fetching and creating remote user: {}", apub_id); let person = fetch_remote_object::(client, apub_id).await?; - let uf = UserForm::from_apub(&person, client, pool, apub_id).await?; + let uf = UserForm::from_apub(&person, client, pool).await?; let user = blocking(pool, move |conn| User_::create(conn, &uf)).await??; Ok(user) @@ -282,7 +282,7 @@ pub async fn get_or_fetch_and_upsert_community( debug!("Fetching and updating from remote community: {}", apub_id); let group = fetch_remote_object::(client, apub_id).await?; - let mut cf = CommunityForm::from_apub(&group, client, pool, apub_id).await?; + let mut cf = CommunityForm::from_apub(&group, client, pool).await?; cf.last_refreshed_at = Some(naive_now()); let community = blocking(pool, move |conn| Community::update(conn, c.id, &cf)).await??; @@ -293,7 +293,7 @@ pub async fn get_or_fetch_and_upsert_community( debug!("Fetching and creating remote community: {}", apub_id); let group = fetch_remote_object::(client, apub_id).await?; - let cf = CommunityForm::from_apub(&group, client, pool, apub_id).await?; + let cf = CommunityForm::from_apub(&group, client, pool).await?; let community = blocking(pool, move |conn| Community::create(conn, &cf)).await??; // Also add the community moderators too @@ -358,7 +358,7 @@ pub async fn get_or_fetch_and_insert_post( Err(NotFound {}) => { debug!("Fetching and creating remote post: {}", post_ap_id); let post = fetch_remote_object::(client, post_ap_id).await?; - let post_form = PostForm::from_apub(&post, client, pool, post_ap_id).await?; + let post_form = PostForm::from_apub(&post, client, pool).await?; let post = blocking(pool, move |conn| Post::create(conn, &post_form)).await??; @@ -396,7 +396,7 @@ pub async fn get_or_fetch_and_insert_comment( comment_ap_id ); let comment = fetch_remote_object::(client, comment_ap_id).await?; - let comment_form = CommentForm::from_apub(&comment, client, pool, comment_ap_id).await?; + let comment_form = CommentForm::from_apub(&comment, client, pool).await?; let comment = blocking(pool, move |conn| Comment::create(conn, &comment_form)).await??; diff --git a/server/src/apub/inbox/activities/create.rs b/server/src/apub/inbox/activities/create.rs index da90bea53..0f5595cd0 100644 --- a/server/src/apub/inbox/activities/create.rs +++ b/server/src/apub/inbox/activities/create.rs @@ -9,7 +9,6 @@ use crate::{ get_user_from_activity, receive_unhandled_activity, }, - ActorType, FromApub, PageExt, }, @@ -57,7 +56,7 @@ async fn receive_create_post( let user = get_user_from_activity(&create, client, pool).await?; let page = PageExt::from_any_base(create.object().to_owned().one().unwrap())?.unwrap(); - let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?; + let post = PostForm::from_apub(&page, client, pool).await?; let inserted_post = blocking(pool, move |conn| Post::create(conn, &post)).await??; @@ -89,7 +88,7 @@ async fn receive_create_comment( let user = get_user_from_activity(&create, client, pool).await?; let note = Note::from_any_base(create.object().to_owned().one().unwrap())?.unwrap(); - let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?; + let comment = CommentForm::from_apub(¬e, client, pool).await?; let inserted_comment = blocking(pool, move |conn| Comment::create(conn, &comment)).await??; diff --git a/server/src/apub/inbox/activities/delete.rs b/server/src/apub/inbox/activities/delete.rs index 09df0bc1e..b4fe0de48 100644 --- a/server/src/apub/inbox/activities/delete.rs +++ b/server/src/apub/inbox/activities/delete.rs @@ -7,7 +7,6 @@ use crate::{ get_user_from_activity, receive_unhandled_activity, }, - ActorType, FromApub, GroupExt, PageExt, @@ -58,7 +57,7 @@ async fn receive_delete_post( let user = get_user_from_activity(&delete, client, pool).await?; let page = PageExt::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap(); - let post_ap_id = PostForm::from_apub(&page, client, pool, &user.actor_id()?) + let post_ap_id = PostForm::from_apub(&page, client, pool) .await? .get_ap_id()?; @@ -112,7 +111,7 @@ async fn receive_delete_comment( let user = get_user_from_activity(&delete, client, pool).await?; let note = Note::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap(); - let comment_ap_id = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?) + let comment_ap_id = CommentForm::from_apub(¬e, client, pool) .await? .get_ap_id()?; @@ -169,7 +168,7 @@ async fn receive_delete_community( let group = GroupExt::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap(); let user = get_user_from_activity(&delete, client, pool).await?; - let community_actor_id = CommunityForm::from_apub(&group, client, pool, &user.actor_id()?) + let community_actor_id = CommunityForm::from_apub(&group, client, pool) .await? .actor_id; diff --git a/server/src/apub/inbox/activities/dislike.rs b/server/src/apub/inbox/activities/dislike.rs index 7135505e1..cb12724d6 100644 --- a/server/src/apub/inbox/activities/dislike.rs +++ b/server/src/apub/inbox/activities/dislike.rs @@ -7,7 +7,6 @@ use crate::{ get_user_from_activity, receive_unhandled_activity, }, - ActorType, FromApub, PageExt, }, @@ -53,7 +52,7 @@ async fn receive_dislike_post( let user = get_user_from_activity(&dislike, client, pool).await?; let page = PageExt::from_any_base(dislike.object().to_owned().one().unwrap())?.unwrap(); - let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?; + let post = PostForm::from_apub(&page, client, pool).await?; let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool) .await? @@ -94,7 +93,7 @@ async fn receive_dislike_comment( let note = Note::from_any_base(dislike.object().to_owned().one().unwrap())?.unwrap(); let user = get_user_from_activity(&dislike, client, pool).await?; - let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?; + let comment = CommentForm::from_apub(¬e, client, pool).await?; let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool) .await? diff --git a/server/src/apub/inbox/activities/like.rs b/server/src/apub/inbox/activities/like.rs index 36bdbfa8d..da92bbff3 100644 --- a/server/src/apub/inbox/activities/like.rs +++ b/server/src/apub/inbox/activities/like.rs @@ -7,7 +7,6 @@ use crate::{ get_user_from_activity, receive_unhandled_activity, }, - ActorType, FromApub, PageExt, }, @@ -53,7 +52,7 @@ async fn receive_like_post( let user = get_user_from_activity(&like, client, pool).await?; let page = PageExt::from_any_base(like.object().to_owned().one().unwrap())?.unwrap(); - let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?; + let post = PostForm::from_apub(&page, client, pool).await?; let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool) .await? @@ -94,7 +93,7 @@ async fn receive_like_comment( let note = Note::from_any_base(like.object().to_owned().one().unwrap())?.unwrap(); let user = get_user_from_activity(&like, client, pool).await?; - let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?; + let comment = CommentForm::from_apub(¬e, client, pool).await?; let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool) .await? diff --git a/server/src/apub/inbox/activities/remove.rs b/server/src/apub/inbox/activities/remove.rs index 1ae482d42..af3d144b8 100644 --- a/server/src/apub/inbox/activities/remove.rs +++ b/server/src/apub/inbox/activities/remove.rs @@ -7,7 +7,6 @@ use crate::{ get_user_from_activity, receive_unhandled_activity, }, - ActorType, FromApub, GroupExt, PageExt, @@ -58,7 +57,7 @@ async fn receive_remove_post( let mod_ = get_user_from_activity(&remove, client, pool).await?; let page = PageExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap(); - let post_ap_id = PostForm::from_apub(&page, client, pool, &mod_.actor_id()?) + let post_ap_id = PostForm::from_apub(&page, client, pool) .await? .get_ap_id()?; @@ -112,7 +111,7 @@ async fn receive_remove_comment( let mod_ = get_user_from_activity(&remove, client, pool).await?; let note = Note::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap(); - let comment_ap_id = CommentForm::from_apub(¬e, client, pool, &mod_.actor_id()?) + let comment_ap_id = CommentForm::from_apub(¬e, client, pool) .await? .get_ap_id()?; @@ -169,7 +168,7 @@ async fn receive_remove_community( let mod_ = get_user_from_activity(&remove, client, pool).await?; let group = GroupExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap(); - let community_actor_id = CommunityForm::from_apub(&group, client, pool, &mod_.actor_id()?) + let community_actor_id = CommunityForm::from_apub(&group, client, pool) .await? .actor_id; diff --git a/server/src/apub/inbox/activities/undo.rs b/server/src/apub/inbox/activities/undo.rs index 3634bd44d..332364843 100644 --- a/server/src/apub/inbox/activities/undo.rs +++ b/server/src/apub/inbox/activities/undo.rs @@ -7,7 +7,6 @@ use crate::{ get_user_from_activity, receive_unhandled_activity, }, - ActorType, FromApub, GroupExt, PageExt, @@ -123,7 +122,7 @@ async fn receive_undo_delete_comment( let user = get_user_from_activity(delete, client, pool).await?; let note = Note::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap(); - let comment_ap_id = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?) + let comment_ap_id = CommentForm::from_apub(¬e, client, pool) .await? .get_ap_id()?; @@ -181,7 +180,7 @@ async fn receive_undo_remove_comment( let mod_ = get_user_from_activity(remove, client, pool).await?; let note = Note::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap(); - let comment_ap_id = CommentForm::from_apub(¬e, client, pool, &mod_.actor_id()?) + let comment_ap_id = CommentForm::from_apub(¬e, client, pool) .await? .get_ap_id()?; @@ -239,7 +238,7 @@ async fn receive_undo_delete_post( let user = get_user_from_activity(delete, client, pool).await?; let page = PageExt::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap(); - let post_ap_id = PostForm::from_apub(&page, client, pool, &user.actor_id()?) + let post_ap_id = PostForm::from_apub(&page, client, pool) .await? .get_ap_id()?; @@ -294,7 +293,7 @@ async fn receive_undo_remove_post( let mod_ = get_user_from_activity(remove, client, pool).await?; let page = PageExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap(); - let post_ap_id = PostForm::from_apub(&page, client, pool, &mod_.actor_id()?) + let post_ap_id = PostForm::from_apub(&page, client, pool) .await? .get_ap_id()?; @@ -349,7 +348,7 @@ async fn receive_undo_delete_community( let user = get_user_from_activity(delete, client, pool).await?; let group = GroupExt::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap(); - let community_actor_id = CommunityForm::from_apub(&group, client, pool, &user.actor_id()?) + let community_actor_id = CommunityForm::from_apub(&group, client, pool) .await? .actor_id; @@ -413,7 +412,7 @@ async fn receive_undo_remove_community( let mod_ = get_user_from_activity(remove, client, pool).await?; let group = GroupExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap(); - let community_actor_id = CommunityForm::from_apub(&group, client, pool, &mod_.actor_id()?) + let community_actor_id = CommunityForm::from_apub(&group, client, pool) .await? .actor_id; @@ -477,7 +476,7 @@ async fn receive_undo_like_comment( let user = get_user_from_activity(like, client, pool).await?; let note = Note::from_any_base(like.object().to_owned().one().unwrap())?.unwrap(); - let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?; + let comment = CommentForm::from_apub(¬e, client, pool).await?; let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool) .await? @@ -523,7 +522,7 @@ async fn receive_undo_like_post( let user = get_user_from_activity(like, client, pool).await?; let page = PageExt::from_any_base(like.object().to_owned().one().unwrap())?.unwrap(); - let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?; + let post = PostForm::from_apub(&page, client, pool).await?; let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool) .await? diff --git a/server/src/apub/inbox/activities/update.rs b/server/src/apub/inbox/activities/update.rs index 2d5d06606..5da262e1f 100644 --- a/server/src/apub/inbox/activities/update.rs +++ b/server/src/apub/inbox/activities/update.rs @@ -10,7 +10,6 @@ use crate::{ get_user_from_activity, receive_unhandled_activity, }, - ActorType, FromApub, PageExt, }, @@ -57,7 +56,7 @@ async fn receive_update_post( let user = get_user_from_activity(&update, client, pool).await?; let page = PageExt::from_any_base(update.object().to_owned().one().unwrap())?.unwrap(); - let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?; + let post = PostForm::from_apub(&page, client, pool).await?; let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool) .await? @@ -89,7 +88,7 @@ async fn receive_update_comment( let note = Note::from_any_base(update.object().to_owned().one().unwrap())?.unwrap(); let user = get_user_from_activity(&update, client, pool).await?; - let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?; + let comment = CommentForm::from_apub(¬e, client, pool).await?; let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool) .await? diff --git a/server/src/apub/inbox/user_inbox.rs b/server/src/apub/inbox/user_inbox.rs index 13d974e9a..be99d81a0 100644 --- a/server/src/apub/inbox/user_inbox.rs +++ b/server/src/apub/inbox/user_inbox.rs @@ -121,7 +121,7 @@ async fn receive_create_private_message( insert_activity(user.id, create, false, pool).await?; - let private_message = PrivateMessageForm::from_apub(¬e, client, pool, user_uri).await?; + let private_message = PrivateMessageForm::from_apub(¬e, client, pool).await?; let inserted_private_message = blocking(pool, move |conn| { PrivateMessage::create(conn, &private_message) @@ -162,7 +162,7 @@ async fn receive_update_private_message( insert_activity(user.id, update, false, pool).await?; - let private_message_form = PrivateMessageForm::from_apub(¬e, client, pool, user_uri).await?; + let private_message_form = PrivateMessageForm::from_apub(¬e, client, pool).await?; let private_message_ap_id = private_message_form.ap_id.clone(); let private_message = blocking(pool, move |conn| { @@ -211,7 +211,7 @@ async fn receive_delete_private_message( insert_activity(user.id, delete, false, pool).await?; - let private_message_form = PrivateMessageForm::from_apub(¬e, client, pool, user_uri).await?; + let private_message_form = PrivateMessageForm::from_apub(¬e, client, pool).await?; let private_message_ap_id = private_message_form.ap_id; let private_message = blocking(pool, move |conn| { @@ -273,7 +273,7 @@ async fn receive_undo_delete_private_message( insert_activity(user.id, delete, false, pool).await?; - let private_message = PrivateMessageForm::from_apub(¬e, client, pool, user_uri).await?; + let private_message = PrivateMessageForm::from_apub(¬e, client, pool).await?; let private_message_ap_id = private_message.ap_id.clone(); let private_message_id = blocking(pool, move |conn| { diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index 47f01e315..28eb86ac2 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -132,7 +132,6 @@ pub trait FromApub { apub: &Self::ApubType, client: &Client, pool: &DbPool, - actor_id: &Url, ) -> Result where Self: Sized; diff --git a/server/src/apub/post.rs b/server/src/apub/post.rs index a4cf8e4cc..39e4faf34 100644 --- a/server/src/apub/post.rs +++ b/server/src/apub/post.rs @@ -154,7 +154,6 @@ impl FromApub for PostForm { page: &PageExt, client: &Client, pool: &DbPool, - actor_id: &Url, ) -> Result { let ext = &page.ext_one; let creator_actor_id = page @@ -246,11 +245,7 @@ impl FromApub for PostForm { embed_description, embed_html, thumbnail_url, - ap_id: page - .inner - .id(actor_id.domain().unwrap())? - .unwrap() - .to_string(), + ap_id: page.inner.id_unchecked().unwrap().to_string(), local: false, }) } diff --git a/server/src/apub/private_message.rs b/server/src/apub/private_message.rs index 5f8abca8e..f58a6bfed 100644 --- a/server/src/apub/private_message.rs +++ b/server/src/apub/private_message.rs @@ -75,7 +75,6 @@ impl FromApub for PrivateMessageForm { note: &Note, client: &Client, pool: &DbPool, - actor_id: &Url, ) -> Result { let creator_actor_id = note .attributed_to() @@ -103,7 +102,7 @@ impl FromApub for PrivateMessageForm { updated: note.updated().map(|u| u.to_owned().naive_local()), deleted: None, read: None, - ap_id: note.id(actor_id.domain().unwrap())?.unwrap().to_string(), + ap_id: note.id_unchecked().unwrap().to_string(), local: false, }) } diff --git a/server/src/apub/user.rs b/server/src/apub/user.rs index 9d8c9167f..0e90941d6 100644 --- a/server/src/apub/user.rs +++ b/server/src/apub/user.rs @@ -201,12 +201,7 @@ impl ActorType for User_ { impl FromApub for UserForm { type ApubType = PersonExt; /// Parse an ActivityPub person received from another instance into a Lemmy user. - async fn from_apub( - person: &PersonExt, - _: &Client, - _: &DbPool, - actor_id: &Url, - ) -> Result { + async fn from_apub(person: &PersonExt, _: &Client, _: &DbPool) -> Result { let avatar = match person.icon() { Some(any_image) => Image::from_any_base(any_image.as_one().unwrap().clone()) .unwrap() @@ -242,7 +237,7 @@ impl FromApub for UserForm { show_avatars: false, send_notifications_to_email: false, matrix_user_id: None, - actor_id: person.id(actor_id.domain().unwrap())?.unwrap().to_string(), + actor_id: person.id_unchecked().unwrap().to_string(), bio: person .inner .summary()