From c4503aa6b24fa1f58b85c95c405b333d6fbc3d0f Mon Sep 17 00:00:00 2001 From: tamaina Date: Sat, 17 Jul 2021 21:49:45 +0900 Subject: [PATCH 1/7] =?UTF-8?q?api/notifications/read=E3=81=AF=E9=85=8D?= =?UTF-8?q?=E5=88=97=E3=81=A7=E5=8F=97=E3=81=91=E4=BB=98=E3=81=91=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/endpoints/notifications/read.ts | 41 +++++++------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/server/api/endpoints/notifications/read.ts b/src/server/api/endpoints/notifications/read.ts index fe8e5ba44f2a..fc99a91b8254 100644 --- a/src/server/api/endpoints/notifications/read.ts +++ b/src/server/api/endpoints/notifications/read.ts @@ -1,42 +1,29 @@ import $ from 'cafy'; import { ID } from '@/misc/cafy-id'; -import { publishMainStream } from '../../../../services/stream'; import define from '../../define'; -import { Notifications } from '../../../../models'; import { readNotification } from '../../common/read-notification'; -import { ApiError } from '../../error'; export const meta = { + desc: { + 'ja-JP': '通知を既読にします。', + 'en-US': 'Mark a notification as read.' + }, + tags: ['notifications', 'account'], requireCredential: true as const, - kind: 'write:notifications', - params: { - notificationId: { - validator: $.type(ID), - }, + notificationIds: { + validator: $.arr($.type(ID)), + desc: { + 'ja-JP': '対象の通知のIDの配列', + 'en-US': 'Target notification IDs.' + } + } }, - errors: { - noSuchNotification: { - message: 'No such notification.', - code: 'NO_SUCH_NOTIFICATION', - id: 'efa929d5-05b5-47d1-beec-e6a4dbed011e' - }, - }, + kind: 'write:notifications' }; -export default define(meta, async (ps, user) => { - const notification = await Notifications.findOne({ - notifieeId: user.id, - id: ps.notificationId, - }); - - if (notification == null) { - throw new ApiError(meta.errors.noSuchNotification); - } - - readNotification(user.id, [notification.id]); -}); +export default define(meta, async (ps, user) => readNotification(user.id, ps.notificationIds)); From 9f69fb0a81f7993e9f9cfa763891bb03122df425 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 19 Jul 2021 14:58:18 +0900 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BA=92=E6=8F=9B=E6=80=A7=E3=81=A7notific?= =?UTF-8?q?ationId=E3=82=92=E5=8F=97=E3=81=91=E4=BB=98=E3=81=91=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/endpoints/notifications/read.ts | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/server/api/endpoints/notifications/read.ts b/src/server/api/endpoints/notifications/read.ts index fc99a91b8254..6ad413c0495e 100644 --- a/src/server/api/endpoints/notifications/read.ts +++ b/src/server/api/endpoints/notifications/read.ts @@ -2,6 +2,7 @@ import $ from 'cafy'; import { ID } from '@/misc/cafy-id'; import define from '../../define'; import { readNotification } from '../../common/read-notification'; +import { ApiError } from '../../error'; export const meta = { desc: { @@ -13,9 +14,19 @@ export const meta = { requireCredential: true as const, + kind: 'write:notifications', + params: { + notificationId: { + validator: $.optional.type(ID), + desc: { + 'ja-JP': '対象の通知のID', + 'en-US': 'Target notification ID.' + } + }, + notificationIds: { - validator: $.arr($.type(ID)), + validator: $.optional.arr($.type(ID)), desc: { 'ja-JP': '対象の通知のIDの配列', 'en-US': 'Target notification IDs.' @@ -23,7 +34,24 @@ export const meta = { } }, - kind: 'write:notifications' + errors: { + noNotificationRequested: { + message: 'You requested no notification.', + code: 'NO_NOTIFICATION_REQUESTED', + id: '1dee2109-b88b-21cf-3935-607dad60f5b0' + }, + }, }; -export default define(meta, async (ps, user) => readNotification(user.id, ps.notificationIds)); +export default define(meta, async (ps, user) => { + let notificationIds = [] as string[]; + + if (ps.notificationId) notificationIds.push(ps.notificationId); + if (ps.notificationIds) notificationIds = notificationIds.concat(ps.notificationIds); + + if (notificationIds.length === 0) { + throw new ApiError(meta.errors.noNotificationRequested); + } + + return readNotification(user.id, notificationIds) +}); From ceab3fc011e50a0bb62a83f8b6fd1bafbfb3c4d2 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 19 Jul 2021 15:09:43 +0900 Subject: [PATCH 3/7] fix lint --- src/server/api/endpoints/notifications/read.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/api/endpoints/notifications/read.ts b/src/server/api/endpoints/notifications/read.ts index 6ad413c0495e..a64b1b5acb87 100644 --- a/src/server/api/endpoints/notifications/read.ts +++ b/src/server/api/endpoints/notifications/read.ts @@ -53,5 +53,5 @@ export default define(meta, async (ps, user) => { throw new ApiError(meta.errors.noNotificationRequested); } - return readNotification(user.id, notificationIds) + return readNotification(user.id, notificationIds); }); From c4d5e92f2bec94431cd2495d5faa9a6050edfe9b Mon Sep 17 00:00:00 2001 From: tamaina Date: Fri, 20 Aug 2021 14:26:47 +0900 Subject: [PATCH 4/7] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 159de1dea4e0..8cdca401765d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Improvements - 依存関係の更新 +- API: notifications/readは配列でも受け付けるように ### Bugfixes - チャンネルを作成しているとアカウントを削除できないのを修正 From c71ffa91a949e6dd1c56e8a1e07a792f9bb47a48 Mon Sep 17 00:00:00 2001 From: tamaina Date: Fri, 12 Nov 2021 00:07:06 +0900 Subject: [PATCH 5/7] Update read.ts --- src/server/api/endpoints/notifications/read.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/server/api/endpoints/notifications/read.ts b/src/server/api/endpoints/notifications/read.ts index a64b1b5acb87..c2c6c439a9f4 100644 --- a/src/server/api/endpoints/notifications/read.ts +++ b/src/server/api/endpoints/notifications/read.ts @@ -49,9 +49,5 @@ export default define(meta, async (ps, user) => { if (ps.notificationId) notificationIds.push(ps.notificationId); if (ps.notificationIds) notificationIds = notificationIds.concat(ps.notificationIds); - if (notificationIds.length === 0) { - throw new ApiError(meta.errors.noNotificationRequested); - } - return readNotification(user.id, notificationIds); }); From 1cd67da1a14c1ca581370a3167324c27e99dc516 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sat, 19 Feb 2022 16:19:54 +0900 Subject: [PATCH 6/7] :v: --- .../src/server/api/endpoints/notifications/read.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/notifications/read.ts b/packages/backend/src/server/api/endpoints/notifications/read.ts index 659cc1e0333b..65c78ffb1357 100644 --- a/packages/backend/src/server/api/endpoints/notifications/read.ts +++ b/packages/backend/src/server/api/endpoints/notifications/read.ts @@ -43,10 +43,6 @@ const paramDef = { // eslint-disable-next-line import/no-default-export export default define(meta, paramDef, async (ps, user) => { - let notificationIds = [] as string[]; - - if (ps.notificationId) notificationIds.push(ps.notificationId); - if (ps.notificationIds) notificationIds = notificationIds.concat(ps.notificationIds); - - return readNotification(user.id, notificationIds); + if ('notificationId' in ps) return readNotification(user.id, [ps.notificationId]); + return readNotification(user.id, ps.notificationIds); }); From b8f3eeed4bf7c3035717422032b330c724058560 Mon Sep 17 00:00:00 2001 From: tamaina Date: Fri, 4 Mar 2022 16:02:04 +0900 Subject: [PATCH 7/7] fix --- packages/backend/src/server/api/endpoints/notifications/read.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/endpoints/notifications/read.ts b/packages/backend/src/server/api/endpoints/notifications/read.ts index 2075885db0d3..65e96d486276 100644 --- a/packages/backend/src/server/api/endpoints/notifications/read.ts +++ b/packages/backend/src/server/api/endpoints/notifications/read.ts @@ -1,4 +1,4 @@ -import define from '../../define'; +import define from '../../define.js'; import { readNotification } from '../../common/read-notification.js'; export const meta = {