Skip to content

Commit

Permalink
Partially Revert "Hard mute (misskey-dev#12376)"
Browse files Browse the repository at this point in the history
This reverts commit 864827f partially.

型定義に関する実装はそのままに
一部型定義に合わない実装の修正
  • Loading branch information
u1-liquid committed Nov 25, 2023
1 parent 77e676e commit d9efde9
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 107 deletions.
1 change: 0 additions & 1 deletion locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,6 @@ export interface Locale {
"smtpSecureInfo": string;
"testEmail": string;
"wordMute": string;
"hardWordMute": string;
"regexpError": string;
"regexpErrorDescription": string;
"instanceMute": string;
Expand Down
1 change: 0 additions & 1 deletion locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ smtpSecure: "SMTP 接続に暗黙的なSSL/TLSを使用する"
smtpSecureInfo: "STARTTLS使用時はオフにします。"
testEmail: "配信テスト"
wordMute: "ワードミュート"
hardWordMute: "ハードワードミュート"
regexpError: "正規表現エラー"
regexpErrorDescription: "{tab}ワードミュートの{line}行目の正規表現にエラーが発生しました:"
instanceMute: "サーバーミュート"
Expand Down
14 changes: 7 additions & 7 deletions packages/backend/migration/1700383825690-hard-mute.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export class HardMute1700383825690 {
name = 'HardMute1700383825690'
name = 'HardMute1700383825690'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "user_profile" ADD "hardMutedWords" jsonb NOT NULL DEFAULT '[]'`);
}
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "user_profile" ADD "hardMutedWords" jsonb NOT NULL DEFAULT '[]'`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "hardMutedWords"`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "hardMutedWords"`);
}
}
35 changes: 35 additions & 0 deletions packages/backend/migration/1700880703631-revert-hard-mute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

export class RevertHardMute1700880703631 {
name = 'RevertHardMute1700880703631';

async up(queryRunner) {
// migrate hardMutedWords to mutedWords
await queryRunner.query(`
update "user_profile"
set "mutedWords" = (
select jsonb_agg(elem order by ord)
from (
select elem, ord
from (
select elem, row_number() over () as ord
from jsonb_array_elements("mutedWords") as elem
) as muted
union
select elem, 1000000 + row_number() over ()
from jsonb_array_elements("hardMutedWords") as elem
where elem not in (select jsonb_array_elements("mutedWords"))
) as combined
)
where "hardMutedWords" <> '[]'
`);
await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "hardMutedWords"`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "user_profile" ADD "hardMutedWords" jsonb NOT NULL DEFAULT '[]'`);
}
}
1 change: 0 additions & 1 deletion packages/backend/src/core/entities/UserEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ export class UserEntityService implements OnModuleInit {
hasPendingReceivedFollowRequest: this.getHasPendingReceivedFollowRequest(user.id),
unreadNotificationsCount: notificationsInfo?.unreadCount,
mutedWords: profile!.mutedWords,
hardMutedWords: profile!.hardMutedWords,
mutedInstances: profile!.mutedInstances,
mutingNotificationTypes: [], // 後方互換性のため
notificationRecieveConfig: profile!.notificationRecieveConfig,
Expand Down
5 changes: 0 additions & 5 deletions packages/backend/src/models/UserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ export class MiUserProfile {
})
public mutedWords: (string[] | string)[];

@Column('jsonb', {
default: [],
})
public hardMutedWords: (string[] | string)[];

@Column('jsonb', {
default: [],
comment: 'List of instances muted by the user.',
Expand Down
12 changes: 0 additions & 12 deletions packages/backend/src/models/json-schema/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,18 +534,6 @@ export const packedMeDetailedOnlySchema = {
},
},
},
hardMutedWords: {
type: 'array',
nullable: false, optional: false,
items: {
type: 'array',
nullable: false, optional: false,
items: {
type: 'string',
nullable: false, optional: false,
},
},
},
mutedInstances: {
type: 'array',
nullable: true, optional: false,
Expand Down
42 changes: 13 additions & 29 deletions packages/backend/src/server/api/endpoints/i/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type { UsersRepository, DriveFilesRepository, UserProfilesRepository, Pag
import type { MiLocalUser, MiUser } from '@/models/User.js';
import { birthdaySchema, descriptionSchema, locationSchema, nameSchema } from '@/models/User.js';
import type { MiUserProfile } from '@/models/UserProfile.js';
import { notificationTypes } from '@/types.js';
import { normalizeForSearch } from '@/misc/normalize-for-search.js';
import { langmap } from '@/misc/langmap.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
Expand Down Expand Up @@ -124,11 +123,6 @@ export const meta = {
},
} as const;

const muteWordsType = { type: 'array', items: { oneOf: [
{ type: 'array', items: { type: 'string' } },
{ type: 'string' }
] } } as const;

export const paramDef = {
type: 'object',
properties: {
Expand Down Expand Up @@ -177,8 +171,12 @@ export const paramDef = {
autoSensitive: { type: 'boolean' },
ffVisibility: { type: 'string', enum: ['public', 'followers', 'private'] },
pinnedPageId: { type: 'string', format: 'misskey:id', nullable: true },
mutedWords: muteWordsType,
hardMutedWords: muteWordsType,
mutedWords: { type: 'array', items: {
oneOf: [
{ type: 'array', items: { type: 'string' } },
{ type: 'string' }
]
} },
mutedInstances: { type: 'array', items: {
type: 'string',
} },
Expand Down Expand Up @@ -241,41 +239,27 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (ps.location !== undefined) profileUpdates.location = ps.location;
if (ps.birthday !== undefined) profileUpdates.birthday = ps.birthday;
if (ps.ffVisibility !== undefined) profileUpdates.ffVisibility = ps.ffVisibility;

function checkMuteWordCount(mutedWords: (string[] | string)[], limit: number) {
const length = mutedWords.length;
if (length > limit) {
if (ps.mutedWords !== undefined) {
const length = ps.mutedWords.length;
if (length > (await this.roleService.getUserPolicies(user.id)).wordMuteLimit) {
throw new ApiError(meta.errors.tooManyMutedWords);
}
}

function validateMuteWordRegex(mutedWords: (string[] | string)[]) {
for (const mutedWord of mutedWords) {
if (typeof mutedWord !== "string") continue;

const regexp = mutedWord.match(/^\/(.+)\/(.*)$/);
// validate regular expression syntax
ps.mutedWords.filter(x => !Array.isArray(x)).forEach(x => {
const regexp = RegExp(/^\/(.+)\/(.*)$/).exec(x as string);
if (!regexp) throw new ApiError(meta.errors.invalidRegexp);

try {
new RE2(regexp[1], regexp[2]);
} catch (err) {
throw new ApiError(meta.errors.invalidRegexp);
}
}
}

if (ps.mutedWords !== undefined) {
checkMuteWordCount(ps.mutedWords, (await this.roleService.getUserPolicies(user.id)).wordMuteLimit);
validateMuteWordRegex(ps.mutedWords);
});

profileUpdates.mutedWords = ps.mutedWords;
profileUpdates.enableWordMute = ps.mutedWords.length > 0;
}
if (ps.hardMutedWords !== undefined) {
checkMuteWordCount(ps.hardMutedWords, (await this.roleService.getUserPolicies(user.id)).wordMuteLimit);
validateMuteWordRegex(ps.hardMutedWords);
profileUpdates.hardMutedWords = ps.hardMutedWords;
}
if (ps.mutedInstances !== undefined) profileUpdates.mutedInstances = ps.mutedInstances;
if (ps.notificationRecieveConfig !== undefined) profileUpdates.notificationRecieveConfig = ps.notificationRecieveConfig;
if (typeof ps.isLocked === 'boolean') updates.isLocked = ps.isLocked;
Expand Down
1 change: 0 additions & 1 deletion packages/backend/test/e2e/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ describe('ユーザー', () => {
hasPendingReceivedFollowRequest: user.hasPendingReceivedFollowRequest,
unreadAnnouncements: user.unreadAnnouncements,
mutedWords: user.mutedWords,
hardMutedWords: user.hardMutedWords,
mutedInstances: user.mutedInstances,
mutingNotificationTypes: user.mutingNotificationTypes,
notificationRecieveConfig: user.notificationRecieveConfig,
Expand Down
6 changes: 2 additions & 4 deletions packages/frontend/src/components/MkNote.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<template>
<div
v-if="!hardMuted && !muted"
v-if="!muted"
v-show="!isDeleted"
ref="el"
v-hotkey="keymap"
Expand Down Expand Up @@ -133,7 +133,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</div>
</article>
</div>
<div v-else-if="!hardMuted" :class="$style.muted" @click="muted = false">
<div v-else :class="$style.muted" @click="muted = false">
<I18n :src="i18n.ts.userSaysSomething" tag="small">
<template #name>
<MkA v-user-preview="appearNote.userId" :to="userPage(appearNote.user)">
Expand Down Expand Up @@ -183,7 +183,6 @@ const props = withDefaults(defineProps<{
note: Misskey.entities.Note;
pinned?: boolean;
mock?: boolean;
withHardMute?: boolean;
}>(), {
mock: false,
});
Expand Down Expand Up @@ -241,7 +240,6 @@ const isLong = shouldCollapsed(appearNote, urls ?? []);
const collapsed = ref(appearNote.cw == null && isLong);
const isDeleted = ref(false);
const muted = ref(checkMute(appearNote, $i?.mutedWords));
const hardMuted = ref(props.withHardMute && checkMute(appearNote, $i?.hardMutedWords));
const translation = ref<any>(null);
const translating = ref(false);
const showTicker = (defaultStore.state.instanceTicker === 'always') || (defaultStore.state.instanceTicker === 'remote' && appearNote.user.instance);
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkNotes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SPDX-License-Identifier: AGPL-3.0-only
:ad="true"
:class="$style.notes"
>
<MkNote :key="note._featuredId_ || note._prId_ || note.id" :class="$style.note" :note="note" :withHardMute="true"/>
<MkNote :key="note._featuredId_ || note._prId_ || note.id" :class="$style.note" :note="note"/>
</MkDateSeparatedList>
</div>
</template>
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkNotifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<template #default="{ items: notifications }">
<MkDateSeparatedList v-slot="{ item: notification }" :class="$style.list" :items="notifications" :noGap="true">
<MkNote v-if="['reply', 'quote', 'mention'].includes(notification.type)" :key="notification.id" :note="notification.note" :withHardMute="true"/>
<MkNote v-if="['reply', 'quote', 'mention'].includes(notification.type)" :key="notification.id" :note="notification.note"/>
<XNotification v-else :key="notification.id" :notification="notification" :withTime="true" :full="true" class="_panel"/>
</MkDateSeparatedList>
</template>
Expand Down
18 changes: 1 addition & 17 deletions packages/frontend/src/pages/settings/mute-block.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #icon><i class="ti ti-message-off"></i></template>
<template #label>{{ i18n.ts.wordMute }}</template>

<XWordMute :muted="$i!.mutedWords" @save="saveMutedWords"/>
</MkFolder>

<MkFolder>
<template #icon><i class="ti ti-message-off"></i></template>
<template #label>{{ i18n.ts.hardWordMute }}</template>

<XWordMute :muted="$i!.hardMutedWords" @save="saveHardMutedWords"/>
<XWordMute/>
</MkFolder>

<MkFolder>
Expand Down Expand Up @@ -136,7 +129,6 @@ import { definePageMetadata } from '@/scripts/page-metadata.js';
import MkUserCardMini from '@/components/MkUserCardMini.vue';
import * as os from '@/os.js';
import { infoImageUrl } from '@/instance.js';
import { $i } from '@/account.js';
import MkFolder from '@/components/MkFolder.vue';
const renoteMutingPagination = {
Expand Down Expand Up @@ -215,14 +207,6 @@ async function toggleBlockItem(item) {
}
}
async function saveMutedWords(mutedWords: (string | string[])[]) {
await os.api('i/update', { mutedWords });
}
async function saveHardMutedWords(hardMutedWords: (string | string[])[]) {
await os.api('i/update', { hardMutedWords });
}
const headerActions = $computed(() => []);
const headerTabs = $computed(() => []);
Expand Down
36 changes: 16 additions & 20 deletions packages/frontend/src/pages/settings/mute-block.word-mute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,33 @@ import { ref, watch } from 'vue';
import MkTextarea from '@/components/MkTextarea.vue';
import MkButton from '@/components/MkButton.vue';
import * as os from '@/os.js';
import { $i } from '@/account.js';
import { i18n } from '@/i18n.js';
const props = defineProps<{
muted: (string[] | string)[];
}>();
const emit = defineEmits<{
(ev: 'save', value: (string[] | string)[]): void;
}>();
const render = (mutedWords) => mutedWords.map(x => {
const render = (mutedWords?: (string | string[])[]) => mutedWords?.map(x => {
if (Array.isArray(x)) {
return x.join(' ');
} else {
return x;
}
}).join('\n');
const mutedWords = ref(render(props.muted));
const mutedWords = ref(render($i?.mutedWords));
const changed = ref(false);
watch(mutedWords, () => {
changed.value = true;
});
async function save() {
const parseMutes = (mutes) => {
// split into lines, remove empty lines and unnecessary whitespace
let lines = mutes.trim().split('\n').map(line => line.trim()).filter(line => line !== '');
const parseMutes = (mutes?: string): (string | string[])[] => {
const parsed: (string | string[])[] = [];
if (!mutes) return parsed;
// split into lines, remove empty lines and unnecessary whitespace
// check each line if it is a RegExp or not
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const regexp = line.match(/^\/(.+)\/(.*)$/);
for (const [i, line] of mutes.trim().split('\n').map(line => line.trim()).filter(line => line !== '').entries()) {
const regexp = RegExp(/^\/(.+)\/(.*)$/).exec(line);
if (regexp) {
// check that the RegExp is valid
try {
Expand All @@ -69,23 +62,26 @@ async function save() {
// re-throw error so these invalid settings are not saved
throw err;
}
parsed.push(line);
} else {
lines[i] = line.split(' ');
parsed.push(line.split(' '));
}
}
return lines;
return parsed;
};
let parsed;
let parsed: (string | string[])[];
try {
parsed = parseMutes(mutedWords.value);
} catch (err) {
// already displayed error message in parseMutes
return;
}
emit('save', parsed);
await os.api('i/update', {
mutedWords: parsed,
});
changed.value = false;
}
Expand Down
Loading

0 comments on commit d9efde9

Please sign in to comment.