Fix for follower/following timelines being wrong

This commit is contained in:
Jesse Wierzbinski 2024-04-08 16:40:35 -10:00
parent 8bda61e099
commit 342a8011f1
No known key found for this signature in database
3 changed files with 49 additions and 56 deletions

View file

@ -1,7 +1,8 @@
import { apiRoute, applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response";
import { fetchTimeline } from "@timelines";
import { client } from "~database/datasource";
import { userToAPI } from "~database/entities/User";
import { type UserWithRelations, userToAPI } from "~database/entities/User";
import { userRelations } from "~database/entities/relations";
export const meta = applyConfig({
@ -40,7 +41,9 @@ export default apiRoute<{
if (!user) return errorResponse("User not found", 404);
const objects = await client.user.findMany({
const { objects, link } = await fetchTimeline<UserWithRelations>(
client.user,
{
where: {
relationships: {
some: {
@ -59,23 +62,15 @@ export default apiRoute<{
orderBy: {
id: "desc",
},
});
// Constuct HTTP Link header (next and prev)
const linkHeader = [];
if (objects.length > 0) {
const urlWithoutQuery = req.url.split("?")[0];
linkHeader.push(
`<${urlWithoutQuery}?max_id=${objects.at(-1)?.id}>; rel="next"`,
`<${urlWithoutQuery}?min_id=${objects[0].id}>; rel="prev"`,
},
req,
);
}
return jsonResponse(
await Promise.all(objects.map((object) => userToAPI(object))),
200,
{
Link: linkHeader.join(", "),
Link: link,
},
);
});

View file

@ -1,7 +1,8 @@
import { apiRoute, applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response";
import { fetchTimeline } from "@timelines";
import { client } from "~database/datasource";
import { userToAPI } from "~database/entities/User";
import { userToAPI, type UserWithRelations } from "~database/entities/User";
import { userRelations } from "~database/entities/relations";
export const meta = applyConfig({
@ -40,7 +41,9 @@ export default apiRoute<{
if (!user) return errorResponse("User not found", 404);
const objects = await client.user.findMany({
const { objects, link } = await fetchTimeline<UserWithRelations>(
client.user,
{
where: {
relationshipSubjects: {
some: {
@ -59,23 +62,15 @@ export default apiRoute<{
orderBy: {
id: "desc",
},
});
// Constuct HTTP Link header (next and prev)
const linkHeader = [];
if (objects.length > 0) {
const urlWithoutQuery = req.url.split("?")[0];
linkHeader.push(
`<${urlWithoutQuery}?max_id=${objects.at(-1)?.id}>; rel="next"`,
`<${urlWithoutQuery}?min_id=${objects[0].id}>; rel="prev"`,
},
req,
);
}
return jsonResponse(
await Promise.all(objects.map((object) => userToAPI(object))),
200,
{
Link: linkHeader.join(", "),
Link: link,
},
);
});

View file

@ -48,6 +48,7 @@ export default apiRoute<{
since_id,
limit = "20",
exclude_reblogs,
only_media = false,
pinned,
} = extraData.parsedRequest;
@ -70,6 +71,8 @@ export default apiRoute<{
id: user.id,
},
},
// If only_media is true, only return statuses with attachments
attachments: only_media ? { some: {} } : undefined,
id: {
lt: max_id,
gt: min_id,