banUserFromSite,
searchPostLocal,
banUserFromCommunity,
+ followCommunity,
} from './shared';
import { PostView, CommunityView } from 'lemmy-js-client';
});
test('Lock a post', async () => {
+ await followCommunity(alpha, true, betaCommunity.community.id);
let postRes = await createPost(alpha, betaCommunity.community.id);
// Lock the post
- let lockedPostRes = await lockPost(alpha, true, postRes.post_view.post);
+ let searchBeta = await searchPost(beta, postRes.post_view.post);
+ let betaPost1 = searchBeta.posts[0];
+ let lockedPostRes = await lockPost(beta, true, betaPost1.post);
expect(lockedPostRes.post_view.post.locked).toBe(true);
- // Make sure that post is locked on beta
- let searchBeta = await searchPostLocal(beta, postRes.post_view.post);
- let betaPost1 = searchBeta.posts[0];
- expect(betaPost1.post.locked).toBe(true);
+ // Make sure that post is locked on alpha
+ let searchAlpha = await searchPostLocal(alpha, postRes.post_view.post);
+ let alphaPost1 = searchAlpha.posts[0];
+ expect(alphaPost1.post.locked).toBe(true);
// Try to make a new comment there, on alpha
- let comment: any = await createComment(alpha, postRes.post_view.post.id);
+ let comment: any = await createComment(alpha, alphaPost1.post.id);
expect(comment['error']).toBe('locked');
// Unlock a post
- let unlockedPost = await lockPost(alpha, false, postRes.post_view.post);
+ let unlockedPost = await lockPost(beta, false, betaPost1.post);
expect(unlockedPost.post_view.post.locked).toBe(false);
- // Make sure that post is unlocked on beta
- let searchBeta2 = await searchPost(beta, postRes.post_view.post);
- let betaPost2 = searchBeta2.posts[0];
- expect(betaPost2.community.local).toBe(true);
- expect(betaPost2.creator.local).toBe(false);
- expect(betaPost2.post.locked).toBe(false);
+ // Make sure that post is unlocked on alpha
+ let searchAlpha2 = await searchPostLocal(alpha, postRes.post_view.post);
+ let alphaPost2 = searchAlpha2.posts[0];
+ expect(alphaPost2.community.local).toBe(false);
+ expect(alphaPost2.creator.local).toBe(true);
+ expect(alphaPost2.post.locked).toBe(false);
- // Try to create a new comment, on beta
- let commentBeta = await createComment(beta, betaPost2.post.id);
- expect(commentBeta).toBeDefined();
+ // Try to create a new comment, on alpha
+ let commentAlpha = await createComment(alpha, alphaPost1.post.id);
+ expect(commentAlpha).toBeDefined();
});
test('Delete a post', async () => {
// If sticked or locked state was changed, make sure the actor is a mod
let stickied = page.ext_one.stickied.context(location_info!())?;
let locked = !page.ext_one.comments_enabled.context(location_info!())?;
- let mut is_mod_action = false;
+ let mut mod_action_allowed = false;
if stickied != old_post.stickied || locked != old_post.locked {
let community = blocking(context.pool(), move |conn| {
Community::read(conn, old_post.community_id)
})
.await??;
- verify_mod_activity(&update, announce, &community, context).await?;
- is_mod_action = true;
+ // Only check mod status if the community is local, otherwise we trust that it was sent correctly.
+ if community.local {
+ verify_mod_activity(&update, announce, &community, context).await?;
+ }
+ mod_action_allowed = true;
}
let post = Post::from_apub(
context,
user.actor_id(),
request_counter,
- is_mod_action,
+ mod_action_allowed,
)
.await?;
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(AnnounceType::Announce)?)
.set_to(public())
- .set_many_ccs(vec![self.actor_id()]);
+ .set_many_ccs(vec![self.followers_url.clone().into_inner()]);
send_to_community_followers(announce, self, context).await?;
use crate::{
activities::receive::{
+ comment::{receive_create_comment, receive_update_comment},
community::{
receive_delete_community,
receive_remove_community,
}
}
+/// Receive either a new private message, or a new comment mention. We distinguish them by checking
+/// whether the activity is public.
async fn receive_create(
context: &LemmyContext,
activity: AnyBase,
) -> Result<(), LemmyError> {
let create = Create::from_any_base(activity)?.context(location_info!())?;
verify_activity_domains_valid(&create, &expected_domain, true)?;
- receive_create_private_message(&context, create, expected_domain, request_counter).await
+ if verify_is_addressed_to_public(&create).is_ok() {
+ receive_create_comment(create, context, request_counter).await
+ } else {
+ receive_create_private_message(&context, create, expected_domain, request_counter).await
+ }
}
+/// 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,
) -> Result<(), LemmyError> {
let update = Update::from_any_base(activity)?.context(location_info!())?;
verify_activity_domains_valid(&update, &expected_domain, true)?;
- receive_update_private_message(&context, update, expected_domain, request_counter).await
+ if verify_is_addressed_to_public(&update).is_ok() {
+ receive_update_comment(update, context, request_counter).await
+ } else {
+ receive_update_private_message(&context, update, expected_domain, request_counter).await
+ }
}
async fn receive_delete(
context: &LemmyContext,
expected_domain: Url,
request_counter: &mut i32,
- is_mod_action: bool,
+ mod_action_allowed: bool,
) -> Result<Comment, LemmyError> {
let comment: Comment = get_object_from_apub(
note,
context,
expected_domain,
request_counter,
- is_mod_action,
+ mod_action_allowed,
)
.await?;
context: &LemmyContext,
expected_domain: Url,
request_counter: &mut i32,
- _is_mod_action: bool,
+ _mod_action_allowed: bool,
) -> Result<CommentForm, LemmyError> {
let creator_actor_id = ¬e
.attributed_to()
context: &LemmyContext,
expected_domain: Url,
request_counter: &mut i32,
- is_mod_action: bool,
+ mod_action_allowed: bool,
) -> Result<Community, LemmyError> {
let community: Community = get_object_from_apub(
group,
context,
expected_domain,
request_counter,
- is_mod_action,
+ mod_action_allowed,
)
.await?;
context: &LemmyContext,
expected_domain: Url,
request_counter: &mut i32,
- _is_mod_action: bool,
+ _mod_action_allowed: bool,
) -> Result<Self, LemmyError> {
let moderator_uris = fetch_community_mods(context, group, request_counter).await?;
let creator_uri = moderator_uris.first().context(location_info!())?;
/// * `apub` The object to read from
/// * `context` LemmyContext which holds DB pool, HTTP client etc
/// * `expected_domain` Domain where the object was received from. None in case of mod action.
- /// * `is_mod_action` True if the object was sent in a mod activity, ignore `expected_domain` in this case
+ /// * `mod_action_allowed` True if the object can be a mod activity, ignore `expected_domain` in this case
async fn from_apub(
apub: &Self::ApubType,
context: &LemmyContext,
expected_domain: Url,
request_counter: &mut i32,
- is_mod_action: bool,
+ mod_action_allowed: bool,
) -> Result<Self, LemmyError>
where
Self: Sized;
context: &LemmyContext,
expected_domain: Url,
request_counter: &mut i32,
- is_mod_action: bool,
+ mod_action_allowed: bool,
) -> Result<Self, LemmyError>
where
Self: Sized;
context: &LemmyContext,
expected_domain: Url,
request_counter: &mut i32,
- is_mod_action: bool,
+ mod_action_allowed: bool,
) -> Result<Post, LemmyError> {
let post: Post = get_object_from_apub(
page,
context,
expected_domain,
request_counter,
- is_mod_action,
+ mod_action_allowed,
)
.await?;
check_object_for_community_or_site_ban(page, post.community_id, context, request_counter)
context: &LemmyContext,
expected_domain: Url,
request_counter: &mut i32,
- is_mod_action: bool,
+ mod_action_allowed: bool,
) -> Result<PostForm, LemmyError> {
- let ap_id = if is_mod_action {
+ let ap_id = if mod_action_allowed {
let id = page.id_unchecked().context(location_info!())?;
check_is_apub_id_valid(id)?;
id.to_owned().into()
context: &LemmyContext,
expected_domain: Url,
request_counter: &mut i32,
- is_mod_action: bool,
+ mod_action_allowed: bool,
) -> Result<PrivateMessage, LemmyError> {
get_object_from_apub(
note,
context,
expected_domain,
request_counter,
- is_mod_action,
+ mod_action_allowed,
)
.await
}
context: &LemmyContext,
expected_domain: Url,
request_counter: &mut i32,
- _is_mod_action: bool,
+ _mod_action_allowed: bool,
) -> Result<PrivateMessageForm, LemmyError> {
let creator_actor_id = note
.attributed_to()
context: &LemmyContext,
expected_domain: Url,
request_counter: &mut i32,
- is_mod_action: bool,
+ mod_action_allowed: bool,
) -> Result<User_, LemmyError> {
let user_id = person.id_unchecked().context(location_info!())?.to_owned();
let domain = user_id.domain().context(location_info!())?;
context,
expected_domain,
request_counter,
- is_mod_action,
+ mod_action_allowed,
)
.await?;
let user = blocking(context.pool(), move |conn| User_::upsert(conn, &user_form)).await??;
_context: &LemmyContext,
expected_domain: Url,
_request_counter: &mut i32,
- _is_mod_action: bool,
+ _mod_action_allowed: bool,
) -> Result<Self, LemmyError> {
let avatar = match person.icon() {
Some(any_image) => Some(