互換性でnotificationIdを受け付けるように
This commit is contained in:
parent
c4503aa6b2
commit
9f69fb0a81
|
@ -2,6 +2,7 @@ import $ from 'cafy';
|
||||||
import { ID } from '@/misc/cafy-id';
|
import { ID } from '@/misc/cafy-id';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { readNotification } from '../../common/read-notification';
|
import { readNotification } from '../../common/read-notification';
|
||||||
|
import { ApiError } from '../../error';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -13,9 +14,19 @@ export const meta = {
|
||||||
|
|
||||||
requireCredential: true as const,
|
requireCredential: true as const,
|
||||||
|
|
||||||
|
kind: 'write:notifications',
|
||||||
|
|
||||||
params: {
|
params: {
|
||||||
|
notificationId: {
|
||||||
|
validator: $.optional.type(ID),
|
||||||
|
desc: {
|
||||||
|
'ja-JP': '対象の通知のID',
|
||||||
|
'en-US': 'Target notification ID.'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
notificationIds: {
|
notificationIds: {
|
||||||
validator: $.arr($.type(ID)),
|
validator: $.optional.arr($.type(ID)),
|
||||||
desc: {
|
desc: {
|
||||||
'ja-JP': '対象の通知のIDの配列',
|
'ja-JP': '対象の通知のIDの配列',
|
||||||
'en-US': 'Target notification IDs.'
|
'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)
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue