This commit is contained in:
Felix Ableitner 2020-12-01 17:34:14 +01:00
parent dbf9c69709
commit 9629f8140b
4 changed files with 16 additions and 87 deletions

View File

@ -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(&note, 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(&note, 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(&note, 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,

View File

@ -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(&note, 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(&note, 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)

View File

@ -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,

View File

@ -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)