summaryrefslogtreecommitdiff
path: root/src/server/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api')
-rw-r--r--src/server/api/endpoints/i/notifications.ts14
-rw-r--r--src/server/api/endpoints/i/update.ts6
2 files changed, 16 insertions, 4 deletions
diff --git a/src/server/api/endpoints/i/notifications.ts b/src/server/api/endpoints/i/notifications.ts
index db6772beb3..fd355dab83 100644
--- a/src/server/api/endpoints/i/notifications.ts
+++ b/src/server/api/endpoints/i/notifications.ts
@@ -44,12 +44,10 @@ export const meta = {
includeTypes: {
validator: $.optional.arr($.str.or(notificationTypes as unknown as string[])),
- default: [] as string[]
},
excludeTypes: {
validator: $.optional.arr($.str.or(notificationTypes as unknown as string[])),
- default: [] as string[]
}
},
@@ -65,6 +63,14 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
+ // includeTypes が空の場合はクエリしない
+ if (ps.includeTypes && ps.includeTypes.length === 0) {
+ return [];
+ }
+ // excludeTypes に全指定されている場合はクエリしない
+ if (notificationTypes.every(type => ps.excludeTypes?.includes(type))) {
+ return [];
+ }
const followingQuery = Followings.createQueryBuilder('following')
.select('following.followeeId')
.where('following.followerId = :followerId', { followerId: user.id });
@@ -91,9 +97,9 @@ export default define(meta, async (ps, user) => {
query.setParameters(followingQuery.getParameters());
}
- if (ps.includeTypes!.length > 0) {
+ if (ps.includeTypes?.length > 0) {
query.andWhere(`notification.type IN (:...includeTypes)`, { includeTypes: ps.includeTypes });
- } else if (ps.excludeTypes!.length > 0) {
+ } else if (ps.excludeTypes?.length > 0) {
query.andWhere(`notification.type NOT IN (:...excludeTypes)`, { excludeTypes: ps.excludeTypes });
}
diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts
index e1889df22d..327e303a66 100644
--- a/src/server/api/endpoints/i/update.ts
+++ b/src/server/api/endpoints/i/update.ts
@@ -14,6 +14,7 @@ import { Users, DriveFiles, UserProfiles, Pages } from '../../../../models';
import { User } from '../../../../models/entities/user';
import { UserProfile } from '../../../../models/entities/user-profile';
import { ensure } from '../../../../prelude/ensure';
+import { notificationTypes } from '../../../../types';
export const meta = {
desc: {
@@ -147,6 +148,10 @@ export const meta = {
mutedWords: {
validator: $.optional.arr($.arr($.str))
},
+
+ includingNotificationTypes: {
+ validator: $.optional.arr($.str.or(notificationTypes as unknown as string[]))
+ },
},
errors: {
@@ -201,6 +206,7 @@ export default define(meta, async (ps, user, token) => {
profileUpdates.mutedWords = ps.mutedWords;
profileUpdates.enableWordMute = ps.mutedWords.length > 0;
}
+ if (ps.includingNotificationTypes !== undefined) profileUpdates.includingNotificationTypes = ps.includingNotificationTypes as typeof notificationTypes[number][];
if (typeof ps.isLocked === 'boolean') updates.isLocked = ps.isLocked;
if (typeof ps.isBot === 'boolean') updates.isBot = ps.isBot;
if (typeof ps.carefulBot === 'boolean') profileUpdates.carefulBot = ps.carefulBot;