From 9629f8140b3c58bb97db3cb6f5ea9a9781bc424e Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 1 Dec 2020 17:34:14 +0100 Subject: [PATCH] cleanup --- lemmy_apub/src/activities/receive/comment.rs | 32 +++---------------- .../src/activities/receive/comment_undo.rs | 22 ++----------- lemmy_apub/src/activities/receive/post.rs | 29 +++-------------- .../src/activities/receive/post_undo.rs | 20 ++---------- 4 files changed, 16 insertions(+), 87 deletions(-) diff --git a/lemmy_apub/src/activities/receive/comment.rs b/lemmy_apub/src/activities/receive/comment.rs index 26220d060..6f6a22da8 100644 --- a/lemmy_apub/src/activities/receive/comment.rs +++ b/lemmy_apub/src/activities/receive/comment.rs @@ -1,10 +1,4 @@ -use crate::{ - activities::receive::get_actor_as_user, - fetcher::get_or_fetch_and_insert_comment, - objects::FromApub, - ActorType, - NoteExt, -}; +use crate::{activities::receive::get_actor_as_user, objects::FromApub, ActorType, NoteExt}; use activitystreams::{ activity::{ActorAndObjectRefExt, Create, Dislike, Like, Remove, Update}, base::ExtendsExt, @@ -19,7 +13,6 @@ use lemmy_db::{ use lemmy_structs::{blocking, comment::CommentResponse, send_local_notifs}; use lemmy_utils::{location_info, utils::scrape_text_for_mentions, LemmyError}; use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation}; -use url::Url; pub(crate) async fn receive_create_comment( create: Create, @@ -79,12 +72,7 @@ pub(crate) async fn receive_update_comment( let comment = Comment::from_apub(¬e, context, Some(user.actor_id()?), request_counter).await?; - // TODO: why fetch? - let original_comment_id = - get_or_fetch_and_insert_comment(&Url::parse(&comment.ap_id)?, context, request_counter) - .await? - .id; - + let comment_id = comment.id; let post_id = comment.post_id; let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??; @@ -94,7 +82,7 @@ pub(crate) async fn receive_update_comment( // Refetch the view let comment_view = blocking(context.pool(), move |conn| { - CommentView::read(conn, original_comment_id, None) + CommentView::read(conn, comment_id, None) }) .await??; @@ -124,12 +112,7 @@ pub(crate) async fn receive_like_comment( let comment = Comment::from_apub(¬e, context, None, request_counter).await?; - // TODO: why do we need to fetch here if we already have the comment? - let comment_id = - get_or_fetch_and_insert_comment(&Url::parse(&comment.ap_id)?, context, request_counter) - .await? - .id; - + let comment_id = comment.id; let like_form = CommentLikeForm { comment_id, post_id: comment.post_id, @@ -183,12 +166,7 @@ pub(crate) async fn receive_dislike_comment( let comment = Comment::from_apub(¬e, context, None, request_counter).await?; - // TODO: same as above, why fetch here? - let comment_id = - get_or_fetch_and_insert_comment(&Url::parse(&comment.ap_id)?, context, request_counter) - .await? - .id; - + let comment_id = comment.id; let like_form = CommentLikeForm { comment_id, post_id: comment.post_id, diff --git a/lemmy_apub/src/activities/receive/comment_undo.rs b/lemmy_apub/src/activities/receive/comment_undo.rs index 5e5295d7d..2ccec087b 100644 --- a/lemmy_apub/src/activities/receive/comment_undo.rs +++ b/lemmy_apub/src/activities/receive/comment_undo.rs @@ -1,9 +1,4 @@ -use crate::{ - activities::receive::get_actor_as_user, - fetcher::get_or_fetch_and_insert_comment, - objects::FromApub, - NoteExt, -}; +use crate::{activities::receive::get_actor_as_user, objects::FromApub, NoteExt}; use activitystreams::{activity::*, prelude::*}; use anyhow::Context; use lemmy_db::{ @@ -14,7 +9,6 @@ use lemmy_db::{ use lemmy_structs::{blocking, comment::CommentResponse}; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation}; -use url::Url; pub(crate) async fn receive_undo_like_comment( like: &Like, @@ -27,12 +21,7 @@ pub(crate) async fn receive_undo_like_comment( let comment = Comment::from_apub(¬e, context, None, request_counter).await?; - // TODO: why? - let comment_id = - get_or_fetch_and_insert_comment(&Url::parse(&comment.ap_id)?, context, request_counter) - .await? - .id; - + let comment_id = comment.id; let user_id = user.id; blocking(context.pool(), move |conn| { CommentLike::remove(conn, user_id, comment_id) @@ -79,12 +68,7 @@ pub(crate) async fn receive_undo_dislike_comment( let comment = Comment::from_apub(¬e, context, None, request_counter).await?; - // TODO - let comment_id = - get_or_fetch_and_insert_comment(&Url::parse(&comment.ap_id)?, context, request_counter) - .await? - .id; - + let comment_id = comment.id; let user_id = user.id; blocking(context.pool(), move |conn| { CommentLike::remove(conn, user_id, comment_id) diff --git a/lemmy_apub/src/activities/receive/post.rs b/lemmy_apub/src/activities/receive/post.rs index e8f4b61bd..d1c92157f 100644 --- a/lemmy_apub/src/activities/receive/post.rs +++ b/lemmy_apub/src/activities/receive/post.rs @@ -1,10 +1,4 @@ -use crate::{ - activities::receive::get_actor_as_user, - fetcher::get_or_fetch_and_insert_post, - objects::FromApub, - ActorType, - PageExt, -}; +use crate::{activities::receive::get_actor_as_user, objects::FromApub, ActorType, PageExt}; use activitystreams::{ activity::{Create, Dislike, Like, Remove, Update}, prelude::*, @@ -18,7 +12,6 @@ use lemmy_db::{ use lemmy_structs::{blocking, post::PostResponse}; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation}; -use url::Url; pub(crate) async fn receive_create_post( create: Create, @@ -60,15 +53,10 @@ pub(crate) async fn receive_update_post( let post = Post::from_apub(&page, context, Some(user.actor_id()?), request_counter).await?; - // TODO: why? - let original_post_id = - get_or_fetch_and_insert_post(&Url::parse(&post.ap_id)?, context, request_counter) - .await? - .id; - + let post_id = post.id; // Refetch the view let post_view = blocking(context.pool(), move |conn| { - PostView::read(conn, original_post_id, None) + PostView::read(conn, post_id, None) }) .await??; @@ -94,11 +82,7 @@ pub(crate) async fn receive_like_post( let post = Post::from_apub(&page, context, None, request_counter).await?; - // TODO: why? - let post_id = get_or_fetch_and_insert_post(&Url::parse(&post.ap_id)?, context, request_counter) - .await? - .id; - + let post_id = post.id; let like_form = PostLikeForm { post_id, user_id: user.id, @@ -145,10 +129,7 @@ pub(crate) async fn receive_dislike_post( let post = Post::from_apub(&page, context, None, request_counter).await?; - let post_id = get_or_fetch_and_insert_post(&Url::parse(&post.ap_id)?, context, request_counter) - .await? - .id; - + let post_id = post.id; let like_form = PostLikeForm { post_id, user_id: user.id, diff --git a/lemmy_apub/src/activities/receive/post_undo.rs b/lemmy_apub/src/activities/receive/post_undo.rs index 8d45f7fa3..aced5f4b3 100644 --- a/lemmy_apub/src/activities/receive/post_undo.rs +++ b/lemmy_apub/src/activities/receive/post_undo.rs @@ -1,9 +1,4 @@ -use crate::{ - activities::receive::get_actor_as_user, - fetcher::get_or_fetch_and_insert_post, - objects::FromApub, - PageExt, -}; +use crate::{activities::receive::get_actor_as_user, objects::FromApub, PageExt}; use activitystreams::{activity::*, prelude::*}; use anyhow::Context; use lemmy_db::{ @@ -14,7 +9,6 @@ use lemmy_db::{ use lemmy_structs::{blocking, post::PostResponse}; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation}; -use url::Url; pub(crate) async fn receive_undo_like_post( like: &Like, @@ -27,11 +21,7 @@ pub(crate) async fn receive_undo_like_post( let post = Post::from_apub(&page, context, None, request_counter).await?; - // TODO: why? - let post_id = get_or_fetch_and_insert_post(&Url::parse(&post.ap_id)?, context, request_counter) - .await? - .id; - + let post_id = post.id; let user_id = user.id; blocking(context.pool(), move |conn| { PostLike::remove(conn, user_id, post_id) @@ -72,11 +62,7 @@ pub(crate) async fn receive_undo_dislike_post( let post = Post::from_apub(&page, context, None, request_counter).await?; - // TODO: why? - let post_id = get_or_fetch_and_insert_post(&Url::parse(&post.ap_id)?, context, request_counter) - .await? - .id; - + let post_id = post.id; let user_id = user.id; blocking(context.pool(), move |conn| { PostLike::remove(conn, user_id, post_id)