diff --git a/migration/1600353287890-mutingNotificationTypes.ts b/migration/1600353287890-mutingNotificationTypes.ts new file mode 100644 index 0000000000000000000000000000000000000000..914bad8e3fe68d6e35c6252a1106c3dd6d84096e --- /dev/null +++ b/migration/1600353287890-mutingNotificationTypes.ts @@ -0,0 +1,20 @@ +import {MigrationInterface, QueryRunner} from "typeorm"; + +export class mutingNotificationTypes1600353287890 implements MigrationInterface { + name = 'mutingNotificationTypes1600353287890' + + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "includingNotificationTypes"`); + await queryRunner.query(`DROP TYPE "public"."user_profile_includingnotificationtypes_enum"`); + await queryRunner.query(`CREATE TYPE "user_profile_mutingnotificationtypes_enum" AS ENUM('follow', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote', 'receiveFollowRequest', 'followRequestAccepted', 'groupInvited', 'app')`); + await queryRunner.query(`ALTER TABLE "user_profile" ADD "mutingNotificationTypes" "user_profile_mutingnotificationtypes_enum" array NOT NULL DEFAULT '{}'`); + } + + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "mutingNotificationTypes"`); + await queryRunner.query(`DROP TYPE "user_profile_mutingnotificationtypes_enum"`); + await queryRunner.query(`CREATE TYPE "public"."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`); + } + +} diff --git a/src/client/app.vue b/src/client/app.vue index c10ba9c9d9fbd04e6cde00f3a901ac2e2f5ddffa..3453baa28091f4bdfcf7b412a167ee128e939635 100644 --- a/src/client/app.vue +++ b/src/client/app.vue @@ -328,8 +328,7 @@ export default Vue.extend({ }, async onNotification(notification) { - const t = this.$store.state.i.includingNotificationTypes; - if (!!t && !t.includes(notification.type)) { + if (this.$store.state.i.mutingNotificationTypes.includes(notification.type)) { return; } if (document.visibilityState === 'visible') { diff --git a/src/client/components/notifications.vue b/src/client/components/notifications.vue index 07dee6354bb671c1926b12c72b2bf65243ca86bf..0e512e19673b2206820d6b6436b12e47d72bac23 100644 --- a/src/client/components/notifications.vue +++ b/src/client/components/notifications.vue @@ -58,7 +58,7 @@ export default Vue.extend({ computed: { allIncludeTypes() { - return this.includeTypes ?? this.$store.state.i.includingNotificationTypes; + return this.includeTypes ?? notificationTypes.filter(x => !this.$store.state.i.mutingNotificationTypes.includes(x)); } }, @@ -66,7 +66,7 @@ export default Vue.extend({ includeTypes() { this.reload(); }, - '$store.state.i.includingNotificationTypes'() { + '$store.state.i.mutingNotificationTypes'() { if (this.includeTypes === null) { this.reload(); } @@ -84,8 +84,7 @@ export default Vue.extend({ methods: { onNotification(notification) { - // - const isMuted = !!this.allIncludeTypes && !this.allIncludeTypes.includes(notification.type); + const isMuted = !this.allIncludeTypes.includes(notification.type); if (isMuted || document.visibilityState === 'visible') { this.$root.stream.send('readNotification', { id: notification.id diff --git a/src/client/deck.vue b/src/client/deck.vue index dc662801f08f8355ab155c9b797f9cb08723e7cd..c383a1b15c16ba8a97d9dce780c52edf3ac52a23 100644 --- a/src/client/deck.vue +++ b/src/client/deck.vue @@ -161,8 +161,7 @@ export default Vue.extend({ }, async onNotification(notification) { - const t = this.$store.state.i.includingNotificationTypes; - if (!!t && !t.includes(notification.type)) { + if (this.$store.state.i.mutingNotificationTypes.includes(notification.type)) { return; } diff --git a/src/client/pages/my-settings/index.vue b/src/client/pages/my-settings/index.vue index 7da9f24c755a2d98cf1d5fdf8fb9b37629f7652a..ae4ad4dff51dd046fc61df0c88a9fd2078650d09 100644 --- a/src/client/pages/my-settings/index.vue +++ b/src/client/pages/my-settings/index.vue @@ -58,6 +58,7 @@ import XIntegration from './integration.vue'; import XApi from './api.vue'; import MkButton from '../../components/ui/button.vue'; import MkSwitch from '../../components/ui/switch.vue'; +import { notificationTypes } from '../../../types'; export default Vue.extend({ metaInfo() { @@ -114,14 +115,15 @@ export default Vue.extend({ }, async configure() { + const includingTypes = notificationTypes.filter(x => !this.$store.state.i.mutingNotificationTypes.includes(x)); this.$root.new(await import('../../components/notification-setting-window.vue').then(m => m.default), { - includingTypes: this.$store.state.i.includingNotificationTypes, + includingTypes, showGlobalToggle: false, }).$on('ok', async ({ includingTypes: value }: any) => { await this.$root.api('i/update', { - includingNotificationTypes: value, + mutingNotificationTypes: notificationTypes.filter(x => !value.includes(x)), }).then(i => { - this.$store.state.i.includingNotificationTypes = i.includingNotificationTypes; + this.$store.state.i.mutingNotificationTypes = i.mutingNotificationTypes; }).catch(err => { this.$root.dialog({ type: 'error', diff --git a/src/models/entities/user-profile.ts b/src/models/entities/user-profile.ts index 0eeed1b40eb64527aa1a9a6fee6e133889d988c2..7195c20ffe7164d9d6f28480efeb5a472439b5d0 100644 --- a/src/models/entities/user-profile.ts +++ b/src/models/entities/user-profile.ts @@ -162,9 +162,9 @@ export class UserProfile { @Column('enum', { enum: notificationTypes, array: true, - nullable: true, + default: [], }) - public includingNotificationTypes: typeof notificationTypes[number][] | null; + public mutingNotificationTypes: typeof notificationTypes[number][]; //#region Denormalized fields @Index() diff --git a/src/models/repositories/user.ts b/src/models/repositories/user.ts index b1b084b7406b30a73d16bbe0f382dbd5ba5c5dd1..7ea4d42bcb5d548cb073cc8df9cfc0b87644c0c2 100644 --- a/src/models/repositories/user.ts +++ b/src/models/repositories/user.ts @@ -248,7 +248,7 @@ export class UserRepository extends Repository<User> { hasPendingReceivedFollowRequest: this.getHasPendingReceivedFollowRequest(user.id), integrations: profile!.integrations, mutedWords: profile!.mutedWords, - includingNotificationTypes: profile?.includingNotificationTypes, + mutingNotificationTypes: profile?.mutingNotificationTypes, } : {}), ...(opts.includeSecrets ? { diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts index 327e303a66b71b076bd10125fe14ae19848298a6..2029f2b4b6c421eb1cabdcc94db00bdd312e66e3 100644 --- a/src/server/api/endpoints/i/update.ts +++ b/src/server/api/endpoints/i/update.ts @@ -149,7 +149,7 @@ export const meta = { validator: $.optional.arr($.arr($.str)) }, - includingNotificationTypes: { + mutingNotificationTypes: { validator: $.optional.arr($.str.or(notificationTypes as unknown as string[])) }, }, @@ -206,7 +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 (ps.mutingNotificationTypes !== undefined) profileUpdates.mutingNotificationTypes = ps.mutingNotificationTypes 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 7471c349eed62ccdc622bf2d39b536a50b2a6d39..5dddaa5727ae43b905c3ea9ad953be1800f4e8f2 100644 --- a/src/services/create-notification.ts +++ b/src/services/create-notification.ts @@ -16,7 +16,7 @@ export async function createNotification( const profile = await UserProfiles.findOne({ userId: notifieeId }); - const isMuted = !(profile?.includingNotificationTypes == null || profile?.includingNotificationTypes.includes(type)); + const isMuted = profile?.mutingNotificationTypes.includes(type); // Create notification const notification = await Notifications.save({