mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-06-02 13:39:21 +00:00
c7de1fcf24
* start to implement apub inbox routing lib * got something that almost works * it compiles! * implemented some more * move library code to separate crate (most of it) * convert private message handlers * convert all comment receivers (except undo comment) * convert post receiver * add verify trait * convert community receivers * add cc field for all activities which i forgot before * convert inbox functions, add missing checks * convert undo like/dislike receivers * convert undo_delete and undo_remove receivers * move block/unblock activities * convert remaining activity receivers * reimplement http signature verification and other checks * also use actor type for routing, VerifyActivity and SendActivity traits * cleanup and restructure apub_receive code * wip: try to fix activity routing * implement a (very bad) derive macro for activityhandler * working activity routing! * rework pm verify(), fix tests and confirm manually also remove inbox username check which was broken * rework following verify(), fix tests and test manually * fix post/comment create/update, rework voting * Rewrite remove/delete post/comment, fix tests, test manually * Rework and fix (un)block user, announce, update post * some code cleanup * rework delete/remove activity receivers (still quite messy) * rewrite, test and fix add/remove mod, update community handlers * add docs for ActivityHandler derive macro * dont try to compile macro comments
66 lines
2 KiB
Rust
66 lines
2 KiB
Rust
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 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.
|
|
// TODO: for compatibility with other projects, it would be much better to read this from cc or tags
|
|
let mentions = scrape_text_for_mentions(&comment.content);
|
|
send_local_notifs(mentions, comment.clone(), actor, post, context.pool(), true).await
|
|
}
|
|
|
|
// TODO: in many call sites we are setting an empty vec for recipient_ids, we should get the actual
|
|
// recipient actors from somewhere
|
|
pub(crate) 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(())
|
|
}
|