summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/notes
diff options
context:
space:
mode:
authorHazel K <acomputerdog@gmail.com>2024-09-30 01:12:29 -0400
committerHazel K <acomputerdog@gmail.com>2024-09-30 01:12:29 -0400
commit3479c2c13a64e71900644b65acce33226d3f1213 (patch)
tree8b3f2bbcc0688a4ee8bb8a9cac40701f568ecccf /packages/backend/src/server/api/endpoints/notes
parentadd /notes/following endpoint (diff)
downloadsharkey-3479c2c13a64e71900644b65acce33226d3f1213.tar.gz
sharkey-3479c2c13a64e71900644b65acce33226d3f1213.tar.bz2
sharkey-3479c2c13a64e71900644b65acce33226d3f1213.zip
add mutuals-only option
Diffstat (limited to 'packages/backend/src/server/api/endpoints/notes')
-rw-r--r--packages/backend/src/server/api/endpoints/notes/following.ts20
1 files changed, 14 insertions, 6 deletions
diff --git a/packages/backend/src/server/api/endpoints/notes/following.ts b/packages/backend/src/server/api/endpoints/notes/following.ts
index 57ab5a6aeb..a317e8e8b1 100644
--- a/packages/backend/src/server/api/endpoints/notes/following.ts
+++ b/packages/backend/src/server/api/endpoints/notes/following.ts
@@ -32,6 +32,7 @@ export const meta = {
export const paramDef = {
type: 'object',
properties: {
+ mutualsOnly: { type: 'boolean', default: false },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
@@ -51,8 +52,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private queryService: QueryService,
) {
super(meta, paramDef, async (ps, me) => {
- const query = this.notesRepository
+ let query = this.notesRepository
.createQueryBuilder('note')
+ .setParameter('me', me.id)
// Limit to latest notes
.innerJoin(LatestNote, 'latest', 'note.id = latest.note_id')
@@ -72,16 +74,22 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Limit to followers
.innerJoin(MiFollowing, 'following', 'latest.user_id = following."followeeId"')
- .andWhere('following."followerId" = :me', { me: me.id })
+ .andWhere('following."followerId" = :me');
- // Support pagination
+ // Limit to mutuals, if requested
+ if (ps.mutualsOnly) {
+ query = query
+ .innerJoin(MiFollowing, 'mutuals', 'latest.user_id = mutuals."followerId" AND mutuals."followeeId" = :me');
+ }
+
+ // Support pagination
+ query = this.queryService
+ .makePaginationQuery(query, ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
.orderBy('note.id', 'DESC')
.take(ps.limit);
// Query and return the next page
- const notes = await this.queryService
- .makePaginationQuery(query, ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
- .getMany();
+ const notes = await query.getMany();
return await this.noteEntityService.packMany(notes, me);
});
}