From a96e5277db7f638d6601fb1d714d95d6d357ca35 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 19 Oct 2021 20:25:47 +0900 Subject: [PATCH] =?UTF-8?q?fix(api):=20=E3=82=A2=E3=83=97=E3=83=AA?= =?UTF-8?q?=E3=82=B1=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E3=81=8C=E5=8F=96=E5=BE=97=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84?= =?UTF-8?q?=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #6702 --- CHANGELOG.md | 1 + CONTRIBUTING.md | 3 +++ src/server/api/endpoints/i/notifications.ts | 11 +++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a07096b3d..705c093a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ ### Bugfixes - クライアント: テーマの管理が行えない問題を修正 +- API: アプリケーション通知が取得できない問題を修正 ## 12.92.0 (2021/10/16) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3ec8baaac..76267ab30 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -171,6 +171,9 @@ const users = userIds.length > 0 ? await Users.find({ SQLでは配列のインデックスは**1始まり**。 `[a, b, c]`の `a`にアクセスしたいなら`[0]`ではなく`[1]`と書く +### null IN +nullが含まれる可能性のあるカラムにINするときは、そのままだとおかしくなるのでORなどでnullのハンドリングをしよう。 + ### `undefined`にご用心 MongoDBの時とは違い、findOneでレコードを取得する時に対象レコードが存在しない場合 **`undefined`** が返ってくるので注意。 MongoDBは`null`で返してきてたので、その感覚で`if (x === null)`とか書くとバグる。代わりに`if (x == null)`と書いてください diff --git a/src/server/api/endpoints/i/notifications.ts b/src/server/api/endpoints/i/notifications.ts index fcabbbc3d..56668d03b 100644 --- a/src/server/api/endpoints/i/notifications.ts +++ b/src/server/api/endpoints/i/notifications.ts @@ -6,6 +6,7 @@ import { makePaginationQuery } from '../../common/make-pagination-query'; import { Notifications, Followings, Mutings, Users } from '@/models/index'; import { notificationTypes } from '@/types'; import read from '@/services/note/read'; +import { Brackets } from 'typeorm'; export const meta = { tags: ['account', 'notifications'], @@ -94,10 +95,16 @@ export default define(meta, async (ps, user) => { .leftJoinAndSelect('reply.user', 'replyUser') .leftJoinAndSelect('renote.user', 'renoteUser'); - query.andWhere(`notification.notifierId NOT IN (${ mutingQuery.getQuery() })`); + query.andWhere(new Brackets(qb => { qb + .where(`notification.notifierId NOT IN (${ mutingQuery.getQuery() })`) + .orWhere('notification.notifierId IS NULL'); + })); query.setParameters(mutingQuery.getParameters()); - query.andWhere(`notification.notifierId NOT IN (${ suspendedQuery.getQuery() })`); + query.andWhere(new Brackets(qb => { qb + .where(`notification.notifierId NOT IN (${ suspendedQuery.getQuery() })`) + .orWhere('notification.notifierId IS NULL'); + })); if (ps.following) { query.andWhere(`((notification.notifierId IN (${ followingQuery.getQuery() })) OR (notification.notifierId = :meId))`, { meId: user.id });