mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-25 10:51:03 +00:00
stuff
This commit is contained in:
parent
ce013f9904
commit
ae78eaa3b1
3 changed files with 45 additions and 47 deletions
|
@ -152,16 +152,7 @@ test("Only followers can view and interact with private community content", asyn
|
|||
follow: true,
|
||||
};
|
||||
await user.followCommunity(follow_form);
|
||||
const pendingFollows1 = await waitUntil(
|
||||
() => listCommunityPendingFollows(alpha),
|
||||
f => f.items.length == 1,
|
||||
);
|
||||
const approve = await approveCommunityPendingFollow(
|
||||
alpha,
|
||||
alphaCommunityId,
|
||||
pendingFollows1.items[0].person.id,
|
||||
);
|
||||
expect(approve.success).toBe(true);
|
||||
approveFollower(alpha, alphaCommunityId);
|
||||
|
||||
// now user can fetch posts and comments in community (using signed fetch), and create posts
|
||||
await waitUntil(
|
||||
|
@ -283,7 +274,7 @@ test("Follow a private community and receive activities", async () => {
|
|||
);
|
||||
});
|
||||
|
||||
test("Fetch remote content in private community", async () => {
|
||||
test.only("Fetch remote content in private community", async () => {
|
||||
// create private community
|
||||
const community = await createCommunity(alpha, randomString(10), "Private");
|
||||
expect(community.community_view.community.visibility).toBe("Private");
|
||||
|
@ -297,6 +288,7 @@ test("Fetch remote content in private community", async () => {
|
|||
follow: true,
|
||||
};
|
||||
await beta.followCommunity(follow_form_beta);
|
||||
await approveFollower(alpha, alphaCommunityId);
|
||||
|
||||
// beta creates post and comment
|
||||
const post = await createPost(beta, betaCommunityId);
|
||||
|
@ -306,40 +298,35 @@ test("Fetch remote content in private community", async () => {
|
|||
const comment_id = comment.comment_view.comment.id;
|
||||
expect(comment_id).toBeDefined();
|
||||
|
||||
// gamma is not following the community and cannot view nor create posts
|
||||
const user = await registerUser(gamma, betaUrl);
|
||||
// create gamma user and follow community
|
||||
const gammaCommunityId = (
|
||||
await resolveCommunity(user, community.community_view.community.actor_id)
|
||||
await resolveCommunity(gamma, community.community_view.community.actor_id)
|
||||
).community!.community.id;
|
||||
|
||||
// follow the community and approve
|
||||
const follow_form: FollowCommunity = {
|
||||
community_id: gammaCommunityId,
|
||||
follow: true,
|
||||
};
|
||||
await user.followCommunity(follow_form);
|
||||
const pendingFollows1 = await waitUntil(
|
||||
() => listCommunityPendingFollows(alpha),
|
||||
f => f.items.length == 1,
|
||||
);
|
||||
const approve = await approveCommunityPendingFollow(
|
||||
alpha,
|
||||
alphaCommunityId,
|
||||
pendingFollows1.items[0].person.id,
|
||||
);
|
||||
expect(approve.success).toBe(true);
|
||||
await gamma.followCommunity(follow_form);
|
||||
await approveFollower(alpha, alphaCommunityId);
|
||||
|
||||
// now user can fetch posts and comments in community (using signed fetch), and create posts
|
||||
console.log(1);
|
||||
await waitUntil(
|
||||
() => resolvePost(user, post.post_view.post),
|
||||
let resolvedPost = await waitUntil(
|
||||
() => resolvePost(gamma, post.post_view.post),
|
||||
p => p?.post?.post.id != undefined,
|
||||
);
|
||||
console.log(2);
|
||||
console.log(post.post_view.post);
|
||||
console.log(resolvedPost.post?.post);
|
||||
expect(resolvedPost.post?.post.ap_id).toBe(post.post_view.post.ap_id);
|
||||
const resolvedComment = (
|
||||
await resolveComment(user, comment.comment_view.comment)
|
||||
await resolveComment(gamma, comment.comment_view.comment)
|
||||
).comment;
|
||||
expect(resolvedComment?.comment.id).toBeDefined();
|
||||
expect(resolvedComment?.comment.ap_id).toBe(
|
||||
comment.comment_view.comment.ap_id,
|
||||
);
|
||||
|
||||
// TODO: this test should fail as check_has_followers_from_instance() on beta returns errors
|
||||
// because it doesnt know the community follower. yet for some reason the test passes???
|
||||
fail();
|
||||
});
|
||||
|
||||
async function approveFollower(user: LemmyHttp, community_id: number) {
|
||||
|
|
|
@ -17,8 +17,10 @@ use lemmy_db_schema::{
|
|||
actor_language::CommunityLanguage,
|
||||
comment::Comment,
|
||||
comment_reply::{CommentReply, CommentReplyInsertForm},
|
||||
community::Community,
|
||||
person::Person,
|
||||
person_mention::{PersonMention, PersonMentionInsertForm},
|
||||
post::Post,
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
|
@ -101,17 +103,28 @@ pub async fn send_local_notifs(
|
|||
let mut recipient_ids = Vec::new();
|
||||
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
|
||||
|
||||
// let person = my_local_user.person;
|
||||
// Read the comment view to get extra info
|
||||
// When called from api code, we have local user view and can read with CommentView
|
||||
// to reduce db queries. But when receiving a federated comment the user view is None,
|
||||
// which means that comments inside private communities cant be read. As a workaround
|
||||
// we need to read the items manually to bypass this check.
|
||||
let (comment, post, community) = if let Some(local_user_view) = local_user_view {
|
||||
let comment_view = CommentView::read(
|
||||
&mut context.pool(),
|
||||
comment_id,
|
||||
local_user_view.map(|view| &view.local_user),
|
||||
Some(&local_user_view.local_user),
|
||||
)
|
||||
.await?;
|
||||
let comment = comment_view.comment;
|
||||
let post = comment_view.post;
|
||||
let community = comment_view.community;
|
||||
(
|
||||
comment_view.comment,
|
||||
comment_view.post,
|
||||
comment_view.community,
|
||||
)
|
||||
} else {
|
||||
let comment = Comment::read(&mut context.pool(), comment_id).await?;
|
||||
let post = Post::read(&mut context.pool(), comment.post_id).await?;
|
||||
let community = Community::read(&mut context.pool(), post.community_id).await?;
|
||||
(comment, post, community)
|
||||
};
|
||||
|
||||
// Send the local mentions
|
||||
for mention in mentions
|
||||
|
|
|
@ -174,9 +174,7 @@ impl ActivityHandler for CreateOrUpdateNote {
|
|||
|
||||
// TODO: this fails in local community comment as CommentView::read() returns nothing
|
||||
// without passing LocalUser
|
||||
send_local_notifs(mentions, comment.id, &actor, do_send_email, context, None)
|
||||
.await
|
||||
.ok();
|
||||
send_local_notifs(mentions, comment.id, &actor, do_send_email, context, None).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue