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::{ use crate::{activities::receive::get_actor_as_user, objects::FromApub, ActorType, NoteExt};
activities::receive::get_actor_as_user,
fetcher::get_or_fetch_and_insert_comment,
objects::FromApub,
ActorType,
NoteExt,
};
use activitystreams::{ use activitystreams::{
activity::{ActorAndObjectRefExt, Create, Dislike, Like, Remove, Update}, activity::{ActorAndObjectRefExt, Create, Dislike, Like, Remove, Update},
base::ExtendsExt, base::ExtendsExt,
@ -19,7 +13,6 @@ use lemmy_db::{
use lemmy_structs::{blocking, comment::CommentResponse, send_local_notifs}; use lemmy_structs::{blocking, comment::CommentResponse, send_local_notifs};
use lemmy_utils::{location_info, utils::scrape_text_for_mentions, LemmyError}; use lemmy_utils::{location_info, utils::scrape_text_for_mentions, LemmyError};
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation}; use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
use url::Url;
pub(crate) async fn receive_create_comment( pub(crate) async fn receive_create_comment(
create: Create, 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?; let comment = Comment::from_apub(&note, context, Some(user.actor_id()?), request_counter).await?;
// TODO: why fetch? let comment_id = comment.id;
let original_comment_id =
get_or_fetch_and_insert_comment(&Url::parse(&comment.ap_id)?, context, request_counter)
.await?
.id;
let post_id = comment.post_id; let post_id = comment.post_id;
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??; 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 // Refetch the view
let comment_view = blocking(context.pool(), move |conn| { let comment_view = blocking(context.pool(), move |conn| {
CommentView::read(conn, original_comment_id, None) CommentView::read(conn, comment_id, None)
}) })
.await??; .await??;
@ -124,12 +112,7 @@ pub(crate) async fn receive_like_comment(
let comment = Comment::from_apub(&note, context, None, request_counter).await?; 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 = comment.id;
let comment_id =
get_or_fetch_and_insert_comment(&Url::parse(&comment.ap_id)?, context, request_counter)
.await?
.id;
let like_form = CommentLikeForm { let like_form = CommentLikeForm {
comment_id, comment_id,
post_id: comment.post_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?; let comment = Comment::from_apub(&note, context, None, request_counter).await?;
// TODO: same as above, why fetch here? let comment_id = comment.id;
let comment_id =
get_or_fetch_and_insert_comment(&Url::parse(&comment.ap_id)?, context, request_counter)
.await?
.id;
let like_form = CommentLikeForm { let like_form = CommentLikeForm {
comment_id, comment_id,
post_id: comment.post_id, post_id: comment.post_id,

View File

@ -1,9 +1,4 @@
use crate::{ use crate::{activities::receive::get_actor_as_user, objects::FromApub, NoteExt};
activities::receive::get_actor_as_user,
fetcher::get_or_fetch_and_insert_comment,
objects::FromApub,
NoteExt,
};
use activitystreams::{activity::*, prelude::*}; use activitystreams::{activity::*, prelude::*};
use anyhow::Context; use anyhow::Context;
use lemmy_db::{ use lemmy_db::{
@ -14,7 +9,6 @@ use lemmy_db::{
use lemmy_structs::{blocking, comment::CommentResponse}; use lemmy_structs::{blocking, comment::CommentResponse};
use lemmy_utils::{location_info, LemmyError}; use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation}; use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
use url::Url;
pub(crate) async fn receive_undo_like_comment( pub(crate) async fn receive_undo_like_comment(
like: &Like, 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?; let comment = Comment::from_apub(&note, context, None, request_counter).await?;
// TODO: why? let comment_id = comment.id;
let comment_id =
get_or_fetch_and_insert_comment(&Url::parse(&comment.ap_id)?, context, request_counter)
.await?
.id;
let user_id = user.id; let user_id = user.id;
blocking(context.pool(), move |conn| { blocking(context.pool(), move |conn| {
CommentLike::remove(conn, user_id, comment_id) 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?; let comment = Comment::from_apub(&note, context, None, request_counter).await?;
// TODO let comment_id = comment.id;
let comment_id =
get_or_fetch_and_insert_comment(&Url::parse(&comment.ap_id)?, context, request_counter)
.await?
.id;
let user_id = user.id; let user_id = user.id;
blocking(context.pool(), move |conn| { blocking(context.pool(), move |conn| {
CommentLike::remove(conn, user_id, comment_id) CommentLike::remove(conn, user_id, comment_id)

View File

@ -1,10 +1,4 @@
use crate::{ use crate::{activities::receive::get_actor_as_user, objects::FromApub, ActorType, PageExt};
activities::receive::get_actor_as_user,
fetcher::get_or_fetch_and_insert_post,
objects::FromApub,
ActorType,
PageExt,
};
use activitystreams::{ use activitystreams::{
activity::{Create, Dislike, Like, Remove, Update}, activity::{Create, Dislike, Like, Remove, Update},
prelude::*, prelude::*,
@ -18,7 +12,6 @@ use lemmy_db::{
use lemmy_structs::{blocking, post::PostResponse}; use lemmy_structs::{blocking, post::PostResponse};
use lemmy_utils::{location_info, LemmyError}; use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation}; use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
use url::Url;
pub(crate) async fn receive_create_post( pub(crate) async fn receive_create_post(
create: Create, 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?; let post = Post::from_apub(&page, context, Some(user.actor_id()?), request_counter).await?;
// TODO: why? let post_id = post.id;
let original_post_id =
get_or_fetch_and_insert_post(&Url::parse(&post.ap_id)?, context, request_counter)
.await?
.id;
// Refetch the view // Refetch the view
let post_view = blocking(context.pool(), move |conn| { let post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, original_post_id, None) PostView::read(conn, post_id, None)
}) })
.await??; .await??;
@ -94,11 +82,7 @@ pub(crate) async fn receive_like_post(
let post = Post::from_apub(&page, context, None, request_counter).await?; let post = Post::from_apub(&page, context, None, request_counter).await?;
// TODO: why? let post_id = post.id;
let post_id = get_or_fetch_and_insert_post(&Url::parse(&post.ap_id)?, context, request_counter)
.await?
.id;
let like_form = PostLikeForm { let like_form = PostLikeForm {
post_id, post_id,
user_id: user.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 = 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) let post_id = post.id;
.await?
.id;
let like_form = PostLikeForm { let like_form = PostLikeForm {
post_id, post_id,
user_id: user.id, user_id: user.id,

View File

@ -1,9 +1,4 @@
use crate::{ use crate::{activities::receive::get_actor_as_user, objects::FromApub, PageExt};
activities::receive::get_actor_as_user,
fetcher::get_or_fetch_and_insert_post,
objects::FromApub,
PageExt,
};
use activitystreams::{activity::*, prelude::*}; use activitystreams::{activity::*, prelude::*};
use anyhow::Context; use anyhow::Context;
use lemmy_db::{ use lemmy_db::{
@ -14,7 +9,6 @@ use lemmy_db::{
use lemmy_structs::{blocking, post::PostResponse}; use lemmy_structs::{blocking, post::PostResponse};
use lemmy_utils::{location_info, LemmyError}; use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation}; use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
use url::Url;
pub(crate) async fn receive_undo_like_post( pub(crate) async fn receive_undo_like_post(
like: &Like, 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?; let post = Post::from_apub(&page, context, None, request_counter).await?;
// TODO: why? let post_id = post.id;
let post_id = get_or_fetch_and_insert_post(&Url::parse(&post.ap_id)?, context, request_counter)
.await?
.id;
let user_id = user.id; let user_id = user.id;
blocking(context.pool(), move |conn| { blocking(context.pool(), move |conn| {
PostLike::remove(conn, user_id, post_id) 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?; let post = Post::from_apub(&page, context, None, request_counter).await?;
// TODO: why? let post_id = post.id;
let post_id = get_or_fetch_and_insert_post(&Url::parse(&post.ap_id)?, context, request_counter)
.await?
.id;
let user_id = user.id; let user_id = user.id;
blocking(context.pool(), move |conn| { blocking(context.pool(), move |conn| {
PostLike::remove(conn, user_id, post_id) PostLike::remove(conn, user_id, post_id)