mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-05 20:15:01 +00:00
convert all comment receivers (except undo comment)
This commit is contained in:
parent
350ef7c2c6
commit
26f4694b98
17 changed files with 417 additions and 308 deletions
|
@ -1,211 +0,0 @@
|
|||
use crate::activities::receive::get_actor_as_person;
|
||||
use activitystreams::{
|
||||
activity::{ActorAndObjectRefExt, Dislike, Like, Update},
|
||||
base::ExtendsExt,
|
||||
};
|
||||
use anyhow::Context;
|
||||
use lemmy_api_common::{blocking, comment::CommentResponse, send_local_notifs};
|
||||
use lemmy_apub::{objects::FromApub, ActorType, NoteExt};
|
||||
use lemmy_db_queries::{source::comment::Comment_, Crud, Likeable};
|
||||
use lemmy_db_schema::source::{
|
||||
comment::{Comment, CommentLike, CommentLikeForm},
|
||||
post::Post,
|
||||
};
|
||||
use lemmy_db_views::comment_view::CommentView;
|
||||
use lemmy_utils::{location_info, utils::scrape_text_for_mentions, LemmyError};
|
||||
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation, UserOperationCrud};
|
||||
|
||||
pub(crate) async fn receive_update_comment(
|
||||
update: Update,
|
||||
context: &LemmyContext,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError> {
|
||||
let note = NoteExt::from_any_base(update.object().to_owned().one().context(location_info!())?)?
|
||||
.context(location_info!())?;
|
||||
let person = get_actor_as_person(&update, context, request_counter).await?;
|
||||
|
||||
let comment =
|
||||
Comment::from_apub(¬e, context, person.actor_id(), request_counter, false).await?;
|
||||
|
||||
let comment_id = comment.id;
|
||||
let post_id = comment.post_id;
|
||||
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
||||
|
||||
let mentions = scrape_text_for_mentions(&comment.content);
|
||||
let recipient_ids =
|
||||
send_local_notifs(mentions, comment, person, post, context.pool(), false).await?;
|
||||
|
||||
// Refetch the view
|
||||
let comment_view = blocking(context.pool(), move |conn| {
|
||||
CommentView::read(conn, comment_id, None)
|
||||
})
|
||||
.await??;
|
||||
|
||||
let res = CommentResponse {
|
||||
comment_view,
|
||||
recipient_ids,
|
||||
form_id: None,
|
||||
};
|
||||
|
||||
context.chat_server().do_send(SendComment {
|
||||
op: UserOperationCrud::EditComment,
|
||||
comment: res,
|
||||
websocket_id: None,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn receive_like_comment(
|
||||
like: Like,
|
||||
comment: Comment,
|
||||
context: &LemmyContext,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError> {
|
||||
let person = get_actor_as_person(&like, context, request_counter).await?;
|
||||
|
||||
let comment_id = comment.id;
|
||||
let like_form = CommentLikeForm {
|
||||
comment_id,
|
||||
post_id: comment.post_id,
|
||||
person_id: person.id,
|
||||
score: 1,
|
||||
};
|
||||
let person_id = person.id;
|
||||
blocking(context.pool(), move |conn| {
|
||||
CommentLike::remove(conn, person_id, comment_id)?;
|
||||
CommentLike::like(conn, &like_form)
|
||||
})
|
||||
.await??;
|
||||
|
||||
// Refetch the view
|
||||
let comment_view = blocking(context.pool(), move |conn| {
|
||||
CommentView::read(conn, comment_id, None)
|
||||
})
|
||||
.await??;
|
||||
|
||||
// TODO get those recipient actor ids from somewhere
|
||||
let recipient_ids = vec![];
|
||||
let res = CommentResponse {
|
||||
comment_view,
|
||||
recipient_ids,
|
||||
form_id: None,
|
||||
};
|
||||
|
||||
context.chat_server().do_send(SendComment {
|
||||
op: UserOperation::CreateCommentLike,
|
||||
comment: res,
|
||||
websocket_id: None,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn receive_dislike_comment(
|
||||
dislike: Dislike,
|
||||
comment: Comment,
|
||||
context: &LemmyContext,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError> {
|
||||
let person = get_actor_as_person(&dislike, context, request_counter).await?;
|
||||
|
||||
let comment_id = comment.id;
|
||||
let like_form = CommentLikeForm {
|
||||
comment_id,
|
||||
post_id: comment.post_id,
|
||||
person_id: person.id,
|
||||
score: -1,
|
||||
};
|
||||
let person_id = person.id;
|
||||
blocking(context.pool(), move |conn| {
|
||||
CommentLike::remove(conn, person_id, comment_id)?;
|
||||
CommentLike::like(conn, &like_form)
|
||||
})
|
||||
.await??;
|
||||
|
||||
// Refetch the view
|
||||
let comment_view = blocking(context.pool(), move |conn| {
|
||||
CommentView::read(conn, comment_id, None)
|
||||
})
|
||||
.await??;
|
||||
|
||||
// TODO get those recipient actor ids from somewhere
|
||||
let recipient_ids = vec![];
|
||||
let res = CommentResponse {
|
||||
comment_view,
|
||||
recipient_ids,
|
||||
form_id: None,
|
||||
};
|
||||
|
||||
context.chat_server().do_send(SendComment {
|
||||
op: UserOperation::CreateCommentLike,
|
||||
comment: res,
|
||||
websocket_id: None,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn receive_delete_comment(
|
||||
context: &LemmyContext,
|
||||
comment: Comment,
|
||||
) -> Result<(), LemmyError> {
|
||||
let deleted_comment = blocking(context.pool(), move |conn| {
|
||||
Comment::update_deleted(conn, comment.id, true)
|
||||
})
|
||||
.await??;
|
||||
|
||||
// Refetch the view
|
||||
let comment_id = deleted_comment.id;
|
||||
let comment_view = blocking(context.pool(), move |conn| {
|
||||
CommentView::read(conn, comment_id, None)
|
||||
})
|
||||
.await??;
|
||||
|
||||
// TODO get those recipient actor ids from somewhere
|
||||
let recipient_ids = vec![];
|
||||
let res = CommentResponse {
|
||||
comment_view,
|
||||
recipient_ids,
|
||||
form_id: None,
|
||||
};
|
||||
context.chat_server().do_send(SendComment {
|
||||
op: UserOperationCrud::EditComment,
|
||||
comment: res,
|
||||
websocket_id: None,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn receive_remove_comment(
|
||||
context: &LemmyContext,
|
||||
comment: Comment,
|
||||
) -> Result<(), LemmyError> {
|
||||
let removed_comment = blocking(context.pool(), move |conn| {
|
||||
Comment::update_removed(conn, comment.id, true)
|
||||
})
|
||||
.await??;
|
||||
|
||||
// Refetch the view
|
||||
let comment_id = removed_comment.id;
|
||||
let comment_view = blocking(context.pool(), move |conn| {
|
||||
CommentView::read(conn, comment_id, None)
|
||||
})
|
||||
.await??;
|
||||
|
||||
// TODO get those recipient actor ids from somewhere
|
||||
let recipient_ids = vec![];
|
||||
let res = CommentResponse {
|
||||
comment_view,
|
||||
recipient_ids,
|
||||
form_id: None,
|
||||
};
|
||||
context.chat_server().do_send(SendComment {
|
||||
op: UserOperationCrud::EditComment,
|
||||
comment: res,
|
||||
websocket_id: None,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -12,7 +12,6 @@ use log::debug;
|
|||
use std::fmt::Debug;
|
||||
use url::Url;
|
||||
|
||||
pub(crate) mod comment;
|
||||
pub(crate) mod comment_undo;
|
||||
pub(crate) mod community;
|
||||
pub(crate) mod post;
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
use crate::inbox::new_inbox_routing::Activity;
|
||||
use activitystreams::activity::kind::CreateType;
|
||||
use lemmy_api_common::{blocking, comment::CommentResponse, send_local_notifs};
|
||||
use lemmy_apub::{fetcher::person::get_or_fetch_and_upsert_person, objects::FromApub, NoteExt};
|
||||
use lemmy_apub_lib::{PublicUrl, ReceiveActivity};
|
||||
use lemmy_db_queries::Crud;
|
||||
use lemmy_db_schema::source::{comment::Comment, post::Post};
|
||||
use lemmy_db_views::comment_view::CommentView;
|
||||
use lemmy_utils::{utils::scrape_text_for_mentions, LemmyError};
|
||||
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperationCrud};
|
||||
use crate::{
|
||||
activities_new::comment::{get_notif_recipients, send_websocket_message},
|
||||
inbox::new_inbox_routing::Activity,
|
||||
};
|
||||
use activitystreams::{activity::kind::CreateType, base::BaseExt};
|
||||
use anyhow::Context;
|
||||
use lemmy_apub::{objects::FromApub, NoteExt};
|
||||
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity};
|
||||
use lemmy_db_schema::source::comment::Comment;
|
||||
use lemmy_utils::{location_info, LemmyError};
|
||||
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
|
@ -27,6 +28,12 @@ impl ReceiveActivity for Activity<CreateComment> {
|
|||
context: &LemmyContext,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError> {
|
||||
verify_domains_match(&self.inner.actor, self.id_unchecked())?;
|
||||
verify_domains_match(
|
||||
&self.inner.actor,
|
||||
self.inner.object.id_unchecked().context(location_info!())?,
|
||||
)?;
|
||||
|
||||
let comment = Comment::from_apub(
|
||||
&self.inner.object,
|
||||
context,
|
||||
|
@ -35,37 +42,14 @@ impl ReceiveActivity for Activity<CreateComment> {
|
|||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let post_id = comment.post_id;
|
||||
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
||||
let actor = get_or_fetch_and_upsert_person(&self.inner.actor, context, request_counter).await?;
|
||||
|
||||
// Note:
|
||||
// Although mentions could be gotten from the post tags (they are included there), or the ccs,
|
||||
// Its much easier to scrape them from the comment body, since the API has to do that
|
||||
// anyway.
|
||||
let mentions = scrape_text_for_mentions(&comment.content);
|
||||
let recipient_ids =
|
||||
send_local_notifs(mentions, comment.clone(), actor, post, context.pool(), true).await?;
|
||||
|
||||
// Refetch the view
|
||||
let comment_view = blocking(context.pool(), move |conn| {
|
||||
CommentView::read(conn, comment.id, None)
|
||||
})
|
||||
.await??;
|
||||
|
||||
let res = CommentResponse {
|
||||
comment_view,
|
||||
recipient_ids,
|
||||
form_id: None,
|
||||
};
|
||||
|
||||
context.chat_server().do_send(SendComment {
|
||||
op: UserOperationCrud::CreateComment,
|
||||
comment: res,
|
||||
websocket_id: None,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
let recipients =
|
||||
get_notif_recipients(&self.inner.actor, &comment, context, request_counter).await?;
|
||||
send_websocket_message(
|
||||
comment.id,
|
||||
recipients,
|
||||
UserOperationCrud::CreateComment,
|
||||
context,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
47
crates/apub_receive/src/activities_new/comment/delete.rs
Normal file
47
crates/apub_receive/src/activities_new/comment/delete.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
use crate::{activities_new::comment::send_websocket_message, inbox::new_inbox_routing::Activity};
|
||||
use activitystreams::activity::kind::DeleteType;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub::fetcher::objects::get_or_fetch_and_insert_comment;
|
||||
use lemmy_apub_lib::{PublicUrl, ReceiveActivity};
|
||||
use lemmy_db_queries::source::comment::Comment_;
|
||||
use lemmy_db_schema::source::comment::Comment;
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DeleteComment {
|
||||
actor: Url,
|
||||
to: PublicUrl,
|
||||
object: Url,
|
||||
cc: Vec<Url>,
|
||||
#[serde(rename = "type")]
|
||||
kind: DeleteType,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl ReceiveActivity for Activity<DeleteComment> {
|
||||
async fn receive(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError> {
|
||||
let comment =
|
||||
get_or_fetch_and_insert_comment(&self.inner.object, context, request_counter).await?;
|
||||
|
||||
let deleted_comment = blocking(context.pool(), move |conn| {
|
||||
Comment::update_deleted(conn, comment.id, true)
|
||||
})
|
||||
.await??;
|
||||
|
||||
// TODO get those recipient actor ids from somewhere
|
||||
send_websocket_message(
|
||||
deleted_comment.id,
|
||||
vec![],
|
||||
UserOperationCrud::EditComment,
|
||||
context,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
61
crates/apub_receive/src/activities_new/comment/dislike.rs
Normal file
61
crates/apub_receive/src/activities_new/comment/dislike.rs
Normal file
|
@ -0,0 +1,61 @@
|
|||
use crate::{activities_new::comment::send_websocket_message, inbox::new_inbox_routing::Activity};
|
||||
use activitystreams::activity::kind::DislikeType;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub::fetcher::{
|
||||
objects::get_or_fetch_and_insert_comment,
|
||||
person::get_or_fetch_and_upsert_person,
|
||||
};
|
||||
use lemmy_apub_lib::{PublicUrl, ReceiveActivity};
|
||||
use lemmy_db_queries::Likeable;
|
||||
use lemmy_db_schema::source::comment::{CommentLike, CommentLikeForm};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{LemmyContext, UserOperation};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DislikeComment {
|
||||
actor: Url,
|
||||
to: PublicUrl,
|
||||
object: Url,
|
||||
cc: Vec<Url>,
|
||||
#[serde(rename = "type")]
|
||||
kind: DislikeType,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl ReceiveActivity for Activity<DislikeComment> {
|
||||
async fn receive(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError> {
|
||||
let person =
|
||||
get_or_fetch_and_upsert_person(&self.inner.actor, context, request_counter).await?;
|
||||
let comment =
|
||||
get_or_fetch_and_insert_comment(&self.inner.object, context, request_counter).await?;
|
||||
|
||||
let comment_id = comment.id;
|
||||
let like_form = CommentLikeForm {
|
||||
comment_id,
|
||||
post_id: comment.post_id,
|
||||
person_id: person.id,
|
||||
score: -1,
|
||||
};
|
||||
let person_id = person.id;
|
||||
blocking(context.pool(), move |conn| {
|
||||
CommentLike::remove(conn, person_id, comment_id)?;
|
||||
CommentLike::like(conn, &like_form)
|
||||
})
|
||||
.await??;
|
||||
|
||||
// TODO get those recipient actor ids from somewhere
|
||||
send_websocket_message(
|
||||
comment_id,
|
||||
vec![],
|
||||
UserOperation::CreateCommentLike,
|
||||
context,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
61
crates/apub_receive/src/activities_new/comment/like.rs
Normal file
61
crates/apub_receive/src/activities_new/comment/like.rs
Normal file
|
@ -0,0 +1,61 @@
|
|||
use crate::{activities_new::comment::send_websocket_message, inbox::new_inbox_routing::Activity};
|
||||
use activitystreams::activity::kind::LikeType;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub::fetcher::{
|
||||
objects::get_or_fetch_and_insert_comment,
|
||||
person::get_or_fetch_and_upsert_person,
|
||||
};
|
||||
use lemmy_apub_lib::{PublicUrl, ReceiveActivity};
|
||||
use lemmy_db_queries::Likeable;
|
||||
use lemmy_db_schema::source::comment::{CommentLike, CommentLikeForm};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{LemmyContext, UserOperation};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LikeComment {
|
||||
actor: Url,
|
||||
to: PublicUrl,
|
||||
object: Url,
|
||||
cc: Vec<Url>,
|
||||
#[serde(rename = "type")]
|
||||
kind: LikeType,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl ReceiveActivity for Activity<LikeComment> {
|
||||
async fn receive(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError> {
|
||||
let person =
|
||||
get_or_fetch_and_upsert_person(&self.inner.actor, context, request_counter).await?;
|
||||
let comment =
|
||||
get_or_fetch_and_insert_comment(&self.inner.object, context, request_counter).await?;
|
||||
|
||||
let comment_id = comment.id;
|
||||
let like_form = CommentLikeForm {
|
||||
comment_id,
|
||||
post_id: comment.post_id,
|
||||
person_id: person.id,
|
||||
score: 1,
|
||||
};
|
||||
let person_id = person.id;
|
||||
blocking(context.pool(), move |conn| {
|
||||
CommentLike::remove(conn, person_id, comment_id)?;
|
||||
CommentLike::like(conn, &like_form)
|
||||
})
|
||||
.await??;
|
||||
|
||||
// TODO get those recipient actor ids from somewhere
|
||||
send_websocket_message(
|
||||
comment_id,
|
||||
vec![],
|
||||
UserOperation::CreateCommentLike,
|
||||
context,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
|
@ -1 +1,64 @@
|
|||
use lemmy_api_common::{blocking, comment::CommentResponse, send_local_notifs};
|
||||
use lemmy_apub::fetcher::person::get_or_fetch_and_upsert_person;
|
||||
use lemmy_db_queries::Crud;
|
||||
use lemmy_db_schema::{
|
||||
source::{comment::Comment, post::Post},
|
||||
CommentId,
|
||||
LocalUserId,
|
||||
};
|
||||
use lemmy_db_views::comment_view::CommentView;
|
||||
use lemmy_utils::{utils::scrape_text_for_mentions, LemmyError};
|
||||
use lemmy_websocket::{messages::SendComment, LemmyContext};
|
||||
use url::Url;
|
||||
|
||||
pub mod create;
|
||||
pub mod delete;
|
||||
pub mod dislike;
|
||||
pub mod like;
|
||||
pub mod remove;
|
||||
pub mod update;
|
||||
|
||||
async fn get_notif_recipients(
|
||||
actor: &Url,
|
||||
comment: &Comment,
|
||||
context: &LemmyContext,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<Vec<LocalUserId>, LemmyError> {
|
||||
let post_id = comment.post_id;
|
||||
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
||||
let actor = get_or_fetch_and_upsert_person(actor, context, request_counter).await?;
|
||||
|
||||
// Note:
|
||||
// Although mentions could be gotten from the post tags (they are included there), or the ccs,
|
||||
// Its much easier to scrape them from the comment body, since the API has to do that
|
||||
// anyway.
|
||||
let mentions = scrape_text_for_mentions(&comment.content);
|
||||
send_local_notifs(mentions, comment.clone(), actor, post, context.pool(), true).await
|
||||
}
|
||||
|
||||
async fn send_websocket_message<OP: ToString + Send + lemmy_websocket::OperationType + 'static>(
|
||||
comment_id: CommentId,
|
||||
recipient_ids: Vec<LocalUserId>,
|
||||
op: OP,
|
||||
context: &LemmyContext,
|
||||
) -> Result<(), LemmyError> {
|
||||
// Refetch the view
|
||||
let comment_view = blocking(context.pool(), move |conn| {
|
||||
CommentView::read(conn, comment_id, None)
|
||||
})
|
||||
.await??;
|
||||
|
||||
let res = CommentResponse {
|
||||
comment_view,
|
||||
recipient_ids,
|
||||
form_id: None,
|
||||
};
|
||||
|
||||
context.chat_server().do_send(SendComment {
|
||||
op,
|
||||
comment: res,
|
||||
websocket_id: None,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
47
crates/apub_receive/src/activities_new/comment/remove.rs
Normal file
47
crates/apub_receive/src/activities_new/comment/remove.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
use crate::{activities_new::comment::send_websocket_message, inbox::new_inbox_routing::Activity};
|
||||
use activitystreams::activity::kind::RemoveType;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub::fetcher::objects::get_or_fetch_and_insert_comment;
|
||||
use lemmy_apub_lib::{PublicUrl, ReceiveActivity};
|
||||
use lemmy_db_queries::source::comment::Comment_;
|
||||
use lemmy_db_schema::source::comment::Comment;
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RemoveComment {
|
||||
actor: Url,
|
||||
to: PublicUrl,
|
||||
object: Url,
|
||||
cc: Vec<Url>,
|
||||
#[serde(rename = "type")]
|
||||
kind: RemoveType,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl ReceiveActivity for Activity<RemoveComment> {
|
||||
async fn receive(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError> {
|
||||
let comment =
|
||||
get_or_fetch_and_insert_comment(&self.inner.object, context, request_counter).await?;
|
||||
|
||||
let removed_comment = blocking(context.pool(), move |conn| {
|
||||
Comment::update_removed(conn, comment.id, true)
|
||||
})
|
||||
.await??;
|
||||
|
||||
// TODO get those recipient actor ids from somewhere
|
||||
send_websocket_message(
|
||||
removed_comment.id,
|
||||
vec![],
|
||||
UserOperationCrud::EditComment,
|
||||
context,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
56
crates/apub_receive/src/activities_new/comment/update.rs
Normal file
56
crates/apub_receive/src/activities_new/comment/update.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
use crate::{
|
||||
activities_new::comment::{get_notif_recipients, send_websocket_message},
|
||||
inbox::new_inbox_routing::Activity,
|
||||
};
|
||||
use activitystreams::{activity::kind::UpdateType, base::BaseExt};
|
||||
use anyhow::Context;
|
||||
use lemmy_apub::{objects::FromApub, NoteExt};
|
||||
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity};
|
||||
use lemmy_db_schema::source::comment::Comment;
|
||||
use lemmy_utils::{location_info, LemmyError};
|
||||
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UpdateComment {
|
||||
actor: Url,
|
||||
to: PublicUrl,
|
||||
object: NoteExt,
|
||||
#[serde(rename = "type")]
|
||||
kind: UpdateType,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl ReceiveActivity for Activity<UpdateComment> {
|
||||
async fn receive(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError> {
|
||||
verify_domains_match(&self.inner.actor, self.id_unchecked())?;
|
||||
verify_domains_match(
|
||||
&self.inner.actor,
|
||||
self.inner.object.id_unchecked().context(location_info!())?,
|
||||
)?;
|
||||
|
||||
let comment = Comment::from_apub(
|
||||
&self.inner.object,
|
||||
context,
|
||||
self.inner.actor.clone(),
|
||||
request_counter,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let recipients =
|
||||
get_notif_recipients(&self.inner.actor, &comment, context, request_counter).await?;
|
||||
send_websocket_message(
|
||||
comment.id,
|
||||
recipients,
|
||||
UserOperationCrud::EditComment,
|
||||
context,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ use lemmy_apub::{objects::FromApub, NoteExt};
|
|||
use lemmy_apub_lib::{verify_domains_match, ReceiveActivity};
|
||||
use lemmy_db_schema::source::private_message::PrivateMessage;
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
|
@ -38,7 +38,12 @@ impl ReceiveActivity for Activity<CreatePrivateMessage> {
|
|||
)
|
||||
.await?;
|
||||
|
||||
send_websocket_message(private_message.id, context).await?;
|
||||
send_websocket_message(
|
||||
private_message.id,
|
||||
UserOperationCrud::CreatePrivateMessage,
|
||||
context,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use lemmy_apub_lib::{verify_domains_match, ReceiveActivity};
|
|||
use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject};
|
||||
use lemmy_db_schema::source::private_message::PrivateMessage;
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
|
@ -41,7 +41,12 @@ impl ReceiveActivity for Activity<DeletePrivateMessage> {
|
|||
})
|
||||
.await??;
|
||||
|
||||
send_websocket_message(deleted_private_message.id, context).await?;
|
||||
send_websocket_message(
|
||||
deleted_private_message.id,
|
||||
UserOperationCrud::DeletePrivateMessage,
|
||||
context,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ pub mod update;
|
|||
|
||||
async fn send_websocket_message(
|
||||
private_message_id: PrivateMessageId,
|
||||
op: UserOperationCrud,
|
||||
context: &LemmyContext,
|
||||
) -> Result<(), LemmyError> {
|
||||
let message = blocking(&context.pool(), move |conn| {
|
||||
|
@ -31,7 +32,7 @@ async fn send_websocket_message(
|
|||
.id;
|
||||
|
||||
context.chat_server().do_send(SendUserRoomMessage {
|
||||
op: UserOperationCrud::CreatePrivateMessage,
|
||||
op,
|
||||
response: res,
|
||||
local_recipient_id,
|
||||
websocket_id: None,
|
||||
|
|
|
@ -8,7 +8,7 @@ use lemmy_apub_lib::{verify_domains_match, ReceiveActivity};
|
|||
use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject};
|
||||
use lemmy_db_schema::source::private_message::PrivateMessage;
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
|
@ -43,7 +43,12 @@ impl ReceiveActivity for Activity<UndoDeletePrivateMessage> {
|
|||
})
|
||||
.await??;
|
||||
|
||||
send_websocket_message(deleted_private_message.id, context).await?;
|
||||
send_websocket_message(
|
||||
deleted_private_message.id,
|
||||
UserOperationCrud::EditPrivateMessage,
|
||||
context,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use lemmy_apub::{objects::FromApub, NoteExt};
|
|||
use lemmy_apub_lib::{verify_domains_match, ReceiveActivity};
|
||||
use lemmy_db_schema::source::private_message::PrivateMessage;
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
|
@ -38,7 +38,12 @@ impl ReceiveActivity for Activity<UpdatePrivateMessage> {
|
|||
)
|
||||
.await?;
|
||||
|
||||
send_websocket_message(private_message.id, context).await?;
|
||||
send_websocket_message(
|
||||
private_message.id,
|
||||
UserOperationCrud::EditPrivateMessage,
|
||||
context,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
use crate::activities_new::{
|
||||
comment::create::CreateComment,
|
||||
comment::{
|
||||
create::CreateComment,
|
||||
delete::DeleteComment,
|
||||
dislike::DislikeComment,
|
||||
like::LikeComment,
|
||||
remove::RemoveComment,
|
||||
update::UpdateComment,
|
||||
},
|
||||
follow::AcceptFollowCommunity,
|
||||
private_message::{
|
||||
create::CreatePrivateMessage,
|
||||
|
@ -14,6 +21,9 @@ use lemmy_utils::LemmyError;
|
|||
use lemmy_websocket::LemmyContext;
|
||||
use url::Url;
|
||||
|
||||
// TODO: add security checks for received activities back in
|
||||
// mainly check that domain of actor and id are identical (and object/object.id where applicable)
|
||||
|
||||
// TODO: would be nice if we could move this to lemmy_apub_lib crate. doing that gives error:
|
||||
// "only traits defined in the current crate can be implemented for arbitrary types"
|
||||
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
|
||||
|
@ -28,7 +38,6 @@ pub struct Activity<Kind> {
|
|||
pub inner: Kind,
|
||||
|
||||
// unparsed fields
|
||||
// todo: can probably remove this field
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -47,6 +56,11 @@ pub enum PersonAcceptedActivitiesNew {
|
|||
DeletePrivateMessage(DeletePrivateMessage),
|
||||
UndoDeletePrivateMessage(UndoDeletePrivateMessage),
|
||||
CreateComment(CreateComment),
|
||||
UpdateComment(UpdateComment),
|
||||
LikeComment(LikeComment),
|
||||
DislikeComment(DislikeComment),
|
||||
DeleteComment(DeleteComment),
|
||||
RemoveComment(RemoveComment),
|
||||
}
|
||||
|
||||
// todo: can probably get rid of this?
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::{
|
||||
activities::receive::{
|
||||
comment::receive_update_comment,
|
||||
community::{
|
||||
receive_delete_community,
|
||||
receive_remove_community,
|
||||
|
@ -30,7 +29,7 @@ use crate::{
|
|||
},
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::{ActorAndObject, Announce, Delete, Remove, Undo, Update},
|
||||
activity::{ActorAndObject, Announce, Delete, Remove, Undo},
|
||||
base::AnyBase,
|
||||
prelude::*,
|
||||
};
|
||||
|
@ -145,15 +144,7 @@ pub(crate) async fn person_receive_message(
|
|||
Box::pin(receive_announce(&context, any_base, actor, request_counter)).await?
|
||||
}
|
||||
PersonValidTypes::Create => {}
|
||||
PersonValidTypes::Update => {
|
||||
Box::pin(receive_update(
|
||||
&context,
|
||||
any_base,
|
||||
actor_url,
|
||||
request_counter,
|
||||
))
|
||||
.await?
|
||||
}
|
||||
PersonValidTypes::Update => {}
|
||||
PersonValidTypes::Delete => {
|
||||
Box::pin(receive_delete(
|
||||
context,
|
||||
|
@ -304,23 +295,6 @@ pub async fn receive_announce(
|
|||
}
|
||||
}
|
||||
|
||||
/// Receive either an updated private message, or an updated comment mention. We distinguish
|
||||
/// them by checking whether the activity is public.
|
||||
async fn receive_update(
|
||||
context: &LemmyContext,
|
||||
activity: AnyBase,
|
||||
expected_domain: Url,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError> {
|
||||
let update = Update::from_any_base(activity)?.context(location_info!())?;
|
||||
verify_activity_domains_valid(&update, &expected_domain, true)?;
|
||||
if verify_is_addressed_to_public(&update).is_ok() {
|
||||
receive_update_comment(update, context, request_counter).await
|
||||
} else {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
async fn receive_delete(
|
||||
context: &LemmyContext,
|
||||
any_base: AnyBase,
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
use crate::{
|
||||
activities::receive::{
|
||||
comment::{
|
||||
receive_delete_comment,
|
||||
receive_dislike_comment,
|
||||
receive_like_comment,
|
||||
receive_remove_comment,
|
||||
receive_update_comment,
|
||||
},
|
||||
comment_undo::{
|
||||
receive_undo_delete_comment,
|
||||
receive_undo_dislike_comment,
|
||||
|
@ -162,7 +155,7 @@ pub(in crate::inbox) async fn receive_update_for_community(
|
|||
Some(ObjectTypes::Page) => {
|
||||
receive_update_post(update, announce, context, request_counter).await
|
||||
}
|
||||
Some(ObjectTypes::Note) => receive_update_comment(update, context, request_counter).await,
|
||||
Some(ObjectTypes::Note) => todo!(),
|
||||
Some(ObjectTypes::Group) => {
|
||||
receive_remote_mod_update_community(update, context, request_counter).await
|
||||
}
|
||||
|
@ -187,8 +180,8 @@ pub(in crate::inbox) async fn receive_like_for_community(
|
|||
.context(location_info!())?;
|
||||
match fetch_post_or_comment_by_id(&object_id, context, request_counter).await? {
|
||||
PostOrComment::Post(post) => receive_like_post(like, *post, context, request_counter).await,
|
||||
PostOrComment::Comment(comment) => {
|
||||
receive_like_comment(like, *comment, context, request_counter).await
|
||||
PostOrComment::Comment(_) => {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,8 +213,8 @@ pub(in crate::inbox) async fn receive_dislike_for_community(
|
|||
PostOrComment::Post(post) => {
|
||||
receive_dislike_post(dislike, *post, context, request_counter).await
|
||||
}
|
||||
PostOrComment::Comment(comment) => {
|
||||
receive_dislike_comment(dislike, *comment, context, request_counter).await
|
||||
PostOrComment::Comment(_) => {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -250,9 +243,9 @@ pub(in crate::inbox) async fn receive_delete_for_community(
|
|||
verify_activity_domains_valid(&delete, &expected_domain, true)?;
|
||||
receive_delete_post(context, *p).await
|
||||
}
|
||||
Ok(Object::Comment(c)) => {
|
||||
Ok(Object::Comment(_)) => {
|
||||
verify_activity_domains_valid(&delete, &expected_domain, true)?;
|
||||
receive_delete_comment(context, *c).await
|
||||
todo!()
|
||||
}
|
||||
Ok(Object::Community(c)) => {
|
||||
receive_remote_mod_delete_community(delete, *c, context, request_counter).await
|
||||
|
@ -309,7 +302,7 @@ pub(in crate::inbox) async fn receive_remove_for_community(
|
|||
|
||||
match find_post_or_comment_by_id(context, object).await {
|
||||
Ok(PostOrComment::Post(p)) => receive_remove_post(context, *p).await,
|
||||
Ok(PostOrComment::Comment(c)) => receive_remove_comment(context, *c).await,
|
||||
Ok(PostOrComment::Comment(_)) => todo!(),
|
||||
// if we dont have the object, no need to do anything
|
||||
Err(_) => Ok(()),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue