This commit is contained in:
syuilo 2020-09-18 22:18:21 +09:00 committed by GitHub
parent f104e9b6cc
commit df71dbb024
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 17 deletions

View file

@ -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`);
}
}

View file

@ -328,8 +328,7 @@ export default Vue.extend({
}, },
async onNotification(notification) { async onNotification(notification) {
const t = this.$store.state.i.includingNotificationTypes; if (this.$store.state.i.mutingNotificationTypes.includes(notification.type)) {
if (!!t && !t.includes(notification.type)) {
return; return;
} }
if (document.visibilityState === 'visible') { if (document.visibilityState === 'visible') {

View file

@ -58,7 +58,7 @@ export default Vue.extend({
computed: { computed: {
allIncludeTypes() { 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() { includeTypes() {
this.reload(); this.reload();
}, },
'$store.state.i.includingNotificationTypes'() { '$store.state.i.mutingNotificationTypes'() {
if (this.includeTypes === null) { if (this.includeTypes === null) {
this.reload(); this.reload();
} }
@ -84,8 +84,7 @@ export default Vue.extend({
methods: { methods: {
onNotification(notification) { onNotification(notification) {
// const isMuted = !this.allIncludeTypes.includes(notification.type);
const isMuted = !!this.allIncludeTypes && !this.allIncludeTypes.includes(notification.type);
if (isMuted || document.visibilityState === 'visible') { if (isMuted || document.visibilityState === 'visible') {
this.$root.stream.send('readNotification', { this.$root.stream.send('readNotification', {
id: notification.id id: notification.id

View file

@ -161,8 +161,7 @@ export default Vue.extend({
}, },
async onNotification(notification) { async onNotification(notification) {
const t = this.$store.state.i.includingNotificationTypes; if (this.$store.state.i.mutingNotificationTypes.includes(notification.type)) {
if (!!t && !t.includes(notification.type)) {
return; return;
} }

View file

@ -58,6 +58,7 @@ import XIntegration from './integration.vue';
import XApi from './api.vue'; import XApi from './api.vue';
import MkButton from '../../components/ui/button.vue'; import MkButton from '../../components/ui/button.vue';
import MkSwitch from '../../components/ui/switch.vue'; import MkSwitch from '../../components/ui/switch.vue';
import { notificationTypes } from '../../../types';
export default Vue.extend({ export default Vue.extend({
metaInfo() { metaInfo() {
@ -114,14 +115,15 @@ export default Vue.extend({
}, },
async configure() { 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), { this.$root.new(await import('../../components/notification-setting-window.vue').then(m => m.default), {
includingTypes: this.$store.state.i.includingNotificationTypes, includingTypes,
showGlobalToggle: false, showGlobalToggle: false,
}).$on('ok', async ({ includingTypes: value }: any) => { }).$on('ok', async ({ includingTypes: value }: any) => {
await this.$root.api('i/update', { await this.$root.api('i/update', {
includingNotificationTypes: value, mutingNotificationTypes: notificationTypes.filter(x => !value.includes(x)),
}).then(i => { }).then(i => {
this.$store.state.i.includingNotificationTypes = i.includingNotificationTypes; this.$store.state.i.mutingNotificationTypes = i.mutingNotificationTypes;
}).catch(err => { }).catch(err => {
this.$root.dialog({ this.$root.dialog({
type: 'error', type: 'error',

View file

@ -162,9 +162,9 @@ export class UserProfile {
@Column('enum', { @Column('enum', {
enum: notificationTypes, enum: notificationTypes,
array: true, array: true,
nullable: true, default: [],
}) })
public includingNotificationTypes: typeof notificationTypes[number][] | null; public mutingNotificationTypes: typeof notificationTypes[number][];
//#region Denormalized fields //#region Denormalized fields
@Index() @Index()

View file

@ -248,7 +248,7 @@ export class UserRepository extends Repository<User> {
hasPendingReceivedFollowRequest: this.getHasPendingReceivedFollowRequest(user.id), hasPendingReceivedFollowRequest: this.getHasPendingReceivedFollowRequest(user.id),
integrations: profile!.integrations, integrations: profile!.integrations,
mutedWords: profile!.mutedWords, mutedWords: profile!.mutedWords,
includingNotificationTypes: profile?.includingNotificationTypes, mutingNotificationTypes: profile?.mutingNotificationTypes,
} : {}), } : {}),
...(opts.includeSecrets ? { ...(opts.includeSecrets ? {

View file

@ -149,7 +149,7 @@ export const meta = {
validator: $.optional.arr($.arr($.str)) validator: $.optional.arr($.arr($.str))
}, },
includingNotificationTypes: { mutingNotificationTypes: {
validator: $.optional.arr($.str.or(notificationTypes as unknown as string[])) 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.mutedWords = ps.mutedWords;
profileUpdates.enableWordMute = ps.mutedWords.length > 0; 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.isLocked === 'boolean') updates.isLocked = ps.isLocked;
if (typeof ps.isBot === 'boolean') updates.isBot = ps.isBot; if (typeof ps.isBot === 'boolean') updates.isBot = ps.isBot;
if (typeof ps.carefulBot === 'boolean') profileUpdates.carefulBot = ps.carefulBot; if (typeof ps.carefulBot === 'boolean') profileUpdates.carefulBot = ps.carefulBot;

View file

@ -16,7 +16,7 @@ export async function createNotification(
const profile = await UserProfiles.findOne({ userId: notifieeId }); const profile = await UserProfiles.findOne({ userId: notifieeId });
const isMuted = !(profile?.includingNotificationTypes == null || profile?.includingNotificationTypes.includes(type)); const isMuted = profile?.mutingNotificationTypes.includes(type);
// Create notification // Create notification
const notification = await Notifications.save({ const notification = await Notifications.save({