mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-09-04 12:14:31 +00:00
Better way to check if we should accept activity in remote community (#5823)
* Better way to check if we should accept activity in remote community (fixes #5596) * fix test
This commit is contained in:
parent
a6b03fabdb
commit
35f48c5a95
4 changed files with 21 additions and 12 deletions
|
@ -122,10 +122,8 @@ test("Delete user", async () => {
|
|||
(await getComments(alpha, localComment.post_id)).comments[0].comment
|
||||
.deleted,
|
||||
).toBe(true);
|
||||
expect(
|
||||
(await getComments(alpha, remoteComment.post_id)).comments[0].comment
|
||||
.deleted,
|
||||
).toBe(true);
|
||||
let comment = await alpha.getComment({ id: remoteComment.id });
|
||||
expect(comment.comment_view.comment.deleted).toBe(true);
|
||||
await expect(
|
||||
getPersonDetails(user, remoteComment.creator_id),
|
||||
).rejects.toStrictEqual(new LemmyError("not_found"));
|
||||
|
|
|
@ -18,7 +18,7 @@ async fn community_use_pending(community: &Community, context: &LemmyContext) ->
|
|||
if community.local {
|
||||
return false;
|
||||
}
|
||||
CommunityActions::check_has_local_followers(&mut context.pool(), community.id)
|
||||
CommunityActions::check_accept_activity_in_community(&mut context.pool(), community.id)
|
||||
.await
|
||||
.is_ok()
|
||||
}
|
||||
|
|
|
@ -204,7 +204,8 @@ async fn can_accept_activity_in_community(
|
|||
return Err(LemmyErrorType::NotFound.into());
|
||||
}
|
||||
if !community.local {
|
||||
CommunityActions::check_has_local_followers(&mut context.pool(), community.id).await?
|
||||
CommunityActions::check_accept_activity_in_community(&mut context.pool(), community.id)
|
||||
.await?
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -38,7 +38,7 @@ use diesel::{
|
|||
use diesel_async::RunQueryDsl;
|
||||
use lemmy_db_schema_file::{
|
||||
enums::{CommunityFollowerState, CommunityVisibility, ListingType},
|
||||
schema::{community, community_actions, instance, post},
|
||||
schema::{comment, community, community_actions, instance, post},
|
||||
};
|
||||
use lemmy_utils::{
|
||||
error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult},
|
||||
|
@ -381,17 +381,27 @@ impl CommunityActions {
|
|||
}
|
||||
}
|
||||
|
||||
/// Check if a remote instance has any followers on local instance. For this it is enough to check
|
||||
/// if any follow relation is stored. Dont use this for local community.
|
||||
pub async fn check_has_local_followers(
|
||||
/// Check if we should accept activity in remote community. This requires either:
|
||||
/// - Local follower of the community
|
||||
/// - Local post or comment in the community
|
||||
///
|
||||
/// Dont use this check for local communities.
|
||||
pub async fn check_accept_activity_in_community(
|
||||
pool: &mut DbPool<'_>,
|
||||
remote_community_id: CommunityId,
|
||||
) -> LemmyResult<()> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
let find_action = community_actions::table
|
||||
let follow_action = community_actions::table
|
||||
.filter(community_actions::followed_at.is_not_null())
|
||||
.filter(community_actions::community_id.eq(remote_community_id));
|
||||
select(exists(find_action))
|
||||
let local_post = post::table
|
||||
.filter(post::community_id.eq(remote_community_id))
|
||||
.filter(post::local);
|
||||
let local_comment = comment::table
|
||||
.inner_join(post::table)
|
||||
.filter(post::community_id.eq(remote_community_id))
|
||||
.filter(comment::local);
|
||||
select(exists(follow_action).or(exists(local_post).or(exists(local_comment))))
|
||||
.get_result::<bool>(conn)
|
||||
.await?
|
||||
.then_some(())
|
||||
|
|
Loading…
Reference in a new issue