Make reads from activitypub objects immutable
This commit is contained in:
parent
f0357bc988
commit
bb3e29e5c4
10 changed files with 118 additions and 186 deletions
|
@ -181,7 +181,7 @@ mod tests {
|
|||
pub fn establish_unpooled_connection() -> PgConnection {
|
||||
let db_url = match get_database_url_from_env() {
|
||||
Ok(url) => url,
|
||||
Err(_) => panic!("Failed to read database URL from env var LEMMY_DATABASE_URL"),
|
||||
Err(e) => panic!("Failed to read database URL from env var LEMMY_DATABASE_URL: {}", e),
|
||||
};
|
||||
PgConnection::establish(&db_url).unwrap_or_else(|_| panic!("Error connecting to {}", db_url))
|
||||
}
|
||||
|
|
|
@ -1,25 +1,16 @@
|
|||
use crate::{
|
||||
apub::{
|
||||
activities::{populate_object_props, send_activity_to_community},
|
||||
create_apub_response,
|
||||
create_apub_tombstone_response,
|
||||
create_tombstone,
|
||||
fetch_webfinger_url,
|
||||
create_apub_response, create_apub_tombstone_response, create_tombstone, fetch_webfinger_url,
|
||||
fetcher::{
|
||||
get_or_fetch_and_insert_remote_comment,
|
||||
get_or_fetch_and_insert_remote_post,
|
||||
get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post,
|
||||
get_or_fetch_and_upsert_remote_user,
|
||||
},
|
||||
ActorType,
|
||||
ApubLikeableType,
|
||||
ApubObjectType,
|
||||
FromApub,
|
||||
ToApub,
|
||||
ActorType, ApubLikeableType, ApubObjectType, FromApub, ToApub,
|
||||
},
|
||||
blocking,
|
||||
routes::DbPoolParam,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
DbPool, LemmyError,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
|
||||
|
@ -121,7 +112,7 @@ impl FromApub for CommentForm {
|
|||
|
||||
/// Parse an ActivityPub note received from another instance into a Lemmy comment
|
||||
async fn from_apub(
|
||||
note: &mut Note,
|
||||
note: &Note,
|
||||
client: &Client,
|
||||
pool: &DbPool,
|
||||
) -> Result<CommentForm, LemmyError> {
|
||||
|
|
|
@ -1,28 +1,18 @@
|
|||
use crate::{
|
||||
apub::{
|
||||
activities::{populate_object_props, send_activity},
|
||||
create_apub_response,
|
||||
create_apub_tombstone_response,
|
||||
create_tombstone,
|
||||
create_apub_response, create_apub_tombstone_response, create_tombstone,
|
||||
extensions::group_extensions::GroupExtension,
|
||||
fetcher::get_or_fetch_and_upsert_remote_user,
|
||||
get_shared_inbox,
|
||||
insert_activity,
|
||||
ActorType,
|
||||
FromApub,
|
||||
GroupExt,
|
||||
ToApub,
|
||||
get_shared_inbox, insert_activity, ActorType, FromApub, GroupExt, ToApub,
|
||||
},
|
||||
blocking,
|
||||
routes::DbPoolParam,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
DbPool, LemmyError,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::{Accept, Announce, Delete, Remove, Undo},
|
||||
Activity,
|
||||
Base,
|
||||
BaseBox,
|
||||
Activity, Base, BaseBox,
|
||||
};
|
||||
use activitystreams_ext::Ext2;
|
||||
use activitystreams_new::{
|
||||
|
@ -367,13 +357,8 @@ impl FromApub for CommunityForm {
|
|||
type ApubType = GroupExt;
|
||||
|
||||
/// Parse an ActivityPub group received from another instance into a Lemmy community.
|
||||
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();
|
||||
async fn from_apub(group: &GroupExt, client: &Client, pool: &DbPool) -> Result<Self, LemmyError> {
|
||||
let creator_and_moderator_uris = group.attributed_to().unwrap();
|
||||
let creator_uri = creator_and_moderator_uris
|
||||
.as_many()
|
||||
.unwrap()
|
||||
|
@ -386,27 +371,20 @@ impl FromApub for CommunityForm {
|
|||
let creator = get_or_fetch_and_upsert_remote_user(creator_uri.as_str(), client, pool).await?;
|
||||
|
||||
Ok(CommunityForm {
|
||||
name: group
|
||||
.take_name()
|
||||
.unwrap()
|
||||
.as_single_xsd_string()
|
||||
.unwrap()
|
||||
.into(),
|
||||
title: group.inner.take_preferred_username().unwrap(),
|
||||
name: group.name().unwrap().as_single_xsd_string().unwrap().into(),
|
||||
title: group.inner.preferred_username().unwrap().to_string(),
|
||||
// TODO: should be parsed as html and tags like <script> removed (or use markdown source)
|
||||
// -> same for post.content etc
|
||||
description: group
|
||||
.take_content()
|
||||
.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: group
|
||||
.take_published()
|
||||
.map(|u| u.as_ref().to_owned().naive_local()),
|
||||
updated: group
|
||||
.take_updated()
|
||||
.published()
|
||||
.map(|u| u.as_ref().to_owned().naive_local()),
|
||||
updated: group.updated().map(|u| u.as_ref().to_owned().naive_local()),
|
||||
deleted: None,
|
||||
nsfw: group.ext_one.sensitive,
|
||||
actor_id: group.id().unwrap().to_string(),
|
||||
|
|
|
@ -4,8 +4,7 @@ use crate::{
|
|||
blocking,
|
||||
request::{retry, RecvError},
|
||||
routes::nodeinfo::{NodeInfo, NodeInfoWellKnown},
|
||||
DbPool,
|
||||
LemmyError,
|
||||
DbPool, LemmyError,
|
||||
};
|
||||
use activitystreams::object::Note;
|
||||
use activitystreams_new::{base::BaseExt, prelude::*, primitives::XsdAnyUri};
|
||||
|
@ -22,9 +21,7 @@ use lemmy_db::{
|
|||
post_view::PostView,
|
||||
user::{UserForm, User_},
|
||||
user_view::UserView,
|
||||
Crud,
|
||||
Joinable,
|
||||
SearchType,
|
||||
Crud, Joinable, SearchType,
|
||||
};
|
||||
use lemmy_utils::get_apub_protocol_string;
|
||||
use log::debug;
|
||||
|
@ -164,15 +161,15 @@ pub async fn search_by_apub_id(
|
|||
|
||||
response
|
||||
}
|
||||
SearchAcceptedObjects::Page(mut p) => {
|
||||
let post_form = PostForm::from_apub(&mut p, client, pool).await?;
|
||||
SearchAcceptedObjects::Page(p) => {
|
||||
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??];
|
||||
|
||||
response
|
||||
}
|
||||
SearchAcceptedObjects::Comment(mut c) => {
|
||||
SearchAcceptedObjects::Comment(c) => {
|
||||
let post_url = c
|
||||
.object_props
|
||||
.get_many_in_reply_to_xsd_any_uris()
|
||||
|
@ -182,9 +179,9 @@ pub async fn search_by_apub_id(
|
|||
.to_string();
|
||||
|
||||
// TODO: also fetch parent comments if any
|
||||
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?;
|
||||
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?;
|
||||
|
||||
blocking(pool, move |conn| upsert_post(&post_form, conn)).await??;
|
||||
let c = blocking(pool, move |conn| upsert_comment(&comment_form, conn)).await??;
|
||||
|
@ -214,9 +211,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 mut person = fetch_remote_object::<PersonExt>(client, &Url::parse(apub_id)?).await?;
|
||||
let person = fetch_remote_object::<PersonExt>(client, &Url::parse(apub_id)?).await?;
|
||||
|
||||
let mut uf = UserForm::from_apub(&mut person, client, pool).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??;
|
||||
|
||||
|
@ -225,9 +222,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 mut person = fetch_remote_object::<PersonExt>(client, &Url::parse(apub_id)?).await?;
|
||||
let person = fetch_remote_object::<PersonExt>(client, &Url::parse(apub_id)?).await?;
|
||||
|
||||
let uf = UserForm::from_apub(&mut person, client, pool).await?;
|
||||
let uf = UserForm::from_apub(&person, client, pool).await?;
|
||||
let user = blocking(pool, move |conn| User_::create(conn, &uf)).await??;
|
||||
|
||||
Ok(user)
|
||||
|
@ -265,9 +262,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 mut group = fetch_remote_object::<GroupExt>(client, &Url::parse(apub_id)?).await?;
|
||||
let group = fetch_remote_object::<GroupExt>(client, &Url::parse(apub_id)?).await?;
|
||||
|
||||
let mut cf = CommunityForm::from_apub(&mut group, client, pool).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??;
|
||||
|
||||
|
@ -276,13 +273,13 @@ 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 mut group = fetch_remote_object::<GroupExt>(client, &Url::parse(apub_id)?).await?;
|
||||
let group = fetch_remote_object::<GroupExt>(client, &Url::parse(apub_id)?).await?;
|
||||
|
||||
let cf = CommunityForm::from_apub(&mut group, client, pool).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
|
||||
let attributed_to = group.inner.take_attributed_to().unwrap();
|
||||
let attributed_to = group.inner.attributed_to().unwrap();
|
||||
let creator_and_moderator_uris: Vec<&XsdAnyUri> = attributed_to
|
||||
.as_many()
|
||||
.unwrap()
|
||||
|
@ -342,8 +339,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 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 = fetch_remote_object::<PageExt>(client, &Url::parse(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??;
|
||||
|
||||
|
@ -380,8 +377,8 @@ pub async fn get_or_fetch_and_insert_remote_comment(
|
|||
"Fetching and creating remote comment and its parents: {}",
|
||||
comment_ap_id
|
||||
);
|
||||
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 = fetch_remote_object::<Note>(client, &Url::parse(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??;
|
||||
|
||||
|
|
|
@ -19,8 +19,7 @@ use crate::{
|
|||
blocking,
|
||||
request::{retry, RecvError},
|
||||
routes::webfinger::WebFingerResponse,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
DbPool, LemmyError,
|
||||
};
|
||||
use activitystreams::object::Page;
|
||||
use activitystreams_ext::{Ext1, Ext2};
|
||||
|
@ -129,7 +128,7 @@ fn create_tombstone(
|
|||
pub trait FromApub {
|
||||
type ApubType;
|
||||
async fn from_apub(
|
||||
apub: &mut Self::ApubType,
|
||||
apub: &Self::ApubType,
|
||||
client: &Client,
|
||||
pool: &DbPool,
|
||||
) -> Result<Self, LemmyError>
|
||||
|
|
|
@ -1,22 +1,14 @@
|
|||
use crate::{
|
||||
apub::{
|
||||
activities::{populate_object_props, send_activity_to_community},
|
||||
create_apub_response,
|
||||
create_apub_tombstone_response,
|
||||
create_tombstone,
|
||||
create_apub_response, create_apub_tombstone_response, create_tombstone,
|
||||
extensions::page_extension::PageExtension,
|
||||
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
|
||||
ActorType,
|
||||
ApubLikeableType,
|
||||
ApubObjectType,
|
||||
FromApub,
|
||||
PageExt,
|
||||
ToApub,
|
||||
ActorType, ApubLikeableType, ApubObjectType, FromApub, PageExt, ToApub,
|
||||
},
|
||||
blocking,
|
||||
routes::DbPoolParam,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
DbPool, LemmyError,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
|
||||
|
@ -162,7 +154,7 @@ impl FromApub for PostForm {
|
|||
|
||||
/// Parse an ActivityPub page received from another instance into a Lemmy post.
|
||||
async fn from_apub(
|
||||
page: &mut PageExt,
|
||||
page: &PageExt,
|
||||
client: &Client,
|
||||
pool: &DbPool,
|
||||
) -> Result<PostForm, LemmyError> {
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
use crate::{
|
||||
apub::{
|
||||
activities::send_activity,
|
||||
create_tombstone,
|
||||
fetcher::get_or_fetch_and_upsert_remote_user,
|
||||
insert_activity,
|
||||
ApubObjectType,
|
||||
FromApub,
|
||||
ToApub,
|
||||
activities::send_activity, create_tombstone, fetcher::get_or_fetch_and_upsert_remote_user,
|
||||
insert_activity, ApubObjectType, FromApub, ToApub,
|
||||
},
|
||||
blocking,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
blocking, DbPool, LemmyError,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::{Create, Delete, Undo, Update},
|
||||
|
@ -71,7 +64,7 @@ impl FromApub for PrivateMessageForm {
|
|||
|
||||
/// Parse an ActivityPub note received from another instance into a Lemmy Private message
|
||||
async fn from_apub(
|
||||
note: &mut Note,
|
||||
note: &Note,
|
||||
client: &Client,
|
||||
pool: &DbPool,
|
||||
) -> Result<PrivateMessageForm, LemmyError> {
|
||||
|
|
|
@ -8,15 +8,10 @@ use crate::{
|
|||
community::do_announce,
|
||||
extensions::signatures::verify,
|
||||
fetcher::{
|
||||
get_or_fetch_and_insert_remote_comment,
|
||||
get_or_fetch_and_insert_remote_post,
|
||||
get_or_fetch_and_upsert_remote_community,
|
||||
get_or_fetch_and_upsert_remote_user,
|
||||
get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post,
|
||||
get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user,
|
||||
},
|
||||
insert_activity,
|
||||
FromApub,
|
||||
GroupExt,
|
||||
PageExt,
|
||||
insert_activity, FromApub, GroupExt, PageExt,
|
||||
},
|
||||
blocking,
|
||||
routes::{ChatServerParam, DbPoolParam},
|
||||
|
@ -24,15 +19,12 @@ use crate::{
|
|||
server::{SendComment, SendCommunityRoomMessage, SendPost},
|
||||
UserOperation,
|
||||
},
|
||||
DbPool,
|
||||
LemmyError,
|
||||
DbPool, LemmyError,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::{Announce, Create, Delete, Dislike, Like, Remove, Undo, Update},
|
||||
object::Note,
|
||||
Activity,
|
||||
Base,
|
||||
BaseBox,
|
||||
Activity, Base, BaseBox,
|
||||
};
|
||||
use actix_web::{client::Client, web, HttpRequest, HttpResponse};
|
||||
use lemmy_db::{
|
||||
|
@ -43,8 +35,7 @@ use lemmy_db::{
|
|||
naive_now,
|
||||
post::{Post, PostForm, PostLike, PostLikeForm},
|
||||
post_view::PostView,
|
||||
Crud,
|
||||
Likeable,
|
||||
Crud, Likeable,
|
||||
};
|
||||
use lemmy_utils::scrape_text_for_mentions;
|
||||
use log::debug;
|
||||
|
@ -336,7 +327,7 @@ async fn receive_create_post(
|
|||
pool: &DbPool,
|
||||
chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let mut page = create
|
||||
let page = create
|
||||
.create_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -354,7 +345,7 @@ async fn receive_create_post(
|
|||
|
||||
insert_activity(user.id, create, false, pool).await?;
|
||||
|
||||
let post = PostForm::from_apub(&mut page, client, pool).await?;
|
||||
let post = PostForm::from_apub(&page, client, pool).await?;
|
||||
|
||||
let inserted_post = blocking(pool, move |conn| Post::create(conn, &post)).await??;
|
||||
|
||||
|
@ -382,7 +373,7 @@ async fn receive_create_comment(
|
|||
pool: &DbPool,
|
||||
chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let mut note = create
|
||||
let note = create
|
||||
.create_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -400,7 +391,7 @@ async fn receive_create_comment(
|
|||
|
||||
insert_activity(user.id, create, false, pool).await?;
|
||||
|
||||
let comment = CommentForm::from_apub(&mut note, client, pool).await?;
|
||||
let comment = CommentForm::from_apub(¬e, client, pool).await?;
|
||||
|
||||
let inserted_comment = blocking(pool, move |conn| Comment::create(conn, &comment)).await??;
|
||||
|
||||
|
@ -441,7 +432,7 @@ async fn receive_update_post(
|
|||
pool: &DbPool,
|
||||
chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let mut page = update
|
||||
let page = update
|
||||
.update_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -459,7 +450,7 @@ async fn receive_update_post(
|
|||
|
||||
insert_activity(user.id, update, false, pool).await?;
|
||||
|
||||
let post = PostForm::from_apub(&mut page, client, pool).await?;
|
||||
let post = PostForm::from_apub(&page, client, pool).await?;
|
||||
|
||||
let post_id = get_or_fetch_and_insert_remote_post(&post.ap_id, client, pool)
|
||||
.await?
|
||||
|
@ -487,7 +478,7 @@ async fn receive_like_post(
|
|||
pool: &DbPool,
|
||||
chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let mut page = like
|
||||
let page = like
|
||||
.like_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -501,7 +492,7 @@ async fn receive_like_post(
|
|||
|
||||
insert_activity(user.id, like, false, pool).await?;
|
||||
|
||||
let post = PostForm::from_apub(&mut page, client, pool).await?;
|
||||
let post = PostForm::from_apub(&page, client, pool).await?;
|
||||
|
||||
let post_id = get_or_fetch_and_insert_remote_post(&post.ap_id, client, pool)
|
||||
.await?
|
||||
|
@ -538,7 +529,7 @@ async fn receive_dislike_post(
|
|||
pool: &DbPool,
|
||||
chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let mut page = dislike
|
||||
let page = dislike
|
||||
.dislike_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -556,7 +547,7 @@ async fn receive_dislike_post(
|
|||
|
||||
insert_activity(user.id, dislike, false, pool).await?;
|
||||
|
||||
let post = PostForm::from_apub(&mut page, client, pool).await?;
|
||||
let post = PostForm::from_apub(&page, client, pool).await?;
|
||||
|
||||
let post_id = get_or_fetch_and_insert_remote_post(&post.ap_id, client, pool)
|
||||
.await?
|
||||
|
@ -593,7 +584,7 @@ async fn receive_update_comment(
|
|||
pool: &DbPool,
|
||||
chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let mut note = update
|
||||
let note = update
|
||||
.update_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -611,7 +602,7 @@ async fn receive_update_comment(
|
|||
|
||||
insert_activity(user.id, update, false, pool).await?;
|
||||
|
||||
let comment = CommentForm::from_apub(&mut note, client, pool).await?;
|
||||
let comment = CommentForm::from_apub(¬e, client, pool).await?;
|
||||
|
||||
let comment_id = get_or_fetch_and_insert_remote_comment(&comment.ap_id, client, pool)
|
||||
.await?
|
||||
|
@ -652,7 +643,7 @@ async fn receive_like_comment(
|
|||
pool: &DbPool,
|
||||
chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let mut note = like
|
||||
let note = like
|
||||
.like_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -666,7 +657,7 @@ async fn receive_like_comment(
|
|||
|
||||
insert_activity(user.id, like, false, pool).await?;
|
||||
|
||||
let comment = CommentForm::from_apub(&mut note, client, pool).await?;
|
||||
let comment = CommentForm::from_apub(¬e, client, pool).await?;
|
||||
|
||||
let comment_id = get_or_fetch_and_insert_remote_comment(&comment.ap_id, client, pool)
|
||||
.await?
|
||||
|
@ -710,7 +701,7 @@ async fn receive_dislike_comment(
|
|||
pool: &DbPool,
|
||||
chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let mut note = dislike
|
||||
let note = dislike
|
||||
.dislike_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -728,7 +719,7 @@ async fn receive_dislike_comment(
|
|||
|
||||
insert_activity(user.id, dislike, false, pool).await?;
|
||||
|
||||
let comment = CommentForm::from_apub(&mut note, client, pool).await?;
|
||||
let comment = CommentForm::from_apub(¬e, client, pool).await?;
|
||||
|
||||
let comment_id = get_or_fetch_and_insert_remote_comment(&comment.ap_id, client, pool)
|
||||
.await?
|
||||
|
@ -778,7 +769,7 @@ async fn receive_delete_community(
|
|||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mut group = delete
|
||||
let group = delete
|
||||
.delete_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -790,7 +781,7 @@ async fn receive_delete_community(
|
|||
|
||||
insert_activity(user.id, delete, false, pool).await?;
|
||||
|
||||
let community_actor_id = CommunityForm::from_apub(&mut group, client, pool)
|
||||
let community_actor_id = CommunityForm::from_apub(&group, client, pool)
|
||||
.await?
|
||||
.actor_id;
|
||||
|
||||
|
@ -855,7 +846,7 @@ async fn receive_remove_community(
|
|||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mut group = remove
|
||||
let group = remove
|
||||
.remove_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -867,7 +858,7 @@ async fn receive_remove_community(
|
|||
|
||||
insert_activity(mod_.id, remove, false, pool).await?;
|
||||
|
||||
let community_actor_id = CommunityForm::from_apub(&mut group, client, pool)
|
||||
let community_actor_id = CommunityForm::from_apub(&group, client, pool)
|
||||
.await?
|
||||
.actor_id;
|
||||
|
||||
|
@ -932,7 +923,7 @@ async fn receive_delete_post(
|
|||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mut page = delete
|
||||
let page = delete
|
||||
.delete_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -944,7 +935,7 @@ async fn receive_delete_post(
|
|||
|
||||
insert_activity(user.id, delete, false, pool).await?;
|
||||
|
||||
let post_ap_id = PostForm::from_apub(&mut page, client, pool).await?.ap_id;
|
||||
let post_ap_id = PostForm::from_apub(&page, client, pool).await?.ap_id;
|
||||
|
||||
let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
|
||||
|
||||
|
@ -998,7 +989,7 @@ async fn receive_remove_post(
|
|||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mut page = remove
|
||||
let page = remove
|
||||
.remove_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -1010,7 +1001,7 @@ async fn receive_remove_post(
|
|||
|
||||
insert_activity(mod_.id, remove, false, pool).await?;
|
||||
|
||||
let post_ap_id = PostForm::from_apub(&mut page, client, pool).await?.ap_id;
|
||||
let post_ap_id = PostForm::from_apub(&page, client, pool).await?.ap_id;
|
||||
|
||||
let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
|
||||
|
||||
|
@ -1064,7 +1055,7 @@ async fn receive_delete_comment(
|
|||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mut note = delete
|
||||
let note = delete
|
||||
.delete_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -1076,7 +1067,7 @@ async fn receive_delete_comment(
|
|||
|
||||
insert_activity(user.id, delete, false, pool).await?;
|
||||
|
||||
let comment_ap_id = CommentForm::from_apub(&mut note, client, pool).await?.ap_id;
|
||||
let comment_ap_id = CommentForm::from_apub(¬e, client, pool).await?.ap_id;
|
||||
|
||||
let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
|
||||
|
||||
|
@ -1132,7 +1123,7 @@ async fn receive_remove_comment(
|
|||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mut note = remove
|
||||
let note = remove
|
||||
.remove_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -1144,7 +1135,7 @@ async fn receive_remove_comment(
|
|||
|
||||
insert_activity(mod_.id, remove, false, pool).await?;
|
||||
|
||||
let comment_ap_id = CommentForm::from_apub(&mut note, client, pool).await?.ap_id;
|
||||
let comment_ap_id = CommentForm::from_apub(¬e, client, pool).await?.ap_id;
|
||||
|
||||
let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
|
||||
|
||||
|
@ -1260,7 +1251,7 @@ async fn receive_undo_delete_comment(
|
|||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mut note = delete
|
||||
let note = delete
|
||||
.delete_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -1272,7 +1263,7 @@ async fn receive_undo_delete_comment(
|
|||
|
||||
insert_activity(user.id, delete, false, pool).await?;
|
||||
|
||||
let comment_ap_id = CommentForm::from_apub(&mut note, client, pool).await?.ap_id;
|
||||
let comment_ap_id = CommentForm::from_apub(¬e, client, pool).await?.ap_id;
|
||||
|
||||
let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
|
||||
|
||||
|
@ -1328,7 +1319,7 @@ async fn receive_undo_remove_comment(
|
|||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mut note = remove
|
||||
let note = remove
|
||||
.remove_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -1340,7 +1331,7 @@ async fn receive_undo_remove_comment(
|
|||
|
||||
insert_activity(mod_.id, remove, false, pool).await?;
|
||||
|
||||
let comment_ap_id = CommentForm::from_apub(&mut note, client, pool).await?.ap_id;
|
||||
let comment_ap_id = CommentForm::from_apub(¬e, client, pool).await?.ap_id;
|
||||
|
||||
let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
|
||||
|
||||
|
@ -1396,7 +1387,7 @@ async fn receive_undo_delete_post(
|
|||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mut page = delete
|
||||
let page = delete
|
||||
.delete_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -1408,7 +1399,7 @@ async fn receive_undo_delete_post(
|
|||
|
||||
insert_activity(user.id, delete, false, pool).await?;
|
||||
|
||||
let post_ap_id = PostForm::from_apub(&mut page, client, pool).await?.ap_id;
|
||||
let post_ap_id = PostForm::from_apub(&page, client, pool).await?.ap_id;
|
||||
|
||||
let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
|
||||
|
||||
|
@ -1462,7 +1453,7 @@ async fn receive_undo_remove_post(
|
|||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mut page = remove
|
||||
let page = remove
|
||||
.remove_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -1474,7 +1465,7 @@ async fn receive_undo_remove_post(
|
|||
|
||||
insert_activity(mod_.id, remove, false, pool).await?;
|
||||
|
||||
let post_ap_id = PostForm::from_apub(&mut page, client, pool).await?.ap_id;
|
||||
let post_ap_id = PostForm::from_apub(&page, client, pool).await?.ap_id;
|
||||
|
||||
let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
|
||||
|
||||
|
@ -1528,7 +1519,7 @@ async fn receive_undo_delete_community(
|
|||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mut group = delete
|
||||
let group = delete
|
||||
.delete_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -1540,7 +1531,7 @@ async fn receive_undo_delete_community(
|
|||
|
||||
insert_activity(user.id, delete, false, pool).await?;
|
||||
|
||||
let community_actor_id = CommunityForm::from_apub(&mut group, client, pool)
|
||||
let community_actor_id = CommunityForm::from_apub(&group, client, pool)
|
||||
.await?
|
||||
.actor_id;
|
||||
|
||||
|
@ -1605,7 +1596,7 @@ async fn receive_undo_remove_community(
|
|||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mut group = remove
|
||||
let group = remove
|
||||
.remove_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -1617,7 +1608,7 @@ async fn receive_undo_remove_community(
|
|||
|
||||
insert_activity(mod_.id, remove, false, pool).await?;
|
||||
|
||||
let community_actor_id = CommunityForm::from_apub(&mut group, client, pool)
|
||||
let community_actor_id = CommunityForm::from_apub(&group, client, pool)
|
||||
.await?
|
||||
.actor_id;
|
||||
|
||||
|
@ -1705,7 +1696,7 @@ async fn receive_undo_like_comment(
|
|||
pool: &DbPool,
|
||||
chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let mut note = like
|
||||
let note = like
|
||||
.like_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -1719,7 +1710,7 @@ async fn receive_undo_like_comment(
|
|||
|
||||
insert_activity(user.id, like, false, pool).await?;
|
||||
|
||||
let comment = CommentForm::from_apub(&mut note, client, pool).await?;
|
||||
let comment = CommentForm::from_apub(¬e, client, pool).await?;
|
||||
|
||||
let comment_id = get_or_fetch_and_insert_remote_comment(&comment.ap_id, client, pool)
|
||||
.await?
|
||||
|
@ -1759,7 +1750,7 @@ async fn receive_undo_like_post(
|
|||
pool: &DbPool,
|
||||
chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let mut page = like
|
||||
let page = like
|
||||
.like_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -1773,7 +1764,7 @@ async fn receive_undo_like_post(
|
|||
|
||||
insert_activity(user.id, like, false, pool).await?;
|
||||
|
||||
let post = PostForm::from_apub(&mut page, client, pool).await?;
|
||||
let post = PostForm::from_apub(&page, client, pool).await?;
|
||||
|
||||
let post_id = get_or_fetch_and_insert_remote_post(&post.ap_id, client, pool)
|
||||
.await?
|
||||
|
|
|
@ -1,18 +1,12 @@
|
|||
use crate::{
|
||||
api::claims::Claims,
|
||||
apub::{
|
||||
activities::send_activity,
|
||||
create_apub_response,
|
||||
insert_activity,
|
||||
ActorType,
|
||||
FromApub,
|
||||
PersonExt,
|
||||
ToApub,
|
||||
activities::send_activity, create_apub_response, insert_activity, ActorType, FromApub,
|
||||
PersonExt, ToApub,
|
||||
},
|
||||
blocking,
|
||||
routes::DbPoolParam,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
DbPool, LemmyError,
|
||||
};
|
||||
use activitystreams_ext::Ext1;
|
||||
use activitystreams_new::{
|
||||
|
@ -193,8 +187,8 @@ 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: &mut PersonExt, _: &Client, _: &DbPool) -> Result<Self, LemmyError> {
|
||||
let avatar = match person.take_icon() {
|
||||
async fn from_apub(person: &PersonExt, _: &Client, _: &DbPool) -> Result<Self, LemmyError> {
|
||||
let avatar = match person.icon() {
|
||||
Some(any_image) => Image::from_any_base(any_image.as_one().unwrap().clone())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
|
@ -207,19 +201,19 @@ impl FromApub for UserForm {
|
|||
|
||||
Ok(UserForm {
|
||||
name: person
|
||||
.take_name()
|
||||
.name()
|
||||
.unwrap()
|
||||
.as_single_xsd_string()
|
||||
.unwrap()
|
||||
.into(),
|
||||
preferred_username: person.inner.take_preferred_username(),
|
||||
preferred_username: person.inner.preferred_username().map(|u| u.to_string()),
|
||||
password_encrypted: "".to_string(),
|
||||
admin: false,
|
||||
banned: false,
|
||||
email: None,
|
||||
avatar,
|
||||
updated: person
|
||||
.take_updated()
|
||||
.updated()
|
||||
.map(|u| u.as_ref().to_owned().naive_local()),
|
||||
show_nsfw: false,
|
||||
theme: "".to_string(),
|
||||
|
@ -231,7 +225,7 @@ impl FromApub for UserForm {
|
|||
matrix_user_id: None,
|
||||
actor_id: person.id().unwrap().to_string(),
|
||||
bio: person
|
||||
.take_summary()
|
||||
.summary()
|
||||
.map(|s| s.as_single_xsd_string().unwrap().into()),
|
||||
local: false,
|
||||
private_key: None,
|
||||
|
|
|
@ -3,14 +3,12 @@ use crate::{
|
|||
apub::{
|
||||
extensions::signatures::verify,
|
||||
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
|
||||
insert_activity,
|
||||
FromApub,
|
||||
insert_activity, FromApub,
|
||||
},
|
||||
blocking,
|
||||
routes::{ChatServerParam, DbPoolParam},
|
||||
websocket::{server::SendUserRoomMessage, UserOperation},
|
||||
DbPool,
|
||||
LemmyError,
|
||||
DbPool, LemmyError,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::{Accept, Create, Delete, Undo, Update},
|
||||
|
@ -23,8 +21,7 @@ use lemmy_db::{
|
|||
private_message::{PrivateMessage, PrivateMessageForm},
|
||||
private_message_view::PrivateMessageView,
|
||||
user::User_,
|
||||
Crud,
|
||||
Followable,
|
||||
Crud, Followable,
|
||||
};
|
||||
use log::debug;
|
||||
use serde::Deserialize;
|
||||
|
@ -116,7 +113,7 @@ async fn receive_create_private_message(
|
|||
pool: &DbPool,
|
||||
chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let mut note = create
|
||||
let note = create
|
||||
.create_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -135,7 +132,7 @@ async fn receive_create_private_message(
|
|||
|
||||
insert_activity(user.id, create, false, pool).await?;
|
||||
|
||||
let private_message = PrivateMessageForm::from_apub(&mut note, client, pool).await?;
|
||||
let private_message = PrivateMessageForm::from_apub(¬e, client, pool).await?;
|
||||
|
||||
let inserted_private_message = blocking(pool, move |conn| {
|
||||
PrivateMessage::create(conn, &private_message)
|
||||
|
@ -168,7 +165,7 @@ async fn receive_update_private_message(
|
|||
pool: &DbPool,
|
||||
chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let mut note = update
|
||||
let note = update
|
||||
.update_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -187,7 +184,7 @@ async fn receive_update_private_message(
|
|||
|
||||
insert_activity(user.id, update, false, pool).await?;
|
||||
|
||||
let private_message_form = PrivateMessageForm::from_apub(&mut note, client, pool).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| {
|
||||
|
@ -228,7 +225,7 @@ async fn receive_delete_private_message(
|
|||
pool: &DbPool,
|
||||
chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let mut note = delete
|
||||
let note = delete
|
||||
.delete_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -247,7 +244,7 @@ async fn receive_delete_private_message(
|
|||
|
||||
insert_activity(user.id, delete, false, pool).await?;
|
||||
|
||||
let private_message_form = PrivateMessageForm::from_apub(&mut note, client, pool).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| {
|
||||
|
@ -308,7 +305,7 @@ async fn receive_undo_delete_private_message(
|
|||
.to_owned()
|
||||
.into_concrete::<Delete>()?;
|
||||
|
||||
let mut note = delete
|
||||
let note = delete
|
||||
.delete_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
|
@ -327,7 +324,7 @@ async fn receive_undo_delete_private_message(
|
|||
|
||||
insert_activity(user.id, delete, false, pool).await?;
|
||||
|
||||
let private_message = PrivateMessageForm::from_apub(&mut note, client, pool).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| {
|
||||
|
|
Loading…
Reference in a new issue