feat(api): Implement indexing toggle and followers/following privacy settings

This commit is contained in:
Jesse Wierzbinski 2025-03-30 20:32:42 +02:00
parent 666eef063c
commit 9d1d56bd08
No known key found for this signature in database
15 changed files with 4854 additions and 15 deletions

View file

@ -44,4 +44,33 @@ describe("/api/v1/accounts/:id/followers", () => {
expect(data).toBeInstanceOf(Array);
expect(data.length).toBe(0);
});
test("should return no followers if account is hiding collections", async () => {
await using client0 = await generateClient(users[0]);
await using client1 = await generateClient(users[1]);
const { ok: ok0 } = await client0.followAccount(users[1].id);
expect(ok0).toBe(true);
const { ok: ok1, data: data1 } = await client0.getAccountFollowers(
users[1].id,
);
expect(ok1).toBe(true);
expect(data1).toBeArrayOfSize(1);
const { ok: ok2 } = await client1.updateCredentials({
hide_collections: true,
});
expect(ok2).toBe(true);
const { ok: ok3, data: data3 } = await client0.getAccountFollowers(
users[1].id,
);
expect(ok3).toBe(true);
expect(data3).toBeArrayOfSize(0);
});
});

View file

@ -83,11 +83,18 @@ export default apiRoute((app) =>
handleZodError,
),
async (context) => {
const { user: self } = context.get("auth");
const { max_id, since_id, min_id, limit } =
context.req.valid("query");
const otherUser = context.get("user");
// TODO: Add follower/following privacy settings
if (
self?.id !== otherUser.id &&
otherUser.data.isHidingCollections
) {
return context.json([], 200, { Link: "" });
}
const { objects, link } = await Timeline.getUserTimeline(
and(
max_id ? lt(Users.id, max_id) : undefined,

View file

@ -43,4 +43,33 @@ describe("/api/v1/accounts/:id/following", () => {
expect(data).toBeInstanceOf(Array);
expect(data.length).toBe(0);
});
test("should return no following if account is hiding collections", async () => {
await using client0 = await generateClient(users[0]);
await using client1 = await generateClient(users[1]);
const { ok: ok0 } = await client1.followAccount(users[0].id);
expect(ok0).toBe(true);
const { ok: ok1, data: data1 } = await client0.getAccountFollowing(
users[1].id,
);
expect(ok1).toBe(true);
expect(data1).toBeArrayOfSize(1);
const { ok: ok2 } = await client1.updateCredentials({
hide_collections: true,
});
expect(ok2).toBe(true);
const { ok: ok3, data: data3 } = await client0.getAccountFollowing(
users[1].id,
);
expect(ok3).toBe(true);
expect(data3).toBeArrayOfSize(0);
});
});

View file

@ -84,10 +84,16 @@ export default apiRoute((app) =>
handleZodError,
),
async (context) => {
const { user: self } = context.get("auth");
const { max_id, since_id, min_id } = context.req.valid("query");
const otherUser = context.get("user");
// TODO: Add follower/following privacy settings
if (
self?.id !== otherUser.id &&
otherUser.data.isHidingCollections
) {
return context.json([], 200, { Link: "" });
}
const { objects, link } = await Timeline.getUserTimeline(
and(

View file

@ -110,16 +110,16 @@ export default apiRoute((app) =>
bot: AccountSchema.shape.bot.openapi({
description: "Whether the account has a bot flag.",
}),
discoverable: AccountSchema.shape.discoverable.openapi({
description:
"Whether the account should be shown in the profile directory.",
}),
// TODO: Implement :(
discoverable: AccountSchema.shape.discoverable
.unwrap()
.openapi({
description:
"Whether the account should be shown in the profile directory.",
}),
hide_collections: zBoolean.openapi({
description:
"Whether to hide followers and followed accounts.",
}),
// TODO: Implement :(
indexable: zBoolean.openapi({
description:
"Whether public posts should be searchable to anyone.",
@ -168,6 +168,8 @@ export default apiRoute((app) =>
locked,
bot,
discoverable,
hide_collections,
indexable,
source,
fields_attributes,
} = context.req.valid("json");
@ -249,14 +251,22 @@ export default apiRoute((app) =>
self.isLocked = locked;
}
if (bot) {
if (bot !== undefined) {
self.isBot = bot;
}
if (discoverable) {
if (discoverable !== undefined) {
self.isDiscoverable = discoverable;
}
if (hide_collections !== undefined) {
self.isHidingCollections = hide_collections;
}
if (indexable !== undefined) {
self.isIndexable = indexable;
}
const fieldEmojis: Emoji[] = [];
if (fields_attributes) {
@ -342,6 +352,8 @@ export default apiRoute((app) =>
isLocked: self.isLocked,
isBot: self.isBot,
isDiscoverable: self.isDiscoverable,
isHidingCollections: self.isHidingCollections,
isIndexable: self.isIndexable,
source: self.source || undefined,
});

View file

@ -44,7 +44,7 @@ describe("/api/v1/accounts/verify_credentials", () => {
expect(data.bot).toBe(users[0].data.isBot);
expect(data.group).toBe(false);
expect(data.discoverable).toBe(users[0].data.isDiscoverable);
expect(data.noindex).toBe(false);
expect(data.noindex).toBe(!users[0].data.isIndexable);
expect(data.moved).toBeNull();
expect(data.suspended).toBe(false);
expect(data.limited).toBe(false);