diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/apub/comment.rs | 2 | ||||
-rw-r--r-- | server/src/apub/community.rs | 136 | ||||
-rw-r--r-- | server/src/apub/fetcher.rs | 91 | ||||
-rw-r--r-- | server/src/apub/mod.rs | 18 | ||||
-rw-r--r-- | server/src/apub/post.rs | 2 | ||||
-rw-r--r-- | server/src/apub/private_message.rs | 2 | ||||
-rw-r--r-- | server/src/apub/shared_inbox.rs | 88 | ||||
-rw-r--r-- | server/src/apub/user.rs | 118 | ||||
-rw-r--r-- | server/src/apub/user_inbox.rs | 16 |
9 files changed, 236 insertions, 237 deletions
diff --git a/server/src/apub/comment.rs b/server/src/apub/comment.rs index a42a52c2..dbc15909 100644 --- a/server/src/apub/comment.rs +++ b/server/src/apub/comment.rs @@ -123,7 +123,7 @@ impl FromApub for CommentForm { /// Parse an ActivityPub note received from another instance into a Lemmy comment async fn from_apub( - note: &Note, + note: &mut Note, client: &Client, pool: &DbPool, ) -> Result<CommentForm, LemmyError> { diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs index f866511c..bfc896af 100644 --- a/server/src/apub/community.rs +++ b/server/src/apub/community.rs @@ -4,7 +4,7 @@ use crate::{ create_apub_response, create_apub_tombstone_response, create_tombstone, - extensions::{group_extensions::GroupExtension, signatures::PublicKey}, + extensions::group_extensions::GroupExtension, fetcher::get_or_fetch_and_upsert_remote_user, get_shared_inbox, ActorType, @@ -27,21 +27,25 @@ use crate::{ }; use activitystreams::{ activity::{Accept, Announce, Delete, Remove, Undo}, - actor::{kind::GroupType, properties::ApActorProperties, Group}, - collection::UnorderedCollection, - context, - endpoint::EndpointProperties, - object::properties::ObjectProperties, Activity, Base, BaseBox, }; -use activitystreams_ext::Ext3; -use activitystreams_new::{activity::Follow, object::Tombstone}; +use activitystreams_ext::Ext2; +use activitystreams_new::{ + activity::Follow, + actor::{kind::GroupType, ApActor, Endpoints, Group}, + base::BaseExt, + collection::UnorderedCollection, + context, + object::Tombstone, + prelude::*, + primitives::{XsdAnyUri, XsdDateTime}, +}; use actix_web::{body::Body, client::Client, web, HttpResponse}; use itertools::Itertools; use serde::{Deserialize, Serialize}; -use std::fmt::Debug; +use std::{fmt::Debug, str::FromStr}; #[derive(Deserialize)] pub struct CommunityQuery { @@ -54,9 +58,6 @@ impl ToApub for Community { // Turn a Lemmy Community into an ActivityPub group that can be sent out over the network. async fn to_apub(&self, pool: &DbPool) -> Result<GroupExt, LemmyError> { - let mut group = Group::default(); - let oprops: &mut ObjectProperties = group.as_mut(); - // The attributed to, is an ordered vector with the creator actor_ids first, // then the rest of the moderators // TODO Technically the instance admins can mod the community, but lets @@ -66,36 +67,36 @@ impl ToApub for Community { CommunityModeratorView::for_community(&conn, id) }) .await??; - let moderators = moderators.into_iter().map(|m| m.user_actor_id).collect(); + let moderators: Vec<String> = moderators.into_iter().map(|m| m.user_actor_id).collect(); - oprops - .set_context_xsd_any_uri(context())? - .set_id(self.actor_id.to_owned())? - .set_name_xsd_string(self.name.to_owned())? - .set_published(convert_datetime(self.published))? - .set_many_attributed_to_xsd_any_uris(moderators)?; + let mut group = Group::new(); + group + .set_context(context()) + .set_id(XsdAnyUri::from_str(&self.actor_id)?) + .set_name(self.name.to_owned()) + .set_published(XsdDateTime::from(convert_datetime(self.published))) + .set_many_attributed_tos(moderators); if let Some(u) = self.updated.to_owned() { - oprops.set_updated(convert_datetime(u))?; + group.set_updated(XsdDateTime::from(convert_datetime(u))); } if let Some(d) = self.description.to_owned() { // TODO: this should be html, also add source field with raw markdown // -> same for post.content and others - oprops.set_content_xsd_string(d)?; + group.set_content(d); } - let mut endpoint_props = EndpointProperties::default(); - - endpoint_props.set_shared_inbox(self.get_shared_inbox_url())?; - - let mut actor_props = ApActorProperties::default(); - - actor_props - .set_preferred_username(self.title.to_owned())? - .set_inbox(self.get_inbox_url())? - .set_outbox(self.get_outbox_url())? - .set_endpoints(endpoint_props)? - .set_followers(self.get_followers_url())?; + let mut ap_actor = ApActor::new(self.get_inbox_url().parse()?, group); + ap_actor + .set_preferred_username(self.title.to_owned()) + .set_outbox(self.get_outbox_url().parse()?) + .set_followers(self.get_followers_url().parse()?) + .set_following(self.get_following_url().parse()?) + .set_liked(self.get_liked_url().parse()?) + .set_endpoints(Endpoints { + shared_inbox: Some(self.get_shared_inbox_url().parse()?), + ..Default::default() + }); let nsfw = self.nsfw; let category_id = self.category_id; @@ -104,10 +105,9 @@ impl ToApub for Community { }) .await??; - Ok(Ext3::new( - group, + Ok(Ext2::new( + ap_actor, group_extension, - actor_props, self.get_public_key_ext(), )) } @@ -367,38 +367,52 @@ 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) -> Result<Self, LemmyError> { - let group_extensions: &GroupExtension = &group.ext_one; - let oprops = &group.inner.object_props; - let aprops = &group.ext_two; - let public_key: &PublicKey = &group.ext_three.public_key; - - let mut creator_and_moderator_uris = oprops.get_many_attributed_to_xsd_any_uris().unwrap(); - let creator_uri = creator_and_moderator_uris.next().unwrap(); + async fn from_apub( + group: &mut GroupExt, + client: &Client, + pool: &DbPool, + ) -> Result<Self, LemmyError> { + // TODO: this is probably gonna cause problems cause fetcher:292 also calls take_attributed_to() + let creator_and_moderator_uris = group.clone().take_attributed_to().unwrap(); + let creator_uri = creator_and_moderator_uris + .as_many() + .unwrap() + .iter() + .next() + .unwrap() + .as_xsd_any_uri() + .unwrap(); let creator = get_or_fetch_and_upsert_remote_user(creator_uri.as_str(), client, pool).await?; Ok(CommunityForm { - name: oprops.get_name_xsd_string().unwrap().to_string(), - title: aprops.get_preferred_username().unwrap().to_string(), + name: group + .take_name() + .unwrap() + .as_single_xsd_string() + .unwrap() + .into(), + title: group.inner.take_preferred_username().unwrap(), // TODO: should be parsed as html and tags like <script> removed (or use markdown source) // -> same for post.content etc - description: oprops.get_content_xsd_string().map(|s| s.to_string()), - category_id: group_extensions.category.identifier.parse::<i32>()?, + description: group + .take_content() + .map(|s| s.as_single_xsd_string().unwrap().into()), + category_id: group.ext_one.category.identifier.parse::<i32>()?, creator_id: creator.id, removed: None, - published: oprops - .get_published() + published: group + .take_published() .map(|u| u.as_ref().to_owned().naive_local()), - updated: oprops - .get_updated() + updated: group + .take_updated() .map(|u| u.as_ref().to_owned().naive_local()), deleted: None, - nsfw: group_extensions.sensitive, - actor_id: oprops.get_id().unwrap().to_string(), + nsfw: group.ext_one.sensitive, + actor_id: group.id().unwrap().to_string(), local: false, private_key: None, - public_key: Some(public_key.to_owned().public_key_pem), + public_key: Some(group.ext_two.to_owned().public_key.public_key_pem), last_refreshed_at: Some(naive_now()), }) } @@ -439,14 +453,12 @@ pub async fn get_apub_community_followers( }) .await??; - let mut collection = UnorderedCollection::default(); - let oprops: &mut ObjectProperties = collection.as_mut(); - oprops - .set_context_xsd_any_uri(context())? - .set_id(community.actor_id)?; + let mut collection = UnorderedCollection::new(vec![]); collection - .collection_props - .set_total_items(community_followers.len() as u64)?; + .set_context(context()) + // TODO: this needs its own ID + .set_id(community.actor_id.parse()?) + .set_total_items(community_followers.len() as u64); Ok(create_apub_response(&collection)) } diff --git a/server/src/apub/fetcher.rs b/server/src/apub/fetcher.rs index 598903d0..d8a1e764 100644 --- a/server/src/apub/fetcher.rs +++ b/server/src/apub/fetcher.rs @@ -1,13 +1,14 @@ -use activitystreams::object::Note; -use actix_web::client::Client; -use diesel::{result::Error::NotFound, PgConnection}; -use log::debug; -use serde::Deserialize; -use std::{fmt::Debug, time::Duration}; -use url::Url; - use crate::{ api::site::SearchResponse, + apub::{ + get_apub_protocol_string, + is_apub_id_valid, + FromApub, + GroupExt, + PageExt, + PersonExt, + APUB_JSON_CONTENT_TYPE, + }, blocking, db::{ comment::{Comment, CommentForm}, @@ -17,6 +18,7 @@ use crate::{ post::{Post, PostForm}, post_view::PostView, user::{UserForm, User_}, + user_view::UserView, Crud, Joinable, SearchType, @@ -27,20 +29,15 @@ use crate::{ DbPool, LemmyError, }; - -use crate::{ - apub::{ - get_apub_protocol_string, - is_apub_id_valid, - FromApub, - GroupExt, - PageExt, - PersonExt, - APUB_JSON_CONTENT_TYPE, - }, - db::user_view::UserView, -}; +use activitystreams::object::Note; +use activitystreams_new::{base::BaseExt, prelude::*, primitives::XsdAnyUri}; +use actix_web::client::Client; use chrono::NaiveDateTime; +use diesel::{result::Error::NotFound, PgConnection}; +use log::debug; +use serde::Deserialize; +use std::{fmt::Debug, time::Duration}; +use url::Url; static ACTOR_REFETCH_INTERVAL_SECONDS: i64 = 24 * 60 * 60; @@ -149,7 +146,7 @@ pub async fn search_by_apub_id( let response = match fetch_remote_object::<SearchAcceptedObjects>(client, &query_url).await? { SearchAcceptedObjects::Person(p) => { - let user_uri = p.inner.object_props.get_id().unwrap().to_string(); + let user_uri = p.inner.id().unwrap().to_string(); let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?; @@ -158,7 +155,7 @@ pub async fn search_by_apub_id( response } SearchAcceptedObjects::Group(g) => { - let community_uri = g.inner.object_props.get_id().unwrap().to_string(); + let community_uri = g.inner.id().unwrap().to_string(); let community = get_or_fetch_and_upsert_remote_community(&community_uri, client, pool).await?; @@ -174,15 +171,15 @@ pub async fn search_by_apub_id( response } - SearchAcceptedObjects::Page(p) => { - let post_form = PostForm::from_apub(&p, client, pool).await?; + SearchAcceptedObjects::Page(mut p) => { + let post_form = PostForm::from_apub(&mut 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??]; response } - SearchAcceptedObjects::Comment(c) => { + SearchAcceptedObjects::Comment(mut c) => { let post_url = c .object_props .get_many_in_reply_to_xsd_any_uris() @@ -192,9 +189,9 @@ pub async fn search_by_apub_id( .to_string(); // TODO: also fetch parent comments if any - let post = fetch_remote_object(client, &Url::parse(&post_url)?).await?; - let post_form = PostForm::from_apub(&post, client, pool).await?; - let comment_form = CommentForm::from_apub(&c, client, pool).await?; + let mut post = fetch_remote_object(client, &Url::parse(&post_url)?).await?; + let post_form = PostForm::from_apub(&mut post, client, pool).await?; + let comment_form = CommentForm::from_apub(&mut 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??; @@ -224,9 +221,9 @@ pub async fn get_or_fetch_and_upsert_remote_user( // 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 user: {}", apub_id); - let person = fetch_remote_object::<PersonExt>(client, &Url::parse(apub_id)?).await?; + let mut person = fetch_remote_object::<PersonExt>(client, &Url::parse(apub_id)?).await?; - let mut uf = UserForm::from_apub(&person, client, pool).await?; + let mut uf = UserForm::from_apub(&mut person, client, pool).await?; uf.last_refreshed_at = Some(naive_now()); let user = blocking(pool, move |conn| User_::update(conn, u.id, &uf)).await??; @@ -235,9 +232,9 @@ pub async fn get_or_fetch_and_upsert_remote_user( Ok(u) => Ok(u), Err(NotFound {}) => { debug!("Fetching and creating remote user: {}", apub_id); - let person = fetch_remote_object::<PersonExt>(client, &Url::parse(apub_id)?).await?; + let mut person = fetch_remote_object::<PersonExt>(client, &Url::parse(apub_id)?).await?; - let uf = UserForm::from_apub(&person, client, pool).await?; + let uf = UserForm::from_apub(&mut person, client, pool).await?; let user = blocking(pool, move |conn| User_::create(conn, &uf)).await??; Ok(user) @@ -275,9 +272,9 @@ pub async fn get_or_fetch_and_upsert_remote_community( match community { Ok(c) if !c.local && should_refetch_actor(c.last_refreshed_at) => { debug!("Fetching and updating from remote community: {}", apub_id); - let group = fetch_remote_object::<GroupExt>(client, &Url::parse(apub_id)?).await?; + let mut group = fetch_remote_object::<GroupExt>(client, &Url::parse(apub_id)?).await?; - let mut cf = CommunityForm::from_apub(&group, client, pool).await?; + let mut cf = CommunityForm::from_apub(&mut group, client, pool).await?; cf.last_refreshed_at = Some(naive_now()); let community = blocking(pool, move |conn| Community::update(conn, c.id, &cf)).await??; @@ -286,17 +283,19 @@ pub async fn get_or_fetch_and_upsert_remote_community( Ok(c) => Ok(c), Err(NotFound {}) => { debug!("Fetching and creating remote community: {}", apub_id); - let group = fetch_remote_object::<GroupExt>(client, &Url::parse(apub_id)?).await?; + let mut group = fetch_remote_object::<GroupExt>(client, &Url::parse(apub_id)?).await?; - let cf = CommunityForm::from_apub(&group, client, pool).await?; + let cf = CommunityForm::from_apub(&mut group, client, pool).await?; let community = blocking(pool, move |conn| Community::create(conn, &cf)).await??; // Also add the community moderators too - let creator_and_moderator_uris = group - .inner - .object_props - .get_many_attributed_to_xsd_any_uris() - .unwrap(); + let attributed_to = group.inner.take_attributed_to().unwrap(); + let creator_and_moderator_uris: Vec<&XsdAnyUri> = attributed_to + .as_many() + .unwrap() + .iter() + .map(|a| a.as_xsd_any_uri().unwrap()) + .collect(); let mut creator_and_moderators = Vec::new(); @@ -350,8 +349,8 @@ pub async fn get_or_fetch_and_insert_remote_post( Ok(p) => Ok(p), Err(NotFound {}) => { debug!("Fetching and creating remote post: {}", post_ap_id); - let post = fetch_remote_object::<PageExt>(client, &Url::parse(post_ap_id)?).await?; - let post_form = PostForm::from_apub(&post, client, pool).await?; + let mut post = fetch_remote_object::<PageExt>(client, &Url::parse(post_ap_id)?).await?; + let post_form = PostForm::from_apub(&mut post, client, pool).await?; let post = blocking(pool, move |conn| Post::create(conn, &post_form)).await??; @@ -388,8 +387,8 @@ pub async fn get_or_fetch_and_insert_remote_comment( "Fetching and creating remote comment and its parents: {}", comment_ap_id ); - let comment = fetch_remote_object::<Note>(client, &Url::parse(comment_ap_id)?).await?; - let comment_form = CommentForm::from_apub(&comment, client, pool).await?; + let mut comment = fetch_remote_object::<Note>(client, &Url::parse(comment_ap_id)?).await?; + let comment_form = CommentForm::from_apub(&mut comment, client, pool).await?; let comment = blocking(pool, move |conn| Comment::create(conn, &comment_form)).await??; diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index 90df8734..561dc49a 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -25,20 +25,22 @@ use crate::{ MentionData, Settings, }; -use activitystreams::{ - actor::{properties::ApActorProperties, Group, Person}, - object::Page, +use activitystreams::object::Page; +use activitystreams_ext::{Ext1, Ext2}; +use activitystreams_new::{ + activity::Follow, + actor::{ApActor, Group, Person}, + object::Tombstone, + prelude::*, }; -use activitystreams_ext::{Ext1, Ext2, Ext3}; -use activitystreams_new::{activity::Follow, object::Tombstone, prelude::*}; use actix_web::{body::Body, client::Client, HttpResponse}; use chrono::NaiveDateTime; use log::debug; use serde::Serialize; use url::Url; -type GroupExt = Ext3<Group, GroupExtension, ApActorProperties, PublicKeyExtension>; -type PersonExt = Ext2<Person, ApActorProperties, PublicKeyExtension>; +type GroupExt = Ext2<ApActor<Group>, GroupExtension, PublicKeyExtension>; +type PersonExt = Ext1<ApActor<Person>, PublicKeyExtension>; type PageExt = Ext1<Page, PageExtension>; pub static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json"; @@ -163,7 +165,7 @@ fn create_tombstone( pub trait FromApub { type ApubType; async fn from_apub( - apub: &Self::ApubType, + apub: &mut Self::ApubType, client: &Client, pool: &DbPool, ) -> Result<Self, LemmyError> diff --git a/server/src/apub/post.rs b/server/src/apub/post.rs index 60cb0b55..255629e8 100644 --- a/server/src/apub/post.rs +++ b/server/src/apub/post.rs @@ -164,7 +164,7 @@ impl FromApub for PostForm { /// Parse an ActivityPub page received from another instance into a Lemmy post. async fn from_apub( - page: &PageExt, + page: &mut PageExt, client: &Client, pool: &DbPool, ) -> Result<PostForm, LemmyError> { diff --git a/server/src/apub/private_message.rs b/server/src/apub/private_message.rs index ae4c3626..48bbd1f0 100644 --- a/server/src/apub/private_message.rs +++ b/server/src/apub/private_message.rs @@ -71,7 +71,7 @@ impl FromApub for PrivateMessageForm { /// Parse an ActivityPub note received from another instance into a Lemmy Private message async fn from_apub( - note: &Note, + note: &mut Note, client: &Client, pool: &DbPool, ) -> Result<PrivateMessageForm, LemmyError> { diff --git a/server/src/apub/shared_inbox.rs b/server/src/apub/shared_inbox.rs index 66773252..fa9794b2 100644 --- a/server/src/apub/shared_inbox.rs +++ b/server/src/apub/shared_inbox.rs @@ -335,7 +335,7 @@ async fn receive_create_post( pool: &DbPool, chat_server: ChatServerParam, ) -> Result<HttpResponse, LemmyError> { - let page = create + let mut page = create .create_props .get_object_base_box() .to_owned() @@ -353,7 +353,7 @@ async fn receive_create_post( insert_activity(user.id, create, false, pool).await?; - let post = PostForm::from_apub(&page, client, pool).await?; + let post = PostForm::from_apub(&mut page, client, pool).await?; let inserted_post = blocking(pool, move |conn| Post::create(conn, &post)).await??; @@ -381,7 +381,7 @@ async fn receive_create_comment( pool: &DbPool, chat_server: ChatServerParam, ) -> Result<HttpResponse, LemmyError> { - let note = create + let mut note = create .create_props .get_object_base_box() .to_owned() @@ -399,7 +399,7 @@ async fn receive_create_comment( insert_activity(user.id, create, false, pool).await?; - let comment = CommentForm::from_apub(¬e, client, pool).await?; + let comment = CommentForm::from_apub(&mut note, client, pool).await?; let inserted_comment = blocking(pool, move |conn| Comment::create(conn, &comment)).await??; @@ -440,7 +440,7 @@ async fn receive_update_post( pool: &DbPool, chat_server: ChatServerParam, ) -> Result<HttpResponse, LemmyError> { - let page = update + let mut page = update .update_props .get_object_base_box() .to_owned() @@ -458,7 +458,7 @@ async fn receive_update_post( insert_activity(user.id, update, false, pool).await?; - let post = PostForm::from_apub(&page, client, pool).await?; + let post = PostForm::from_apub(&mut page, client, pool).await?; let post_id = get_or_fetch_and_insert_remote_post(&post.ap_id, client, pool) .await? @@ -486,7 +486,7 @@ async fn receive_like_post( pool: &DbPool, chat_server: ChatServerParam, ) -> Result<HttpResponse, LemmyError> { - let page = like + let mut page = like .like_props .get_object_base_box() .to_owned() @@ -500,7 +500,7 @@ async fn receive_like_post( insert_activity(user.id, like, false, pool).await?; - let post = PostForm::from_apub(&page, client, pool).await?; + let post = PostForm::from_apub(&mut page, client, pool).await?; let post_id = get_or_fetch_and_insert_remote_post(&post.ap_id, client, pool) .await? @@ -537,7 +537,7 @@ async fn receive_dislike_post( pool: &DbPool, chat_server: ChatServerParam, ) -> Result<HttpResponse, LemmyError> { - let page = dislike + let mut page = dislike .dislike_props .get_object_base_box() .to_owned() @@ -555,7 +555,7 @@ async fn receive_dislike_post( insert_activity(user.id, dislike, false, pool).await?; - let post = PostForm::from_apub(&page, client, pool).await?; + let post = PostForm::from_apub(&mut page, client, pool).await?; let post_id = get_or_fetch_and_insert_remote_post(&post.ap_id, client, pool) .await? @@ -592,7 +592,7 @@ async fn receive_update_comment( pool: &DbPool, chat_server: ChatServerParam, ) -> Result<HttpResponse, LemmyError> { - let note = update + let mut note = update .update_props .get_object_base_box() .to_owned() @@ -610,7 +610,7 @@ async fn receive_update_comment( insert_activity(user.id, update, false, pool).await?; - let comment = CommentForm::from_apub(¬e, client, pool).await?; + let comment = CommentForm::from_apub(&mut note, client, pool).await?; let comment_id = get_or_fetch_and_insert_remote_comment(&comment.ap_id, client, pool) .await? @@ -651,7 +651,7 @@ async fn receive_like_comment( pool: &DbPool, chat_server: ChatServerParam, ) -> Result<HttpResponse, LemmyError> { - let note = like + let mut note = like .like_props .get_object_base_box() .to_owned() @@ -665,7 +665,7 @@ async fn receive_like_comment( insert_activity(user.id, like, false, pool).await?; - let comment = CommentForm::from_apub(¬e, client, pool).await?; + let comment = CommentForm::from_apub(&mut note, client, pool).await?; let comment_id = get_or_fetch_and_insert_remote_comment(&comment.ap_id, client, pool) .await? @@ -709,7 +709,7 @@ async fn receive_dislike_comment( pool: &DbPool, chat_server: ChatServerParam, ) -> Result<HttpResponse, LemmyError> { - let note = dislike + let mut note = dislike .dislike_props .get_object_base_box() .to_owned() @@ -727,7 +727,7 @@ async fn receive_dislike_comment( insert_activity(user.id, dislike, false, pool).await?; - let comment = CommentForm::from_apub(¬e, client, pool).await?; + let comment = CommentForm::from_apub(&mut note, client, pool).await?; let comment_id = get_or_fetch_and_insert_remote_comment(&comment.ap_id, client, pool) .await? @@ -777,7 +777,7 @@ async fn receive_delete_community( .unwrap() .to_string(); - let group = delete + let mut group = delete .delete_props .get_object_base_box() .to_owned() @@ -789,7 +789,7 @@ async fn receive_delete_community( insert_activity(user.id, delete, false, pool).await?; - let community_actor_id = CommunityForm::from_apub(&group, client, pool) + let community_actor_id = CommunityForm::from_apub(&mut group, client, pool) .await? .actor_id; @@ -854,7 +854,7 @@ async fn receive_remove_community( .unwrap() .to_string(); - let group = remove + let mut group = remove .remove_props .get_object_base_box() .to_owned() @@ -866,7 +866,7 @@ async fn receive_remove_community( insert_activity(mod_.id, remove, false, pool).await?; - let community_actor_id = CommunityForm::from_apub(&group, client, pool) + let community_actor_id = CommunityForm::from_apub(&mut group, client, pool) .await? .actor_id; @@ -931,7 +931,7 @@ async fn receive_delete_post( .unwrap() .to_string(); - let page = delete + let mut page = delete .delete_props .get_object_base_box() .to_owned() @@ -943,7 +943,7 @@ async fn receive_delete_post( insert_activity(user.id, delete, false, pool).await?; - let post_ap_id = PostForm::from_apub(&page, client, pool).await?.ap_id; + let post_ap_id = PostForm::from_apub(&mut page, client, pool).await?.ap_id; let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?; @@ -997,7 +997,7 @@ async fn receive_remove_post( .unwrap() .to_string(); - let page = remove + let mut page = remove .remove_props .get_object_base_box() .to_owned() @@ -1009,7 +1009,7 @@ async fn receive_remove_post( insert_activity(mod_.id, remove, false, pool).await?; - let post_ap_id = PostForm::from_apub(&page, client, pool).await?.ap_id; + let post_ap_id = PostForm::from_apub(&mut page, client, pool).await?.ap_id; let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?; @@ -1063,7 +1063,7 @@ async fn receive_delete_comment( .unwrap() .to_string(); - let note = delete + let mut note = delete .delete_props .get_object_base_box() .to_owned() @@ -1075,7 +1075,7 @@ async fn receive_delete_comment( insert_activity(user.id, delete, false, pool).await?; - let comment_ap_id = CommentForm::from_apub(¬e, client, pool).await?.ap_id; + let comment_ap_id = CommentForm::from_apub(&mut note, client, pool).await?.ap_id; let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?; @@ -1131,7 +1131,7 @@ async fn receive_remove_comment( .unwrap() .to_string(); - let note = remove + let mut note = remove .remove_props .get_object_base_box() .to_owned() @@ -1143,7 +1143,7 @@ async fn receive_remove_comment( insert_activity(mod_.id, remove, false, pool).await?; - let comment_ap_id = CommentForm::from_apub(¬e, client, pool).await?.ap_id; + let comment_ap_id = CommentForm::from_apub(&mut note, client, pool).await?.ap_id; let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?; @@ -1259,7 +1259,7 @@ async fn receive_undo_delete_comment( .unwrap() .to_string(); - let note = delete + let mut note = delete .delete_props .get_object_base_box() .to_owned() @@ -1271,7 +1271,7 @@ async fn receive_undo_delete_comment( insert_activity(user.id, delete, false, pool).await?; - let comment_ap_id = CommentForm::from_apub(¬e, client, pool).await?.ap_id; + let comment_ap_id = CommentForm::from_apub(&mut note, client, pool).await?.ap_id; let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?; @@ -1327,7 +1327,7 @@ async fn receive_undo_remove_comment( .unwrap() .to_string(); - let note = remove + let mut note = remove .remove_props .get_object_base_box() .to_owned() @@ -1339,7 +1339,7 @@ async fn receive_undo_remove_comment( insert_activity(mod_.id, remove, false, pool).await?; - let comment_ap_id = CommentForm::from_apub(¬e, client, pool).await?.ap_id; + let comment_ap_id = CommentForm::from_apub(&mut note, client, pool).await?.ap_id; let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?; @@ -1395,7 +1395,7 @@ async fn receive_undo_delete_post( .unwrap() .to_string(); - let page = delete + let mut page = delete .delete_props .get_object_base_box() .to_owned() @@ -1407,7 +1407,7 @@ async fn receive_undo_delete_post( insert_activity(user.id, delete, false, pool).await?; - let post_ap_id = PostForm::from_apub(&page, client, pool).await?.ap_id; + let post_ap_id = PostForm::from_apub(&mut page, client, pool).await?.ap_id; let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?; @@ -1461,7 +1461,7 @@ async fn receive_undo_remove_post( .unwrap() .to_string(); - let page = remove + let mut page = remove .remove_props .get_object_base_box() .to_owned() @@ -1473,7 +1473,7 @@ async fn receive_undo_remove_post( insert_activity(mod_.id, remove, false, pool).await?; - let post_ap_id = PostForm::from_apub(&page, client, pool).await?.ap_id; + let post_ap_id = PostForm::from_apub(&mut page, client, pool).await?.ap_id; let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?; @@ -1527,7 +1527,7 @@ async fn receive_undo_delete_community( .unwrap() .to_string(); - let group = delete + let mut group = delete .delete_props .get_object_base_box() .to_owned() @@ -1539,7 +1539,7 @@ async fn receive_undo_delete_community( insert_activity(user.id, delete, false, pool).await?; - let community_actor_id = CommunityForm::from_apub(&group, client, pool) + let community_actor_id = CommunityForm::from_apub(&mut group, client, pool) .await? .actor_id; @@ -1604,7 +1604,7 @@ async fn receive_undo_remove_community( .unwrap() .to_string(); - let group = remove + let mut group = remove .remove_props .get_object_base_box() .to_owned() @@ -1616,7 +1616,7 @@ async fn receive_undo_remove_community( insert_activity(mod_.id, remove, false, pool).await?; - let community_actor_id = CommunityForm::from_apub(&group, client, pool) + let community_actor_id = CommunityForm::from_apub(&mut group, client, pool) .await? .actor_id; @@ -1704,7 +1704,7 @@ async fn receive_undo_like_comment( pool: &DbPool, chat_server: ChatServerParam, ) -> Result<HttpResponse, LemmyError> { - let note = like + let mut note = like .like_props .get_object_base_box() .to_owned() @@ -1718,7 +1718,7 @@ async fn receive_undo_like_comment( insert_activity(user.id, like, false, pool).await?; - let comment = CommentForm::from_apub(¬e, client, pool).await?; + let comment = CommentForm::from_apub(&mut note, client, pool).await?; let comment_id = get_or_fetch_and_insert_remote_comment(&comment.ap_id, client, pool) .await? @@ -1758,7 +1758,7 @@ async fn receive_undo_like_post( pool: &DbPool, chat_server: ChatServerParam, ) -> Result<HttpResponse, LemmyError> { - let page = like + let mut page = like .like_props .get_object_base_box() .to_owned() @@ -1772,7 +1772,7 @@ async fn receive_undo_like_post( insert_activity(user.id, like, false, pool).await?; - let post = PostForm::from_apub(&page, client, pool).await?; + let post = PostForm::from_apub(&mut page, client, pool).await?; let post_id = get_or_fetch_and_insert_remote_post(&post.ap_id, client, pool) .await? diff --git a/server/src/apub/user.rs b/server/src/apub/user.rs index 51339ccf..a3194355 100644 --- a/server/src/apub/user.rs +++ b/server/src/apub/user.rs @@ -1,13 +1,5 @@ use crate::{ - apub::{ - activities::send_activity, - create_apub_response, - extensions::signatures::PublicKey, - ActorType, - FromApub, - PersonExt, - ToApub, - }, + apub::{activities::send_activity, create_apub_response, ActorType, FromApub, PersonExt, ToApub}, blocking, convert_datetime, db::{ @@ -19,20 +11,17 @@ use crate::{ DbPool, LemmyError, }; -use activitystreams::{ - actor::{properties::ApActorProperties, Person}, - context, - endpoint::EndpointProperties, - object::{properties::ObjectProperties, AnyImage, Image}, - primitives::XsdAnyUri, -}; -use activitystreams_ext::Ext2; +use activitystreams_ext::Ext1; use activitystreams_new::{ activity::{Follow, Undo}, - object::Tombstone, + actor::{ApActor, Endpoints, Person}, + context, + object::{Image, Tombstone}, prelude::*, + primitives::{XsdAnyUri, XsdDateTime}, }; use actix_web::{body::Body, client::Client, web, HttpResponse}; +use failure::_core::str::FromStr; use serde::Deserialize; #[derive(Deserialize)] @@ -47,46 +36,39 @@ impl ToApub for User_ { // Turn a Lemmy Community into an ActivityPub group that can be sent out over the network. async fn to_apub(&self, _pool: &DbPool) -> Result<PersonExt, LemmyError> { // TODO go through all these to_string and to_owned() - let mut person = Person::default(); - let oprops: &mut ObjectProperties = person.as_mut(); - oprops - .set_context_xsd_any_uri(context())? - .set_id(self.actor_id.to_string())? - .set_name_xsd_string(self.name.to_owned())? - .set_published(convert_datetime(self.published))?; + let mut person = Person::new(); + person + .set_context(context()) + .set_id(XsdAnyUri::from_str(&self.actor_id)?) |