Merge branch 'develop' into vue3

This commit is contained in:
syuilo 2020-09-19 13:57:38 +09:00
commit f661cb765a
13 changed files with 46 additions and 21 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

@ -65,7 +65,13 @@ export default defineComponent({
}
},
created() {
this.hide = this.image.isSensitive && !this.$store.state.device.alwaysShowNsfw;
// Plugin:register_note_view_interruptor 使watch
this.$watch('image', () => {
this.hide = this.image.isSensitive && !this.$store.state.device.alwaysShowNsfw;
}, {
deep: true,
immediate: true,
});
},
methods: {
onClick() {

View File

@ -59,7 +59,7 @@ export default defineComponent({
computed: {
allIncludeTypes() {
return this.includeTypes ?? this.$store.state.i.includingNotificationTypes;
return this.includeTypes ?? notificationTypes.filter(x => !this.$store.state.i.mutingNotificationTypes.includes(x));
}
},
@ -67,7 +67,7 @@ export default defineComponent({
includeTypes() {
this.reload();
},
'$store.state.i.includingNotificationTypes'() {
'$store.state.i.mutingNotificationTypes'() {
if (this.includeTypes === null) {
this.reload();
}
@ -85,8 +85,7 @@ export default defineComponent({
methods: {
onNotification(notification) {
//
const isMuted = !!this.allIncludeTypes && !this.allIncludeTypes.includes(notification.type);
const isMuted = !this.allIncludeTypes.includes(notification.type);
if (isMuted || document.visibilityState === 'visible') {
os.stream.send('readNotification', {
id: notification.id

View File

@ -156,8 +156,7 @@ export default defineComponent({
},
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;
}

View File

@ -326,8 +326,7 @@ export default defineComponent({
},
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') {

View File

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

View File

@ -16,6 +16,6 @@ export function genId(date?: Date): string {
case 'meidg': return genMeidg(date);
case 'ulid': return ulid(date.getTime());
case 'objectid': return genObjectId(date);
default: throw new Error('unknown id generation method');
default: throw new Error('unrecognized id generation method');
}
}

View File

@ -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()

View File

@ -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 ? {

View File

@ -66,6 +66,6 @@ async function performOneActivity(actor: IRemoteUser, activity: IObject): Promis
} else if (isFlag(activity)) {
await flag(actor, activity);
} else {
apLogger.warn(`unknown activity type: ${(activity as any).type}`);
apLogger.warn(`unrecognized activity type: ${(activity as any).type}`);
}
}

View File

@ -20,7 +20,7 @@ export default class Resolver {
if (isCollectionOrOrderedCollection(collection)) {
return collection;
} else {
throw new Error(`unknown collection type: ${collection.type}`);
throw new Error(`unrecognized collection type: ${collection.type}`);
}
}

View File

@ -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;

View File

@ -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({