summaryrefslogtreecommitdiffstats
path: root/server/src/apub/fetcher.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/apub/fetcher.rs')
-rw-r--r--server/src/apub/fetcher.rs45
1 files changed, 21 insertions, 24 deletions
diff --git a/server/src/apub/fetcher.rs b/server/src/apub/fetcher.rs
index 0604129d..4251cb76 100644
--- a/server/src/apub/fetcher.rs
+++ b/server/src/apub/fetcher.rs
@@ -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??;