diff options
Diffstat (limited to 'server/src/apub/shared_inbox.rs')
-rw-r--r-- | server/src/apub/shared_inbox.rs | 132 |
1 files changed, 62 insertions, 70 deletions
diff --git a/server/src/apub/shared_inbox.rs b/server/src/apub/shared_inbox.rs index fa9794b2..f0f5bbfd 100644 --- a/server/src/apub/shared_inbox.rs +++ b/server/src/apub/shared_inbox.rs @@ -5,47 +5,39 @@ use crate::{ post::PostResponse, }, apub::{ + 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, }, - FromApub, - GroupExt, - PageExt, + insert_activity, FromApub, GroupExt, PageExt, }, blocking, - db::{ - activity::insert_activity, - comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, - comment_view::CommentView, - community::{Community, CommunityForm}, - community_view::CommunityView, - post::{Post, PostForm, PostLike, PostLikeForm}, - post_view::PostView, - Crud, - Likeable, - }, - naive_now, routes::{ChatServerParam, DbPoolParam}, - scrape_text_for_mentions, websocket::{ 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::{ + comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, + comment_view::CommentView, + community::{Community, CommunityForm}, + community_view::CommunityView, + naive_now, + post::{Post, PostForm, PostLike, PostLikeForm}, + post_view::PostView, + Crud, Likeable, +}; +use lemmy_utils::scrape_text_for_mentions; use log::debug; use serde::{Deserialize, Serialize}; use std::fmt::Debug; @@ -234,7 +226,7 @@ where if community.local { let sending_user = get_or_fetch_and_upsert_remote_user(sender, client, pool).await?; - Community::do_announce(activity, &community, &sending_user, client, pool).await + do_announce(activity, &community, &sending_user, client, pool).await } else { Ok(HttpResponse::NotFound().finish()) } @@ -335,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() @@ -353,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??; @@ -381,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() @@ -399,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??; @@ -440,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() @@ -458,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? @@ -486,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() @@ -500,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? @@ -537,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() @@ -555,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? @@ -592,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() @@ -610,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? @@ -651,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() @@ -665,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? @@ -709,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() @@ -727,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? @@ -777,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() @@ -789,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; @@ -854,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() @@ -866,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; @@ -931,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() @@ -943,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?; @@ -997,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() @@ -1009,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?; @@ -1063,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() @@ -1075,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?; @@ -1131,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() @@ -1143,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?; @@ -1259,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() @@ -1271,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?; @@ -1327,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() @@ -1339,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?; @@ -1395,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() @@ -1407,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?; @@ -1461,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() @@ -1473,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?; @@ -1527,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() @@ -1539,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; @@ -1604,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() @@ -1616,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; @@ -1704,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() @@ -1718,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? @@ -1758,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() @@ -1772,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? |