|
|
|
@ -3,15 +3,12 @@ use crate::{
|
|
|
|
|
activity_queue::send_to_community,
|
|
|
|
|
extensions::context::lemmy_context,
|
|
|
|
|
ActorType,
|
|
|
|
|
ApubLikeableType,
|
|
|
|
|
ApubObjectType,
|
|
|
|
|
};
|
|
|
|
|
use activitystreams::{
|
|
|
|
|
activity::{
|
|
|
|
|
kind::{DeleteType, DislikeType, LikeType, RemoveType, UndoType},
|
|
|
|
|
kind::{DeleteType, RemoveType, UndoType},
|
|
|
|
|
Delete,
|
|
|
|
|
Dislike,
|
|
|
|
|
Like,
|
|
|
|
|
Remove,
|
|
|
|
|
Undo,
|
|
|
|
|
},
|
|
|
|
@ -170,93 +167,3 @@ impl ApubObjectType for Comment {
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
|
impl ApubLikeableType for Comment {
|
|
|
|
|
async fn send_like(&self, creator: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
|
|
|
|
|
let post_id = self.post_id;
|
|
|
|
|
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
|
|
|
|
|
|
|
|
|
let community_id = post.community_id;
|
|
|
|
|
let community = blocking(context.pool(), move |conn| {
|
|
|
|
|
Community::read(conn, community_id)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
|
|
|
|
|
let mut like = Like::new(
|
|
|
|
|
creator.actor_id.to_owned().into_inner(),
|
|
|
|
|
self.ap_id.to_owned().into_inner(),
|
|
|
|
|
);
|
|
|
|
|
like
|
|
|
|
|
.set_many_contexts(lemmy_context())
|
|
|
|
|
.set_id(generate_activity_id(LikeType::Like)?)
|
|
|
|
|
.set_to(public())
|
|
|
|
|
.set_many_ccs(vec![community.actor_id()]);
|
|
|
|
|
|
|
|
|
|
send_to_community(like, creator, &community, None, context).await?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn send_dislike(&self, creator: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
|
|
|
|
|
let post_id = self.post_id;
|
|
|
|
|
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
|
|
|
|
|
|
|
|
|
let community_id = post.community_id;
|
|
|
|
|
let community = blocking(context.pool(), move |conn| {
|
|
|
|
|
Community::read(conn, community_id)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
|
|
|
|
|
let mut dislike = Dislike::new(
|
|
|
|
|
creator.actor_id.to_owned().into_inner(),
|
|
|
|
|
self.ap_id.to_owned().into_inner(),
|
|
|
|
|
);
|
|
|
|
|
dislike
|
|
|
|
|
.set_many_contexts(lemmy_context())
|
|
|
|
|
.set_id(generate_activity_id(DislikeType::Dislike)?)
|
|
|
|
|
.set_to(public())
|
|
|
|
|
.set_many_ccs(vec![community.actor_id()]);
|
|
|
|
|
|
|
|
|
|
send_to_community(dislike, creator, &community, None, context).await?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn send_undo_like(
|
|
|
|
|
&self,
|
|
|
|
|
creator: &Person,
|
|
|
|
|
context: &LemmyContext,
|
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
|
let post_id = self.post_id;
|
|
|
|
|
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
|
|
|
|
|
|
|
|
|
let community_id = post.community_id;
|
|
|
|
|
let community = blocking(context.pool(), move |conn| {
|
|
|
|
|
Community::read(conn, community_id)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
|
|
|
|
|
let mut like = Like::new(
|
|
|
|
|
creator.actor_id.to_owned().into_inner(),
|
|
|
|
|
self.ap_id.to_owned().into_inner(),
|
|
|
|
|
);
|
|
|
|
|
like
|
|
|
|
|
.set_many_contexts(lemmy_context())
|
|
|
|
|
.set_id(generate_activity_id(DislikeType::Dislike)?)
|
|
|
|
|
.set_to(public())
|
|
|
|
|
.set_many_ccs(vec![community.actor_id()]);
|
|
|
|
|
|
|
|
|
|
// Undo that fake activity
|
|
|
|
|
let mut undo = Undo::new(
|
|
|
|
|
creator.actor_id.to_owned().into_inner(),
|
|
|
|
|
like.into_any_base()?,
|
|
|
|
|
);
|
|
|
|
|
undo
|
|
|
|
|
.set_many_contexts(lemmy_context())
|
|
|
|
|
.set_id(generate_activity_id(UndoType::Undo)?)
|
|
|
|
|
.set_to(public())
|
|
|
|
|
.set_many_ccs(vec![community.actor_id()]);
|
|
|
|
|
|
|
|
|
|
send_to_community(undo, creator, &community, None, context).await?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|