2022-11-02 19:18:22 +00:00
|
|
|
use crate::{
|
2022-11-28 14:29:33 +00:00
|
|
|
activities::community::send_activity_in_community,
|
|
|
|
activity_lists::AnnouncableActivities,
|
|
|
|
fetcher::post_or_comment::PostOrComment,
|
2023-08-01 13:53:36 +00:00
|
|
|
objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
|
2022-11-28 14:29:33 +00:00
|
|
|
protocol::activities::voting::{
|
|
|
|
undo_vote::UndoVote,
|
|
|
|
vote::{Vote, VoteType},
|
|
|
|
},
|
2022-11-02 19:18:22 +00:00
|
|
|
};
|
2023-03-21 15:03:05 +00:00
|
|
|
use activitypub_federation::{config::Data, fetch::object_id::ObjectId};
|
2023-08-01 13:53:36 +00:00
|
|
|
use lemmy_api_common::context::LemmyContext;
|
2021-10-16 13:33:38 +00:00
|
|
|
use lemmy_db_schema::{
|
2023-08-01 13:53:36 +00:00
|
|
|
newtypes::DbUrl,
|
2021-10-16 13:33:38 +00:00
|
|
|
source::{
|
2023-09-09 16:25:03 +00:00
|
|
|
activity::ActivitySendTargets,
|
2021-10-18 21:36:44 +00:00
|
|
|
comment::{CommentLike, CommentLikeForm},
|
2022-11-28 14:29:33 +00:00
|
|
|
community::Community,
|
|
|
|
person::Person,
|
2021-10-18 21:36:44 +00:00
|
|
|
post::{PostLike, PostLikeForm},
|
2021-10-16 13:33:38 +00:00
|
|
|
},
|
2023-08-01 13:53:36 +00:00
|
|
|
traits::Likeable,
|
Apub inbox rewrite (#1652)
* 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
2021-07-17 16:08:46 +00:00
|
|
|
};
|
2024-04-10 14:14:11 +00:00
|
|
|
use lemmy_utils::error::LemmyResult;
|
Apub inbox rewrite (#1652)
* 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
2021-07-17 16:08:46 +00:00
|
|
|
|
2021-08-02 20:33:40 +00:00
|
|
|
pub mod undo_vote;
|
|
|
|
pub mod vote;
|
Apub inbox rewrite (#1652)
* 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
2021-07-17 16:08:46 +00:00
|
|
|
|
2023-08-01 13:53:36 +00:00
|
|
|
pub(crate) async fn send_like_activity(
|
|
|
|
object_id: DbUrl,
|
|
|
|
actor: Person,
|
|
|
|
community: Community,
|
2022-11-28 14:29:33 +00:00
|
|
|
score: i16,
|
2023-08-01 13:53:36 +00:00
|
|
|
context: Data<LemmyContext>,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<()> {
|
2023-11-07 10:03:13 +00:00
|
|
|
let object_id: ObjectId<PostOrComment> = object_id.into();
|
2023-08-01 13:53:36 +00:00
|
|
|
let actor: ApubPerson = actor.into();
|
|
|
|
let community: ApubCommunity = community.into();
|
2022-11-28 14:29:33 +00:00
|
|
|
|
2023-09-09 16:25:03 +00:00
|
|
|
let empty = ActivitySendTargets::empty();
|
2022-11-28 14:29:33 +00:00
|
|
|
// score of 1 means upvote, -1 downvote, 0 undo a previous vote
|
|
|
|
if score != 0 {
|
2023-08-01 13:53:36 +00:00
|
|
|
let vote = Vote::new(object_id, &actor, &community, score.try_into()?, &context)?;
|
2022-11-28 14:29:33 +00:00
|
|
|
let activity = AnnouncableActivities::Vote(vote);
|
2023-09-09 16:25:03 +00:00
|
|
|
send_activity_in_community(activity, &actor, &community, empty, false, &context).await
|
2022-11-28 14:29:33 +00:00
|
|
|
} else {
|
|
|
|
// Lemmy API doesnt distinguish between Undo/Like and Undo/Dislike, so we hardcode it here.
|
2023-08-01 13:53:36 +00:00
|
|
|
let vote = Vote::new(object_id, &actor, &community, VoteType::Like, &context)?;
|
|
|
|
let undo_vote = UndoVote::new(vote, &actor, &community, &context)?;
|
2022-11-28 14:29:33 +00:00
|
|
|
let activity = AnnouncableActivities::UndoVote(undo_vote);
|
2023-09-09 16:25:03 +00:00
|
|
|
send_activity_in_community(activity, &actor, &community, empty, false, &context).await
|
2022-11-28 14:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2021-08-02 20:33:40 +00:00
|
|
|
async fn vote_comment(
|
|
|
|
vote_type: &VoteType,
|
2021-10-18 21:36:44 +00:00
|
|
|
actor: ApubPerson,
|
|
|
|
comment: &ApubComment,
|
2023-03-21 15:03:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<()> {
|
Apub inbox rewrite (#1652)
* 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
2021-07-17 16:08:46 +00:00
|
|
|
let comment_id = comment.id;
|
|
|
|
let like_form = CommentLikeForm {
|
|
|
|
comment_id,
|
|
|
|
post_id: comment.post_id,
|
|
|
|
person_id: actor.id,
|
2021-08-02 20:33:40 +00:00
|
|
|
score: vote_type.into(),
|
Apub inbox rewrite (#1652)
* 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
2021-07-17 16:08:46 +00:00
|
|
|
};
|
|
|
|
let person_id = actor.id;
|
2023-07-11 13:09:59 +00:00
|
|
|
CommentLike::remove(&mut context.pool(), person_id, comment_id).await?;
|
|
|
|
CommentLike::like(&mut context.pool(), &like_form).await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
Ok(())
|
Apub inbox rewrite (#1652)
* 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
2021-07-17 16:08:46 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2021-08-02 20:33:40 +00:00
|
|
|
async fn vote_post(
|
|
|
|
vote_type: &VoteType,
|
2021-10-18 21:36:44 +00:00
|
|
|
actor: ApubPerson,
|
|
|
|
post: &ApubPost,
|
2023-03-21 15:03:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<()> {
|
Apub inbox rewrite (#1652)
* 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
2021-07-17 16:08:46 +00:00
|
|
|
let post_id = post.id;
|
|
|
|
let like_form = PostLikeForm {
|
|
|
|
post_id: post.id,
|
|
|
|
person_id: actor.id,
|
2021-08-02 20:33:40 +00:00
|
|
|
score: vote_type.into(),
|
Apub inbox rewrite (#1652)
* 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
2021-07-17 16:08:46 +00:00
|
|
|
};
|
|
|
|
let person_id = actor.id;
|
2023-07-11 13:09:59 +00:00
|
|
|
PostLike::remove(&mut context.pool(), person_id, post_id).await?;
|
|
|
|
PostLike::like(&mut context.pool(), &like_form).await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
Ok(())
|
Apub inbox rewrite (#1652)
* 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
2021-07-17 16:08:46 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2021-08-02 20:33:40 +00:00
|
|
|
async fn undo_vote_comment(
|
2021-10-18 21:36:44 +00:00
|
|
|
actor: ApubPerson,
|
|
|
|
comment: &ApubComment,
|
2023-03-21 15:03:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<()> {
|
Apub inbox rewrite (#1652)
* 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
2021-07-17 16:08:46 +00:00
|
|
|
let comment_id = comment.id;
|
|
|
|
let person_id = actor.id;
|
2023-07-11 13:09:59 +00:00
|
|
|
CommentLike::remove(&mut context.pool(), person_id, comment_id).await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
Ok(())
|
Apub inbox rewrite (#1652)
* 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
2021-07-17 16:08:46 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2021-08-02 20:33:40 +00:00
|
|
|
async fn undo_vote_post(
|
2021-10-18 21:36:44 +00:00
|
|
|
actor: ApubPerson,
|
|
|
|
post: &ApubPost,
|
2023-03-21 15:03:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<()> {
|
Apub inbox rewrite (#1652)
* 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
2021-07-17 16:08:46 +00:00
|
|
|
let post_id = post.id;
|
|
|
|
let person_id = actor.id;
|
2023-07-11 13:09:59 +00:00
|
|
|
PostLike::remove(&mut context.pool(), person_id, post_id).await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
Ok(())
|
Apub inbox rewrite (#1652)
* 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
2021-07-17 16:08:46 +00:00
|
|
|
}
|