Skip to content

Commit

Permalink
fix: /i/notificationsがsinceIdのみのときに正しく動かない問題
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed May 19, 2024
1 parent ba62b73 commit cb67abe
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/backend/src/server/api/endpoints/i/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,23 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const includeTypes = ps.includeTypes && ps.includeTypes.filter(type => !(obsoleteNotificationTypes).includes(type as any)) as typeof notificationTypes[number][];
const excludeTypes = ps.excludeTypes && ps.excludeTypes.filter(type => !(obsoleteNotificationTypes).includes(type as any)) as typeof notificationTypes[number][];

let notificationsRes: [id: string, fields: string[]][];
const limit = ps.limit + (ps.untilId ? 1 : 0) + (ps.sinceId ? 1 : 0); // untilIdに指定したものも含まれるため+1
const notificationsRes = await this.redisClient.xrevrange(
`notificationTimeline:${me.id}`,
ps.untilId ? this.idService.parse(ps.untilId).date.getTime() : '+',
ps.sinceId ? this.idService.parse(ps.sinceId).date.getTime() : '-',
'COUNT', limit);

// sinceidのみの場合は古い順、そうでない場合は新しい順。 QueryService.makePaginationQueryも参照
if (ps.sinceId && !ps.untilId) {
notificationsRes = await this.redisClient.xrange(
`notificationTimeline:${me.id}`,
ps.sinceId ? this.idService.parse(ps.sinceId).date.getTime() : '-',
'+',
'COUNT', limit);
} else {
notificationsRes = await this.redisClient.xrevrange(
`notificationTimeline:${me.id}`,
ps.untilId ? this.idService.parse(ps.untilId).date.getTime() : '+',
ps.sinceId ? this.idService.parse(ps.sinceId).date.getTime() : '-',
'COUNT', limit);
}

if (notificationsRes.length === 0) {
return [];
Expand Down

0 comments on commit cb67abe

Please sign in to comment.