Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 59 additions & 16 deletions src/api/v1/timelines.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { zValidator } from "@hono/zod-validator";
import {
and,
asc,
desc,
eq,
gt,
Expand Down Expand Up @@ -78,6 +79,9 @@ app.get(
);
}
const query = c.req.valid("query");
const minId = query.min_id;
const isForward = minId != null;
const sinceId = query.since_id;
const timeline = await db.query.posts.findMany({
where: and(
eq(posts.visibility, "public"),
Expand Down Expand Up @@ -178,12 +182,17 @@ app.get(
),
),
query.max_id == null ? undefined : lt(posts.id, query.max_id),
query.min_id == null ? undefined : gt(posts.id, query.min_id),
minId != null
? gt(posts.id, minId)
: sinceId == null
? undefined
: gt(posts.id, sinceId),
),
with: getPostRelations(owner.id),
orderBy: [desc(posts.id)],
orderBy: [isForward ? asc(posts.id) : desc(posts.id)],
limit: query.limit,
});
if (isForward) timeline.reverse();
const nextMaxId =
timeline.length >= query.limit ? timeline[timeline.length - 1].id : null;
const nextLink = nextMaxId == null ? undefined : new URL(c.req.url);
Expand All @@ -209,6 +218,9 @@ app.get(
);
}
const query = c.req.valid("query");
const minId = query.min_id;
const isForward = minId != null;
const sinceId = query.since_id;
let timeline: Parameters<typeof serializePost>[0][];
if (TIMELINE_INBOXES) {
timeline = await db.query.posts.findMany({
Expand All @@ -224,12 +236,18 @@ app.get(
query.max_id == null
? undefined
: lt(timelinePosts.postId, query.max_id),
query.min_id == null
? undefined
: gt(timelinePosts.postId, query.min_id),
minId != null
? gt(timelinePosts.postId, minId)
: sinceId == null
? undefined
: gt(timelinePosts.postId, sinceId),
),
)
.orderBy(desc(timelinePosts.postId))
.orderBy(
isForward
? asc(timelinePosts.postId)
: desc(timelinePosts.postId),
)
.limit(Math.min(TIMELINE_INBOX_LIMIT, query.limit)),
),
// Hide future posts
Expand Down Expand Up @@ -474,12 +492,17 @@ app.get(
),
),
query.max_id == null ? undefined : lt(posts.id, query.max_id),
query.min_id == null ? undefined : gt(posts.id, query.min_id),
minId != null
? gt(posts.id, minId)
: sinceId == null
? undefined
: gt(posts.id, sinceId),
),
with: getPostRelations(owner.id),
orderBy: [desc(posts.id)],
orderBy: [isForward ? asc(posts.id) : desc(posts.id)],
limit: query.limit,
});
if (isForward) timeline.reverse();
}
const nextMaxId =
timeline.length >= query.limit ? timeline[timeline.length - 1].id : null;
Expand Down Expand Up @@ -509,6 +532,9 @@ app.get(
);
}
const query = c.req.valid("query");
const minId = query.min_id;
const isForward = minId != null;
const sinceId = query.since_id;
const list = await db.query.lists.findFirst({
where: and(eq(lists.id, listId), eq(lists.accountOwnerId, owner.id)),
});
Expand All @@ -528,12 +554,16 @@ app.get(
query.max_id == null
? undefined
: lt(listPosts.postId, query.max_id),
query.min_id == null
? undefined
: gt(listPosts.postId, query.min_id),
minId != null
? gt(listPosts.postId, minId)
: sinceId == null
? undefined
: gt(listPosts.postId, sinceId),
),
)
.orderBy(desc(listPosts.postId))
.orderBy(
isForward ? asc(listPosts.postId) : desc(listPosts.postId),
)
.limit(Math.min(TIMELINE_INBOX_LIMIT, query.limit)),
),
// Hide future posts
Expand Down Expand Up @@ -752,12 +782,17 @@ app.get(
),
),
query.max_id == null ? undefined : lt(posts.id, query.max_id),
query.min_id == null ? undefined : gt(posts.id, query.min_id),
minId != null
? gt(posts.id, minId)
: sinceId == null
? undefined
: gt(posts.id, sinceId),
),
with: getPostRelations(owner.id),
orderBy: [desc(posts.id)],
orderBy: [isForward ? asc(posts.id) : desc(posts.id)],
limit: query.limit,
});
if (isForward) timeline.reverse();
}
const nextMaxId =
timeline.length >= query.limit ? timeline[timeline.length - 1].id : null;
Expand Down Expand Up @@ -785,6 +820,9 @@ app.get(
);
}
const query = c.req.valid("query");
const minId = query.min_id;
const isForward = minId != null;
const sinceId = query.since_id;
const hashtag = `#${c.req.param("hashtag")}`;
const timeline = await db.query.posts.findMany({
where: and(
Expand Down Expand Up @@ -862,12 +900,17 @@ app.get(
.where(eq(blocks.blockedAccountId, owner.id)),
),
query.max_id == null ? undefined : lt(posts.id, query.max_id),
query.min_id == null ? undefined : gt(posts.id, query.min_id),
minId != null
? gt(posts.id, minId)
: sinceId == null
? undefined
: gt(posts.id, sinceId),
),
with: getPostRelations(owner.id),
orderBy: [desc(posts.id)],
orderBy: [isForward ? asc(posts.id) : desc(posts.id)],
limit: query.limit,
});
if (isForward) timeline.reverse();
const nextMaxId =
timeline.length >= query.limit ? timeline[timeline.length - 1].id : null;
const nextLink = nextMaxId == null ? undefined : new URL(c.req.url);
Expand Down
Loading