mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Fix for follower/following timelines being wrong
This commit is contained in:
parent
8bda61e099
commit
342a8011f1
|
|
@ -1,7 +1,8 @@
|
||||||
import { apiRoute, applyConfig } from "@api";
|
import { apiRoute, applyConfig } from "@api";
|
||||||
import { errorResponse, jsonResponse } from "@response";
|
import { errorResponse, jsonResponse } from "@response";
|
||||||
|
import { fetchTimeline } from "@timelines";
|
||||||
import { client } from "~database/datasource";
|
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";
|
import { userRelations } from "~database/entities/relations";
|
||||||
|
|
||||||
export const meta = applyConfig({
|
export const meta = applyConfig({
|
||||||
|
|
@ -40,42 +41,36 @@ export default apiRoute<{
|
||||||
|
|
||||||
if (!user) return errorResponse("User not found", 404);
|
if (!user) return errorResponse("User not found", 404);
|
||||||
|
|
||||||
const objects = await client.user.findMany({
|
const { objects, link } = await fetchTimeline<UserWithRelations>(
|
||||||
where: {
|
client.user,
|
||||||
relationships: {
|
{
|
||||||
some: {
|
where: {
|
||||||
subjectId: user.id,
|
relationships: {
|
||||||
following: true,
|
some: {
|
||||||
|
subjectId: user.id,
|
||||||
|
following: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
id: {
|
||||||
|
lt: max_id,
|
||||||
|
gt: min_id,
|
||||||
|
gte: since_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
id: {
|
include: userRelations,
|
||||||
lt: max_id,
|
take: Number(limit),
|
||||||
gt: min_id,
|
orderBy: {
|
||||||
gte: since_id,
|
id: "desc",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
include: userRelations,
|
req,
|
||||||
take: Number(limit),
|
);
|
||||||
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"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return jsonResponse(
|
return jsonResponse(
|
||||||
await Promise.all(objects.map((object) => userToAPI(object))),
|
await Promise.all(objects.map((object) => userToAPI(object))),
|
||||||
200,
|
200,
|
||||||
{
|
{
|
||||||
Link: linkHeader.join(", "),
|
Link: link,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
import { apiRoute, applyConfig } from "@api";
|
import { apiRoute, applyConfig } from "@api";
|
||||||
import { errorResponse, jsonResponse } from "@response";
|
import { errorResponse, jsonResponse } from "@response";
|
||||||
|
import { fetchTimeline } from "@timelines";
|
||||||
import { client } from "~database/datasource";
|
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";
|
import { userRelations } from "~database/entities/relations";
|
||||||
|
|
||||||
export const meta = applyConfig({
|
export const meta = applyConfig({
|
||||||
|
|
@ -40,42 +41,36 @@ export default apiRoute<{
|
||||||
|
|
||||||
if (!user) return errorResponse("User not found", 404);
|
if (!user) return errorResponse("User not found", 404);
|
||||||
|
|
||||||
const objects = await client.user.findMany({
|
const { objects, link } = await fetchTimeline<UserWithRelations>(
|
||||||
where: {
|
client.user,
|
||||||
relationshipSubjects: {
|
{
|
||||||
some: {
|
where: {
|
||||||
ownerId: user.id,
|
relationshipSubjects: {
|
||||||
following: true,
|
some: {
|
||||||
|
ownerId: user.id,
|
||||||
|
following: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
id: {
|
||||||
|
lt: max_id,
|
||||||
|
gt: min_id,
|
||||||
|
gte: since_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
id: {
|
include: userRelations,
|
||||||
lt: max_id,
|
take: Number(limit),
|
||||||
gt: min_id,
|
orderBy: {
|
||||||
gte: since_id,
|
id: "desc",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
include: userRelations,
|
req,
|
||||||
take: Number(limit),
|
);
|
||||||
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"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return jsonResponse(
|
return jsonResponse(
|
||||||
await Promise.all(objects.map((object) => userToAPI(object))),
|
await Promise.all(objects.map((object) => userToAPI(object))),
|
||||||
200,
|
200,
|
||||||
{
|
{
|
||||||
Link: linkHeader.join(", "),
|
Link: link,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ export default apiRoute<{
|
||||||
since_id,
|
since_id,
|
||||||
limit = "20",
|
limit = "20",
|
||||||
exclude_reblogs,
|
exclude_reblogs,
|
||||||
|
only_media = false,
|
||||||
pinned,
|
pinned,
|
||||||
} = extraData.parsedRequest;
|
} = extraData.parsedRequest;
|
||||||
|
|
||||||
|
|
@ -70,6 +71,8 @@ export default apiRoute<{
|
||||||
id: user.id,
|
id: user.id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// If only_media is true, only return statuses with attachments
|
||||||
|
attachments: only_media ? { some: {} } : undefined,
|
||||||
id: {
|
id: {
|
||||||
lt: max_id,
|
lt: max_id,
|
||||||
gt: min_id,
|
gt: min_id,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue