"eslint": "^7.30.0",
"eslint-plugin-jane": "^9.0.3",
"jest": "^27.0.6",
- "lemmy-js-client": "0.11.4-rc.9",
+ "lemmy-js-client": "0.11.4-rc.14",
"node-fetch": "^2.6.1",
"prettier": "^2.3.2",
"ts-jest": "^27.0.3",
setupLogins,
createPost,
getPost,
- searchComment,
+ resolveComment,
likeComment,
followBeta,
- searchForBetaCommunity,
+ resolveBetaCommunity,
createComment,
editComment,
deleteComment,
removeComment,
getMentions,
- searchPost,
+ resolvePost,
unfollowRemotes,
createCommunity,
registerUser,
await setupLogins();
await followBeta(alpha);
await followBeta(gamma);
- let search = await searchForBetaCommunity(alpha);
+ let betaCommunity = (await resolveBetaCommunity(alpha)).community;
postRes = await createPost(
alpha,
- search.communities.find(c => c.community.local == false).community.id
+ betaCommunity.community.id
);
});
expect(commentRes.comment_view.counts.score).toBe(1);
// Make sure that comment is liked on beta
- let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
- let betaComment = searchBeta.comments[0];
+ let betaComment = (await resolveComment(beta, commentRes.comment_view.comment)).comment;
expect(betaComment).toBeDefined();
expect(betaComment.community.local).toBe(true);
expect(betaComment.creator.local).toBe(false);
test('Update a comment', async () => {
let commentRes = await createComment(alpha, postRes.post_view.post.id);
// Federate the comment first
- let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
- assertCommentFederation(searchBeta.comments[0], commentRes.comment_view);
+ let betaComment = (await resolveComment(beta, commentRes.comment_view.comment)).comment;
+ assertCommentFederation(betaComment, commentRes.comment_view);
let updateCommentRes = await editComment(
alpha,
expect(updateCommentRes.comment_view.creator.local).toBe(true);
// Make sure that post is updated on beta
- let searchBetaUpdated = await searchComment(
+ let betaCommentUpdated = (await resolveComment(
beta,
commentRes.comment_view.comment
- );
+ )).comment;
assertCommentFederation(
- searchBetaUpdated.comments[0],
+ betaCommentUpdated,
updateCommentRes.comment_view
);
});
expect(deleteCommentRes.comment_view.comment.content).toBe("");
// Make sure that comment is undefined on beta
- let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
- let betaComment = searchBeta.comments[0];
- expect(betaComment).toBeUndefined();
+ let betaCommentRes: any = await resolveComment(beta, commentRes.comment_view.comment);
+ expect(betaCommentRes).toStrictEqual({ error: 'couldnt_find_object' });
let undeleteCommentRes = await deleteComment(
alpha,
expect(undeleteCommentRes.comment_view.comment.deleted).toBe(false);
// Make sure that comment is undeleted on beta
- let searchBeta2 = await searchComment(beta, commentRes.comment_view.comment);
- let betaComment2 = searchBeta2.comments[0];
+ let betaComment2 = (await resolveComment(beta, commentRes.comment_view.comment)).comment;
expect(betaComment2.comment.deleted).toBe(false);
assertCommentFederation(
- searchBeta2.comments[0],
+ betaComment2,
undeleteCommentRes.comment_view
);
});
// Get the id for beta
let betaCommentId = (
- await searchComment(beta, commentRes.comment_view.comment)
- ).comments[0].comment.id;
+ await resolveComment(beta, commentRes.comment_view.comment)
+ ).comment.comment.id;
// The beta admin removes it (the community lives on beta)
let removeCommentRes = await removeComment(beta, true, betaCommentId);
expect(commentRes.comment_view.comment.content).toBeDefined();
// Beta searches that to cache it, then removes it
- let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
- let betaComment = searchBeta.comments[0];
+ let betaComment = (await resolveComment(beta, commentRes.comment_view.comment)).comment;
let removeCommentRes = await removeComment(
beta,
true,
expect(unlike.comment_view.counts.score).toBe(0);
// Make sure that post is unliked on beta
- let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
- let betaComment = searchBeta.comments[0];
+ let betaComment = (await resolveComment(beta, commentRes.comment_view.comment)).comment;
expect(betaComment).toBeDefined();
expect(betaComment.community.local).toBe(true);
expect(betaComment.creator.local).toBe(false);
let commentRes = await createComment(alpha, postRes.post_view.post.id);
// Find the comment on beta
- let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
- let betaComment = searchBeta.comments[0];
+ let betaComment = (await resolveComment(beta, commentRes.comment_view.comment)).comment;
let like = await likeComment(beta, 1, betaComment.comment);
expect(like.comment_view.counts.score).toBe(2);
test('Reply to a comment', async () => {
// Create a comment on alpha, find it on beta
let commentRes = await createComment(alpha, postRes.post_view.post.id);
- let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
- let betaComment = searchBeta.comments[0];
+ let betaComment = (await resolveComment(beta, commentRes.comment_view.comment)).comment;
// find that comment id on beta
test('Comment Search', async () => {
let commentRes = await createComment(alpha, postRes.post_view.post.id);
- let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
- assertCommentFederation(searchBeta.comments[0], commentRes.comment_view);
+ let betaComment = (await resolveComment(beta, commentRes.comment_view.comment)).comment;
+ assertCommentFederation(betaComment, commentRes.comment_view);
});
test('A and G subscribe to B (center) A posts, G mentions B, it gets announced to A', async () => {
expect(alphaPost.post_view.community.local).toBe(true);
// Make sure gamma sees it
- let search = await searchPost(gamma, alphaPost.post_view.post);
- let gammaPost = search.posts[0];
+ let gammaPost = (await resolvePost(gamma, alphaPost.post_view.post)).post;
let commentContent =
'A jest test federated comment announce, lets mention @lemmy_beta@lemmy-beta:8551';
expect(updateRes.comment_view.comment.content).toBe(updatedCommentContent);
// Get the post from alpha
- let search = await searchPost(alpha, postRes.post_view.post);
- let alphaPostB = search.posts[0];
+ let alphaPostB = (await resolvePost(alpha, postRes.post_view.post)).post;
let alphaPost = await getPost(alpha, alphaPostB.post.id);
expect(alphaPost.post_view.post.name).toBeDefined();
alpha,
beta,
setupLogins,
- searchForCommunity,
+ resolveCommunity,
createCommunity,
deleteCommunity,
removeCommunity,
// Cache the community on beta, make sure it has the other fields
let searchShort = `!${prevName}@lemmy-alpha:8541`;
- let search = await searchForCommunity(beta, searchShort);
- let communityOnBeta = search.communities[0];
- assertCommunityFederation(communityOnBeta, communityRes.community_view);
+ let betaCommunity = (await resolveCommunity(beta, searchShort)).community;
+ assertCommunityFederation(betaCommunity, communityRes.community_view);
});
test('Delete community', async () => {
// Cache the community on Alpha
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
- let search = await searchForCommunity(alpha, searchShort);
- let communityOnAlpha = search.communities[0];
- assertCommunityFederation(communityOnAlpha, communityRes.community_view);
+ let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
+ assertCommunityFederation(alphaCommunity, communityRes.community_view);
// Follow the community from alpha
let follow = await followCommunity(
alpha,
true,
- communityOnAlpha.community.id
+ alphaCommunity.community.id
);
// Make sure the follow response went through
// Make sure it got deleted on A
let communityOnAlphaDeleted = await getCommunity(
alpha,
- communityOnAlpha.community.id
+ alphaCommunity.community.id
);
expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
// Make sure it got undeleted on A
let communityOnAlphaUnDeleted = await getCommunity(
alpha,
- communityOnAlpha.community.id
+ alphaCommunity.community.id
);
expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
false
// Cache the community on Alpha
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
- let search = await searchForCommunity(alpha, searchShort);
- let communityOnAlpha = search.communities[0];
- assertCommunityFederation(communityOnAlpha, communityRes.community_view);
+ let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
+ assertCommunityFederation(alphaCommunity, communityRes.community_view);
// Follow the community from alpha
let follow = await followCommunity(
alpha,
true,
- communityOnAlpha.community.id
+ alphaCommunity.community.id
);
// Make sure the follow response went through
// Make sure it got Removed on A
let communityOnAlphaRemoved = await getCommunity(
alpha,
- communityOnAlpha.community.id
+ alphaCommunity.community.id
);
expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
// Make sure it got undeleted on A
let communityOnAlphaUnRemoved = await getCommunity(
alpha,
- communityOnAlpha.community.id
+ alphaCommunity.community.id
);
expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
false
expect(communityRes.community_view.community.name).toBeDefined();
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
- let search = await searchForCommunity(alpha, searchShort);
- let communityOnAlpha = search.communities[0];
- assertCommunityFederation(communityOnAlpha, communityRes.community_view);
+ let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
+ assertCommunityFederation(alphaCommunity, communityRes.community_view);
});
import {
alpha,
setupLogins,
- searchForBetaCommunity,
+ resolveBetaCommunity,
followCommunity,
unfollowRemotes,
getSite,
});
test('Follow federated community', async () => {
- let search = await searchForBetaCommunity(alpha); // TODO sometimes this is returning null?
+ let betaCommunity = (await resolveBetaCommunity(alpha)).community;
let follow = await followCommunity(
alpha,
true,
- search.communities[0].community.id
+ betaCommunity.community.id
);
// Make sure the follow response went through
editPost,
stickyPost,
lockPost,
- searchPost,
+ resolvePost,
likePost,
followBeta,
- searchForBetaCommunity,
+ resolveBetaCommunity,
createComment,
deletePost,
removePost,
getPost,
unfollowRemotes,
- searchForUser,
+ resolvePerson,
banPersonFromSite,
searchPostLocal,
followCommunity,
beforeAll(async () => {
await setupLogins();
- let search = await searchForBetaCommunity(alpha);
- betaCommunity = search.communities[0];
+ betaCommunity = (await resolveBetaCommunity(alpha)).community;
+ expect(betaCommunity).toBeDefined();
await unfollows();
});
expect(postRes.post_view.counts.score).toBe(1);
// Make sure that post is liked on beta
- let searchBeta = await searchPost(beta, postRes.post_view.post);
- let betaPost = searchBeta.posts[0];
+ let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
expect(betaPost).toBeDefined();
expect(betaPost.community.local).toBe(true);
assertPostFederation(betaPost, postRes.post_view);
// Delta only follows beta, so it should not see an alpha ap_id
- let searchDelta = await searchPost(delta, postRes.post_view.post);
- expect(searchDelta.posts[0]).toBeUndefined();
+ let deltaPost = (await resolvePost(delta, postRes.post_view.post)).post;
+ expect(deltaPost).toBeUndefined();
// Epsilon has alpha blocked, it should not see the alpha post
- let searchEpsilon = await searchPost(epsilon, postRes.post_view.post);
- expect(searchEpsilon.posts[0]).toBeUndefined();
+ let epsilonPost = (await resolvePost(epsilon, postRes.post_view.post)).post;
+ expect(epsilonPost).toBeUndefined();
});
test('Create a post in a non-existent community', async () => {
expect(unlike2.post_view.counts.score).toBe(0);
// Make sure that post is unliked on beta
- let searchBeta = await searchPost(beta, postRes.post_view.post);
- let betaPost = searchBeta.posts[0];
+ let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
expect(betaPost).toBeDefined();
expect(betaPost.community.local).toBe(true);
expect(betaPost.creator.local).toBe(false);
expect(updatedPost.post_view.creator.local).toBe(true);
// Make sure that post is updated on beta
- let searchBeta = await searchPost(beta, postRes.post_view.post);
- let betaPost = searchBeta.posts[0];
+ let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
expect(betaPost.community.local).toBe(true);
expect(betaPost.creator.local).toBe(false);
expect(betaPost.post.name).toBe(updatedName);
expect(stickiedPostRes.post_view.post.stickied).toBe(true);
// Make sure that post is stickied on beta
- let searchBeta = await searchPost(beta, postRes.post_view.post);
- let betaPost = searchBeta.posts[0];
+ let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
expect(betaPost.community.local).toBe(true);
expect(betaPost.creator.local).toBe(false);
expect(betaPost.post.stickied).toBe(true);
expect(unstickiedPost.post_view.post.stickied).toBe(false);
// Make sure that post is unstickied on beta
- let searchBeta2 = await searchPost(beta, postRes.post_view.post);
- let betaPost2 = searchBeta2.posts[0];
+ let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post;
expect(betaPost2.community.local).toBe(true);
expect(betaPost2.creator.local).toBe(false);
expect(betaPost2.post.stickied).toBe(false);
// Make sure that gamma cannot sticky the post on beta
- let searchGamma = await searchPost(gamma, postRes.post_view.post);
- let gammaPost = searchGamma.posts[0];
+ let gammaPost = (await resolvePost(gamma, postRes.post_view.post)).post;
let gammaTrySticky = await stickyPost(gamma, true, gammaPost.post);
- let searchBeta3 = await searchPost(beta, postRes.post_view.post);
- let betaPost3 = searchBeta3.posts[0];
+ let betaPost3 = (await resolvePost(beta, postRes.post_view.post)).post;
expect(gammaTrySticky.post_view.post.stickied).toBe(true);
expect(betaPost3.post.stickied).toBe(false);
});
let postRes = await createPost(alpha, betaCommunity.community.id);
// Lock the post
- let searchBeta = await searchPost(beta, postRes.post_view.post);
- let betaPost1 = searchBeta.posts[0];
+ let betaPost1 = (await resolvePost(beta, postRes.post_view.post)).post;
let lockedPostRes = await lockPost(beta, true, betaPost1.post);
expect(lockedPostRes.post_view.post.locked).toBe(true);
expect(deletedPost.post_view.post.name).toBe("");
// Make sure lemmy beta sees post is deleted
- let searchBeta = await searchPost(beta, postRes.post_view.post);
- let betaPost = searchBeta.posts[0];
+ let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
// This will be undefined because of the tombstone
expect(betaPost).toBeUndefined();
expect(undeletedPost.post_view.post.deleted).toBe(false);
// Make sure lemmy beta sees post is undeleted
- let searchBeta2 = await searchPost(beta, postRes.post_view.post);
- let betaPost2 = searchBeta2.posts[0];
+ let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post;
expect(betaPost2.post.deleted).toBe(false);
assertPostFederation(betaPost2, undeletedPost.post_view);
expect(removedPost.post_view.post.name).toBe("");
// Make sure lemmy beta sees post is NOT removed
- let searchBeta = await searchPost(beta, postRes.post_view.post);
- let betaPost = searchBeta.posts[0];
+ let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
expect(betaPost.post.removed).toBe(false);
// Undelete
expect(undeletedPost.post_view.post.removed).toBe(false);
// Make sure lemmy beta sees post is undeleted
- let searchBeta2 = await searchPost(beta, postRes.post_view.post);
- let betaPost2 = searchBeta2.posts[0];
+ let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post;
expect(betaPost2.post.removed).toBe(false);
assertPostFederation(betaPost2, undeletedPost.post_view);
});
let postRes = await createPost(alpha, betaCommunity.community.id);
expect(postRes.post_view.post).toBeDefined();
- let searchBeta = await searchPost(beta, postRes.post_view.post);
+ let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
- expect(searchBeta.posts[0].post.name).toBeDefined();
+ expect(betaPost.post.name).toBeDefined();
});
test('A and G subscribe to B (center) A posts, it gets announced to G', async () => {
let postRes = await createPost(alpha, betaCommunity.community.id);
expect(postRes.post_view.post).toBeDefined();
- let search2 = await searchPost(gamma, postRes.post_view.post);
- expect(search2.posts[0].post.name).toBeDefined();
+ let betaPost = (await resolvePost(gamma, postRes.post_view.post)).post;
+ expect(betaPost.post.name).toBeDefined();
});
test('Enforce site ban for federated user', async () => {
let alphaShortname = `@lemmy_alpha@lemmy-alpha:8541`;
- let userSearch = await searchForUser(beta, alphaShortname);
- let alphaUser = userSearch.users[0];
- expect(alphaUser).toBeDefined();
+ let alphaPerson = (await resolvePerson(beta, alphaShortname)).person;
+ expect(alphaPerson).toBeDefined();
// ban alpha from beta site
- let banAlpha = await banPersonFromSite(beta, alphaUser.person.id, true);
+ let banAlpha = await banPersonFromSite(beta, alphaPerson.person.id, true);
expect(banAlpha.banned).toBe(true);
// Alpha makes post on beta
expect(betaPost).toBeUndefined();
// Unban alpha
- let unBanAlpha = await banPersonFromSite(beta, alphaUser.person.id, false);
+ let unBanAlpha = await banPersonFromSite(beta, alphaPerson.person.id, false);
expect(unBanAlpha.banned).toBe(false);
});
test('Enforce community ban for federated user', async () => {
let alphaShortname = `@lemmy_alpha@lemmy-alpha:8541`;
- let userSearch = await searchForUser(beta, alphaShortname);
- let alphaUser = userSearch.users[0];
- expect(alphaUser).toBeDefined();
+ let alphaPerson = (await resolvePerson(beta, alphaShortname)).person;
+ expect(alphaPerson).toBeDefined();
// ban alpha from beta site
- await banPersonFromCommunity(beta, alphaUser.person.id, 2, false);
- let banAlpha = await banPersonFromCommunity(beta, alphaUser.person.id, 2, true);
+ await banPersonFromCommunity(beta, alphaPerson.person.id, 2, false);
+ let banAlpha = await banPersonFromCommunity(beta, alphaPerson.person.id, 2, true);
expect(banAlpha.banned).toBe(true);
// Alpha tries to make post on beta, but it fails because of ban
// Unban alpha
let unBanAlpha = await banPersonFromCommunity(
beta,
- alphaUser.person.id,
+ alphaPerson.person.id,
2,
false
);
BanFromCommunityResponse,
Post,
CreatePrivateMessage,
+ ResolveObjectResponse,
+ ResolveObject,
} from 'lemmy-js-client';
export interface API {
return api.client.lockPost(form);
}
-export async function searchPost(
+export async function resolvePost(
api: API,
post: Post
-): Promise<SearchResponse> {
- let form: Search = {
+): Promise<ResolveObjectResponse> {
+ let form: ResolveObject = {
q: post.ap_id,
- type_: SearchType.Posts,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
export async function searchPostLocal(
return api.client.getPost(form);
}
-export async function searchComment(
+export async function resolveComment(
api: API,
comment: Comment
-): Promise<SearchResponse> {
- let form: Search = {
+): Promise<ResolveObjectResponse> {
+ let form: ResolveObject = {
q: comment.ap_id,
- type_: SearchType.Comments,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
-export async function searchForBetaCommunity(
+export async function resolveBetaCommunity(
api: API
-): Promise<SearchResponse> {
- // Make sure lemmy-beta/c/main is cached on lemmy_alpha
+): Promise<ResolveObjectResponse> {
// Use short-hand search url
- let form: Search = {
+ let form: ResolveObject = {
q: '!main@lemmy-beta:8551',
- type_: SearchType.Communities,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
-export async function searchForCommunity(
+export async function resolveCommunity(
api: API,
q: string
-): Promise<SearchResponse> {
- // Use short-hand search url
- let form: Search = {
+): Promise<ResolveObjectResponse> {
+ let form: ResolveObject = {
q,
- type_: SearchType.Communities,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
-export async function searchForUser(
+export async function resolvePerson(
api: API,
apShortname: string
-): Promise<SearchResponse> {
- // Make sure lemmy-beta/c/main is cached on lemmy_alpha
- // Use short-hand search url
- let form: Search = {
+): Promise<ResolveObjectResponse> {
+ let form: ResolveObject = {
q: apShortname,
- type_: SearchType.Users,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
export async function banPersonFromSite(
ban: boolean
): Promise<BanPersonResponse> {
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
- // Use short-hand search url
let form: BanPerson = {
person_id,
ban,
ban: boolean
): Promise<BanFromCommunityResponse> {
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
- // Use short-hand search url
let form: BanFromCommunity = {
person_id,
community_id,
}
export async function followBeta(api: API): Promise<CommunityResponse> {
- // Cache it
- let search = await searchForBetaCommunity(api);
- let com = search.communities.find(c => c.community.local == false);
- if (com) {
- let follow = await followCommunity(api, true, com.community.id);
+ let betaCommunity = (await resolveBetaCommunity(api)).community;
+ if (betaCommunity) {
+ let follow = await followCommunity(api, true, betaCommunity.community.id);
return follow;
}
}
alpha,
beta,
registerUser,
- searchForUser,
+ resolvePerson,
saveUserSettings,
getSite,
} from './shared';
};
await saveUserSettings(alpha, form);
- let searchAlpha = await searchForUser(alpha, apShortname);
- let userOnAlpha = searchAlpha.users[0];
- let searchBeta = await searchForUser(beta, apShortname);
- let userOnBeta = searchBeta.users[0];
- assertUserFederation(userOnAlpha, userOnBeta);
+ let alphaPerson = (await resolvePerson(alpha, apShortname)).person;
+ let betaPerson = (await resolvePerson(beta, apShortname)).person;
+ assertUserFederation(alphaPerson, betaPerson);
});
dependencies:
language-subtag-registry "~0.3.2"
-lemmy-js-client@0.11.4-rc.9:
- version "0.11.4-rc.9"
- resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.11.4-rc.9.tgz#f7b3c73691e4c1600daf3840d22d9cfbddc5f363"
- integrity sha512-zP8JxWzQU+yuyE8cMG0GzR8aR3lJ++G5zzbynsXwDevzAZXhOm0ObNNtJiA3Q5msStFVKVYa3GwZxBv4XiYshw==
+lemmy-js-client@0.11.4-rc.14:
+ version "0.11.4-rc.14"
+ resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.11.4-rc.14.tgz#dcac5b8dc78c3b04e6b3630ff9351a94aa73e109"
+ integrity sha512-R8M+myyriNQljQlTweVqtUKGBpgmaM7RI4ebYb7N7sYr5Bk5Ip6v2qTNvKAV6BlsDOCTWANOonfeoz/cIerLEg==
leven@^3.1.0:
version "3.1.0"
_websocket_id: Option<ConnectionId>,
) -> Result<ResolveObjectResponse, LemmyError> {
let local_user_view = get_local_user_view_from_jwt_opt(&self.auth, context.pool()).await?;
- search_by_apub_id(&self.q, local_user_view, context).await
+ let res = search_by_apub_id(&self.q, local_user_view, context)
+ .await
+ .map_err(|_| ApiError::err("couldnt_find_object"))?;
+ Ok(res)
}
}
pub auth: Option<String>,
}
-#[derive(Serialize, Debug)]
-pub enum ResolveObjectResponse {
- Comment(CommentView),
- Post(PostView),
- Community(CommunityView),
- Person(PersonViewSafe),
+#[derive(Serialize, Default)]
+pub struct ResolveObjectResponse {
+ pub comment: Option<CommentView>,
+ pub post: Option<PostView>,
+ pub community: Option<CommunityView>,
+ pub person: Option<PersonViewSafe>,
}
#[derive(Deserialize)]
CommunityView::read(conn, community.id, local_user_view.map(|l| l.person.id))
})
.await??;
- Ok(ResolveObjectResponse::Community(res))
+ Ok(ResolveObjectResponse {
+ community: Some(res),
+ ..ResolveObjectResponse::default()
+ })
}
WebfingerType::Person => {
let res = blocking(context.pool(), move |conn| {
PersonViewSafe::read(conn, person.id)
})
.await??;
- Ok(ResolveObjectResponse::Person(res))
+ Ok(ResolveObjectResponse {
+ person: Some(res),
+ ..ResolveObjectResponse::default()
+ })
}
};
}
let person_uri = p.id(&query_url)?;
let person = get_or_fetch_and_upsert_person(person_uri, context, recursion_counter).await?;
- ROR::Person(
- blocking(context.pool(), move |conn| {
+ ROR {
+ person: blocking(context.pool(), move |conn| {
PersonViewSafe::read(conn, person.id)
})
- .await??,
- )
+ .await?
+ .ok(),
+ ..ROR::default()
+ }
}
SearchAcceptedObjects::Group(g) => {
let community_uri = g.id(&query_url)?;
let community =
get_or_fetch_and_upsert_community(community_uri, context, recursion_counter).await?;
- ROR::Community(
- blocking(context.pool(), move |conn| {
+ ROR {
+ community: blocking(context.pool(), move |conn| {
CommunityView::read(conn, community.id, None)
})
- .await??,
- )
+ .await?
+ .ok(),
+ ..ROR::default()
+ }
}
SearchAcceptedObjects::Page(p) => {
let p = Post::from_apub(&p, context, &query_url, recursion_counter).await?;
- ROR::Post(blocking(context.pool(), move |conn| PostView::read(conn, p.id, None)).await??)
+ ROR {
+ post: blocking(context.pool(), move |conn| PostView::read(conn, p.id, None))
+ .await?
+ .ok(),
+ ..ROR::default()
+ }
}
SearchAcceptedObjects::Comment(c) => {
let c = Comment::from_apub(&c, context, &query_url, recursion_counter).await?;
- ROR::Comment(
- blocking(context.pool(), move |conn| {
+ ROR {
+ comment: blocking(context.pool(), move |conn| {
CommentView::read(conn, c.id, None)
})
- .await??,
- )
+ .await?
+ .ok(),
+ ..ROR::default()
+ }
}
})
}