Skip to content

Commit

Permalink
enhance: コントロールパネルのモデレーションからスパムブロックの設定を変更できるように
Browse files Browse the repository at this point in the history
  • Loading branch information
hideki0403 committed Feb 18, 2024
1 parent fd1d125 commit 5f97b4b
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 2 deletions.
8 changes: 8 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5216,6 +5216,14 @@ export interface Locale extends ILocale {
* スワイプしてタブを切り替える
*/
"enableHorizontalSwipe": string;
/**
* 荒らしの可能性があるユーザーからのメンションをブロックする
*/
"blockMentionsFromUnfamiliarRemoteUsers": string;
/**
* このサーバーからのフォロワーがいないリモートユーザーの、メンションを含むノートをブロックするようにします。
*/
"blockMentionsFromUnfamiliarRemoteUsersDescription": string;
"_bubbleGame": {
/**
* 遊び方
Expand Down
2 changes: 2 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,8 @@ hemisphere: "お住まいの地域"
withSensitive: "センシティブなファイルを含むノートを表示"
userSaysSomethingSensitive: "{name}のセンシティブなファイルを含む投稿"
enableHorizontalSwipe: "スワイプしてタブを切り替える"
blockMentionsFromUnfamiliarRemoteUsers: "荒らしの可能性があるユーザーからのメンションをブロックする"
blockMentionsFromUnfamiliarRemoteUsersDescription: "このサーバーからのフォロワーがいないリモートユーザーの、メンションを含むノートをブロックするようにします。"

_bubbleGame:
howToPlay: "遊び方"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class BlockMentionsFromUnfamiliarRemoteUsers1708231797959 {
name = 'BlockMentionsFromUnfamiliarRemoteUsers1708231797959'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "blockMentionsFromUnfamiliarRemoteUsers" boolean NOT NULL DEFAULT true`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "blockMentionsFromUnfamiliarRemoteUsers"`);
}
}
12 changes: 10 additions & 2 deletions packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ import { UtilityService } from '@/core/UtilityService.js';
import { UserBlockingService } from '@/core/UserBlockingService.js';
import { isReply } from '@/misc/is-reply.js';
import { trackPromise } from '@/misc/promise-tracker.js';
import { IdentifiableError } from '@/misc/identifiable-error.js';
import { LoggerService } from '@/core/LoggerService.js';
import type Logger from '@/logger.js';

type NotificationType = 'reply' | 'renote' | 'note' | 'quote' | 'mention';

Expand Down Expand Up @@ -154,6 +157,8 @@ export class NoteCreateService implements OnApplicationShutdown {

public static ContainsProhibitedWordsError = class extends Error {};

private logger: Logger;

constructor(
@Inject(DI.config)
private config: Config,
Expand Down Expand Up @@ -221,7 +226,10 @@ export class NoteCreateService implements OnApplicationShutdown {
private instanceChart: InstanceChart,
private utilityService: UtilityService,
private userBlockingService: UserBlockingService,
) { }
private loggerService: LoggerService,
) {
this.logger = this.loggerService.getLogger('note-create-service');
}

@bindThis
public async create(user: {
Expand Down Expand Up @@ -363,7 +371,7 @@ export class NoteCreateService implements OnApplicationShutdown {

const willCauseNotification = mentionedUsers.filter(u => u.host === null).length > 0 || data.reply?.userHost === null || data.renote?.userHost === null;

if (process.env.MISSKEY_BLOCK_MENTIONS_FROM_UNFAMILIAR_REMOTE_USERS === 'true' && user.host !== null && willCauseNotification) {
if (meta.blockMentionsFromUnfamiliarRemoteUsers && user.host !== null && willCauseNotification) {
const userEntity = await this.usersRepository.findOneBy({ id: user.id });
if ((userEntity?.followersCount ?? 0) === 0) {
this.logger.error('Request rejected because user has no local followers', { user: user.id, note: data });
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/models/Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,9 @@ export class MiMeta {
default: 20,
})
public ageRestrictionThreshold: number;

@Column('boolean', {
default: true,
})
public blockMentionsFromUnfamiliarRemoteUsers: boolean;
}
5 changes: 5 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ export const meta = {
type: 'string',
optional: false, nullable: false,
},
blockMentionsFromUnfamiliarRemoteUsers: {
type: 'boolean',
optional: false, nullable: false,
},
},
},
} as const;
Expand Down Expand Up @@ -685,6 +689,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
disableEntranceFeatureTimeline: instance.disableEntranceFeatureTimeline,
enableAgeRestriction: instance.enableAgeRestriction,
ageRestrictionThreshold: instance.ageRestrictionThreshold,
blockMentionsFromUnfamiliarRemoteUsers: instance.blockMentionsFromUnfamiliarRemoteUsers,
};
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export const paramDef = {
disableEntranceFeatureTimeline: { type: 'boolean' },
enableAgeRestriction: { type: 'boolean' },
ageRestrictionThreshold: { type: 'integer' },
blockMentionsFromUnfamiliarRemoteUsers: { type: 'boolean' },
silencedHosts: {
type: 'array',
nullable: true,
Expand Down Expand Up @@ -683,6 +684,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.bannedEmailDomains = ps.bannedEmailDomains;
}

if (ps.blockMentionsFromUnfamiliarRemoteUsers !== undefined) {
set.blockMentionsFromUnfamiliarRemoteUsers = ps.blockMentionsFromUnfamiliarRemoteUsers;
}

const before = await this.metaService.fetch(true);

await this.metaService.update(set);
Expand Down
8 changes: 8 additions & 0 deletions packages/frontend/src/pages/admin/moderation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #label>{{ i18n.ts.emailRequiredForSignup }}</template>
</MkSwitch>

<MkSwitch v-model="blockMentionsFromUnfamiliarRemoteUsers">
<template #label>{{ i18n.ts.blockMentionsFromUnfamiliarRemoteUsers }}<span class="_beta">{{ i18n.ts.originalFeature }}</span></template>
<template #caption>{{ i18n.ts.blockMentionsFromUnfamiliarRemoteUsersDescription }} Cherry-picked from Misskey.io (https://github.com/MisskeyIO/misskey/commit/82cc3987c13db4ad0da1589386027c222ce85ff8)</template>
</MkSwitch>

<MkSwitch v-if="enableRegistration" v-model="enableRegistrationLimit">
<template #label>{{ i18n.ts.enableRegistrationLimit }}<span class="_beta">{{ i18n.ts.originalFeature }}</span></template>
<template #caption>{{ i18n.ts.enableRegistrationLimitDescription }}</template>
Expand Down Expand Up @@ -129,6 +134,7 @@ const prohibitedWords = ref('');
const hiddenTags = ref('');
const tosUrl = ref<string | null>(null);
const privacyPolicyUrl = ref<string | null>(null);
const blockMentionsFromUnfamiliarRemoteUsers = ref(false);
async function init() {
const meta = await misskeyApi('admin/meta');
Expand All @@ -147,6 +153,7 @@ async function init() {
preservedUsernames.value = meta.preservedUsernames.join('\n');
tosUrl.value = meta.tosUrl;
privacyPolicyUrl.value = meta.privacyPolicyUrl;
blockMentionsFromUnfamiliarRemoteUsers.value = meta.blockMentionsFromUnfamiliarRemoteUsers;
}
function save() {
Expand All @@ -166,6 +173,7 @@ function save() {
prohibitedWords: prohibitedWords.value.split('\n'),
hiddenTags: hiddenTags.value.split('\n'),
preservedUsernames: preservedUsernames.value.split('\n'),
blockMentionsFromUnfamiliarRemoteUsers: blockMentionsFromUnfamiliarRemoteUsers.value,
}).then(() => {
fetchInstance();
});
Expand Down

0 comments on commit 5f97b4b

Please sign in to comment.