Added settable config for muted instances

This commit is contained in:
puffaboo 2021-08-26 16:38:32 +01:00
parent dad6a77645
commit ffdbf751df
8 changed files with 127 additions and 0 deletions

View file

@ -59,6 +59,7 @@ mention: "Mention"
mentions: "Mentions"
directNotes: "Direct notes"
importAndExport: "Import / Export"
instanceMute: "Instance Mutes"
import: "Import"
export: "Export"
files: "Files"
@ -957,6 +958,11 @@ _wordMute:
soft: "Soft"
hard: "Hard"
mutedNotes: "Muted notes"
_instanceMute:
instanceMuteDescription: "Will mute any notes/renotes from the listed instances, including a user replying to a user from a muted instance."
instanceMuteDescription2: "Separate with newlines"
title: "Hides notes from listed instances"
heading: "List of instances to be muted"
_theme:
explore: "Explore Themes"
install: "Install a theme"

View file

@ -588,6 +588,7 @@ smtpSecure: "SMTP 接続に暗黙的なSSL/TLSを使用する"
smtpSecureInfo: "STARTTLS使用時はオフにします。"
testEmail: "配信テスト"
wordMute: "ワードミュート"
instanceMute: "Instance Mutes"
userSaysSomething: "{name}が何かを言いました"
makeActive: "アクティブにする"
display: "表示"
@ -976,6 +977,12 @@ _wordMute:
hard: "ハード"
mutedNotes: "ミュートされたノート"
_instanceMute:
instanceMuteDescription: "Will mute any notes/renotes from the listed instances, including a user replying to a user from a muted instance."
instanceMuteDescription2: "Separate with newlines"
title: "Hides notes from listed instances"
heading: "List of instances to be muted"
_theme:
explore: "テーマを探す"
install: "テーマのインストール"

View file

@ -0,0 +1,15 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class userInstanceBlocks1629968054000 implements MigrationInterface {
name = 'userInstanceBlocks1629968054000'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user_profile" ADD "mutedInstances" jsonb NOT NULL DEFAULT '[]'`);
await queryRunner.query(`COMMENT ON COLUMN "user_profile"."mutedInstances" IS 'List of instances muted by the user.'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "mutedInstances"`);
}
}

View file

@ -35,6 +35,7 @@
<FormLink :active="page === 'import-export'" replace to="/settings/import-export"><template #icon><i class="fas fa-boxes"></i></template>{{ $ts.importAndExport }}</FormLink>
<FormLink :active="page === 'mute-block'" replace to="/settings/mute-block"><template #icon><i class="fas fa-ban"></i></template>{{ $ts.muteAndBlock }}</FormLink>
<FormLink :active="page === 'word-mute'" replace to="/settings/word-mute"><template #icon><i class="fas fa-comment-slash"></i></template>{{ $ts.wordMute }}</FormLink>
<FormLink :active="page === 'instance-mute'" replace to="/settings/instance-mute"><template #icon><i class="fas fa-volume-mute"></i></template>{{ $ts.instanceMute }}</FormLink>
<FormLink :active="page === 'api'" replace to="/settings/api"><template #icon><i class="fas fa-key"></i></template>API</FormLink>
<FormLink :active="page === 'other'" replace to="/settings/other"><template #icon><i class="fas fa-ellipsis-h"></i></template>{{ $ts.other }}</FormLink>
</FormGroup>
@ -108,6 +109,7 @@ export default defineComponent({
case 'notifications': return defineAsyncComponent(() => import('./notifications.vue'));
case 'mute-block': return defineAsyncComponent(() => import('./mute-block.vue'));
case 'word-mute': return defineAsyncComponent(() => import('./word-mute.vue'));
case 'instance-mute': return defineAsyncComponent(() => import('./instance-mute.vue'));
case 'integration': return defineAsyncComponent(() => import('./integration.vue'));
case 'security': return defineAsyncComponent(() => import('./security.vue'));
case '2fa': return defineAsyncComponent(() => import('./2fa.vue'));

View file

@ -0,0 +1,82 @@
<template>
<div>
<FormBase>
<div class="_formItem">
<FormInfo>{{ $ts._instanceMute.title}}</FormInfo>
<FormTextarea v-model:value="instanceMutes">
<span>{{$ts._instanceMute.heading}}</span>
<template #desc>{{ $ts._instanceMute.instanceMuteDescription}}<br>{{$ts._instanceMute.instanceMuteDescription2}}</template>
</FormTextarea>
</div>
<FormButton @click="save()" primary inline :disabled="!changed"><i class="fas fa-save"></i> {{ $ts.save }}</FormButton>
</FormBase>
</div>
</template>
<script>
import { defineComponent } from 'vue'
import FormBase from '@client/components/form/base.vue';
import FormTextarea from '@client/components/form/textarea.vue';
import FormInfo from '@client/components/form/info.vue';
import FormKeyValueView from '@client/components/form/key-value-view.vue';
import FormButton from '@client/components/form/button.vue';
import * as os from '@client/os';
import number from '@client/filters/number';
import * as symbols from '@client/symbols';
export default defineComponent({
components: {
FormBase,
FormButton,
FormTextarea,
FormKeyValueView,
FormInfo,
},
emits: ['info'],
data() {
return {
[symbols.PAGE_INFO]: {
title: this.$ts.instanceMute,
icon: 'fas fa-volume-mute'
},
tab: 'soft',
instanceMutes: '',
changed: false,
}
},
watch: {
instanceMutes: {
handler() {
this.changed = true;
},
deep: true
},
},
mounted() {
this.$emit('info', this[symbols.PAGE_INFO]);
},
async created() {
console.log(this.$i);
this.instanceMutes = this.$i.mutedInstances.join('\n');
},
methods: {
async save() {
let mutes = this.instanceMutes.trim().split('\n');
console.log(mutes);
await os.api('i/update', {
mutedInstances: mutes,
});
this.changed = false;
},
number //?
}
})
</script>

View file

@ -178,6 +178,11 @@ export class UserProfile {
})
public mutedWords: string[][];
@Column('jsonb', {
default: []
})
public mutedInstances: string[];
@Column('enum', {
enum: notificationTypes,
array: true,

View file

@ -270,6 +270,7 @@ export class UserRepository extends Repository<User> {
hasPendingReceivedFollowRequest: this.getHasPendingReceivedFollowRequest(user.id),
integrations: profile!.integrations,
mutedWords: profile!.mutedWords,
mutedInstances: profile!.mutedInstances,
mutingNotificationTypes: profile!.mutingNotificationTypes,
emailNotificationTypes: profile!.emailNotificationTypes,
} : {}),
@ -617,6 +618,10 @@ export const packedUserSchema = {
type: 'array' as const,
nullable: false as const, optional: true as const
},
mutedInstances: {
type: 'array' as const,
nullable: false as const, optional: true as const
},
mutingNotificationTypes: {
type: 'array' as const,
nullable: false as const, optional: true as const

View file

@ -108,6 +108,10 @@ export const meta = {
validator: $.optional.arr($.arr($.str))
},
mutedInstances: {
validator: $.optional.arr($.str)
},
mutingNotificationTypes: {
validator: $.optional.arr($.str.or(notificationTypes as unknown as string[]))
},
@ -176,6 +180,7 @@ export default define(meta, async (ps, _user, token) => {
profileUpdates.mutedWords = ps.mutedWords;
profileUpdates.enableWordMute = ps.mutedWords.length > 0;
}
if (ps.mutedInstances !== undefined) profileUpdates.mutedInstances = ps.mutedInstances;
if (ps.mutingNotificationTypes !== undefined) profileUpdates.mutingNotificationTypes = ps.mutingNotificationTypes as typeof notificationTypes[number][];
if (typeof ps.isLocked === 'boolean') updates.isLocked = ps.isLocked;
if (typeof ps.isExplorable === 'boolean') updates.isExplorable = ps.isExplorable;