diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 870041d673..0812bd8e5b 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -566,6 +566,10 @@ delayed: "遅延" database: "データベース" channel: "チャンネル" create: "作成" +notificationSetting: "通知設定" +notificationSettingDesc: "表示する通知の種別を選択してください。" +useGlobalSetting: "グローバル設定を使う" +useGlobalSettingDesc: "オンにすると、アカウントの通知設定が使用されます。オフにすると、個別に設定できるようになります。" _serverDisconnectedBehavior: reload: "自動でリロード" @@ -1285,8 +1289,11 @@ _notification: renote: "Renote" quote: "引用" reaction: "リアクション" - pollVote: "投票" - receiveFollowRequest: "フォローリクエスト" + pollVote: "アンケートに投票された" + receiveFollowRequest: "フォロー申請を受け取った" + followRequestAccepted: "フォローが受理された" + groupInvited: "グループに招待された" + app: "連携アプリからの通知" _deck: alwaysShowMainColumn: "常にメインカラムを表示" diff --git a/migration/1597236229720-IncludingNotificationTypes.ts b/migration/1597236229720-IncludingNotificationTypes.ts new file mode 100644 index 0000000000..be57824c0b --- /dev/null +++ b/migration/1597236229720-IncludingNotificationTypes.ts @@ -0,0 +1,16 @@ +import {MigrationInterface, QueryRunner} from "typeorm"; + +export class IncludingNotificationTypes1597236229720 implements MigrationInterface { + name = 'IncludingNotificationTypes1597236229720' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TYPE "user_profile_includingnotificationtypes_enum" AS ENUM('follow', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote', 'receiveFollowRequest', 'followRequestAccepted', 'groupInvited', 'app')`); + await queryRunner.query(`ALTER TABLE "user_profile" ADD "includingNotificationTypes" "user_profile_includingnotificationtypes_enum" array`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "includingNotificationTypes"`); + await queryRunner.query(`DROP TYPE "user_profile_includingnotificationtypes_enum"`); + } + +} diff --git a/src/client/app.vue b/src/client/app.vue index f81e7e44ad..c10ba9c9d9 100644 --- a/src/client/app.vue +++ b/src/client/app.vue @@ -328,6 +328,10 @@ export default Vue.extend({ }, async onNotification(notification) { + const t = this.$store.state.i.includingNotificationTypes; + if (!!t && !t.includes(notification.type)) { + return; + } if (document.visibilityState === 'visible') { this.$root.stream.send('readNotification', { id: notification.id diff --git a/src/client/components/deck/notifications-column.vue b/src/client/components/deck/notifications-column.vue index 331cb9207f..ac49aec06d 100644 --- a/src/client/components/deck/notifications-column.vue +++ b/src/client/components/deck/notifications-column.vue @@ -2,7 +2,7 @@ - + @@ -38,28 +38,14 @@ export default Vue.extend({ }, created() { - if (this.column.notificationType == null) { - this.column.notificationType = 'all'; - this.$store.commit('deviceUser/updateDeckColumn', this.column); - } - this.menu = [{ icon: faCog, - text: this.$t('notificationType'), - action: () => { - this.$root.dialog({ - title: this.$t('notificationType'), - type: null, - select: { - items: ['all', 'follow', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote', 'receiveFollowRequest'].map(x => ({ - value: x, text: this.$t(`_notification._types.${x}`) - })) - default: this.column.notificationType, - }, - showCancelButton: true - }).then(({ canceled, result: type }) => { - if (canceled) return; - this.column.notificationType = type; + text: this.$t('notificationSetting'), + action: async () => { + this.$root.new(await import('../notification-setting-window.vue').then(m => m.default), { + includingTypes: this.column.includingTypes, + }).$on('ok', async ({ includingTypes }) => { + this.$set(this.column, 'includingTypes', includingTypes); this.$store.commit('deviceUser/updateDeckColumn', this.column); }); } diff --git a/src/client/components/notification-setting-window.vue b/src/client/components/notification-setting-window.vue new file mode 100644 index 0000000000..d63a3d48a5 --- /dev/null +++ b/src/client/components/notification-setting-window.vue @@ -0,0 +1,98 @@ + + + + + diff --git a/src/client/components/notifications.vue b/src/client/components/notifications.vue index 1271b89475..07dee6354b 100644 --- a/src/client/components/notifications.vue +++ b/src/client/components/notifications.vue @@ -17,11 +17,12 @@ diff --git a/src/client/scripts/form.ts b/src/client/scripts/form.ts index 3cf062be2a..7bf6cec452 100644 --- a/src/client/scripts/form.ts +++ b/src/client/scripts/form.ts @@ -21,6 +21,11 @@ export type FormItem = { default: string | null; hidden?: boolean; enum: string[]; +} | { + label?: string; + type: 'array'; + default: unknown[] | null; + hidden?: boolean; }; export type Form = Record; diff --git a/src/client/widgets/notifications.vue b/src/client/widgets/notifications.vue index 24d7fe4200..9d6282735b 100644 --- a/src/client/widgets/notifications.vue +++ b/src/client/widgets/notifications.vue @@ -1,15 +1,16 @@ diff --git a/src/models/entities/user-profile.ts b/src/models/entities/user-profile.ts index cf1c341182..0eeed1b40e 100644 --- a/src/models/entities/user-profile.ts +++ b/src/models/entities/user-profile.ts @@ -2,6 +2,7 @@ import { Entity, Column, Index, OneToOne, JoinColumn, PrimaryColumn } from 'type import { id } from '../id'; import { User } from './user'; import { Page } from './page'; +import { notificationTypes } from '../../types'; @Entity() export class UserProfile { @@ -158,6 +159,13 @@ export class UserProfile { }) public mutedWords: string[][]; + @Column('enum', { + enum: notificationTypes, + array: true, + nullable: true, + }) + public includingNotificationTypes: typeof notificationTypes[number][] | null; + //#region Denormalized fields @Index() @Column('varchar', { diff --git a/src/models/repositories/user.ts b/src/models/repositories/user.ts index ae5321b15a..b1b084b740 100644 --- a/src/models/repositories/user.ts +++ b/src/models/repositories/user.ts @@ -248,6 +248,7 @@ export class UserRepository extends Repository { hasPendingReceivedFollowRequest: this.getHasPendingReceivedFollowRequest(user.id), integrations: profile!.integrations, mutedWords: profile!.mutedWords, + includingNotificationTypes: profile?.includingNotificationTypes, } : {}), ...(opts.includeSecrets ? { 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; diff --git a/src/services/create-notification.ts b/src/services/create-notification.ts index 7fc8bfaf53..4e713e3804 100644 --- a/src/services/create-notification.ts +++ b/src/services/create-notification.ts @@ -1,6 +1,6 @@ import { publishMainStream } from './stream'; import pushSw from './push-notification'; -import { Notifications, Mutings } from '../models'; +import { Notifications, Mutings, UserProfiles } from '../models'; import { genId } from '../misc/gen-id'; import { User } from '../models/entities/user'; import { Notification } from '../models/entities/notification'; @@ -14,13 +14,18 @@ export async function createNotification( return null; } + const profile = await UserProfiles.findOne({ userId: notifieeId }); + + const isMuted = !profile?.includingNotificationTypes?.includes(type); + // Create notification const notification = await Notifications.save({ id: genId(), createdAt: new Date(), notifieeId: notifieeId, type: type, - isRead: false, + // 相手がこの通知をミュートしているようなら、既読を予めつけておく + isRead: isMuted, ...data } as Partial);