Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ファイルミュート #4827

Merged
merged 3 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,8 @@ admin/views/instanceblocks.vue:
ignoredInstances-info: "Instances that don't send/receive and fetch. One host per line. You can use /RegExp/."
selfSilencedInstances: "Self-silenced instances"
selfSilencedInstances-info: "Instances to deliver with maximum visibility home. One host per line. You can use /RegExp/."
mutedFiles: "Attachments to mute"
mutedFiles-info: "Mute the specified file if it is attached. MD5 lower case."
exposeHome: "If fetched from remote, max visibility to home."
exposeHome-info: "If posts are retrieved from instances with no followers, etc., set the maximum visibility to Home."

Expand Down
2 changes: 2 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,8 @@ admin/views/instanceblocks.vue:
ignoredInstances-info: "送受信と取得を行わないインスタンス。1行に1ホスト記述します。/正規表現/ が使えます。"
selfSilencedInstances: "セルフサイレンスするインスタンス"
selfSilencedInstances-info: "最大公開範囲ホームで配信するインスタンス。1行に1ホスト記述します。/正規表現/ が使えます。"
mutedFiles: "ミュートする添付ファイル"
mutedFiles-info: "指定のファイルが投稿に添付されている場合にミュートします。MD5小文字。"
exposeHome: 取得されるときの最大公開範囲はホームにする
exposeHome-info: "フォロワーのいないインスタンスなどから投稿を取得されるときの最大公開範囲をホームにします。"

Expand Down
9 changes: 9 additions & 0 deletions src/client/app/admin/views/instanceblocks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
<ui-info>{{ $t('selfSilencedInstances-info') }}</ui-info>
</section>

<section>
<header>{{ $t('mutedFiles') }}</header>
<ui-textarea v-model="mutedFiles"></ui-textarea>
<ui-info>{{ $t('mutedFiles-info') }}</ui-info>
</section>

<section>
<ui-switch v-model="exposeHome">{{ $t('exposeHome') }}</ui-switch>
<ui-info>{{ $t('exposeHome-info') }}</ui-info>
Expand All @@ -38,6 +44,7 @@ export default defineComponent({
$root: getCurrentInstance() as any,
blockedInstances: '',
selfSilencedInstances: '',
mutedFiles: '',
exposeHome: false,
};
},
Expand All @@ -49,13 +56,15 @@ export default defineComponent({
this.$root.api('admin/meta').then((meta: any) => {
this.blockedInstances = meta.blockedInstances.join('\n');
this.selfSilencedInstances = meta.selfSilencedInstances.join('\n');
this.mutedFiles = meta.mutedFiles.join('\n');
this.exposeHome = meta.exposeHome;
});
},
save() {
this.$root.api('admin/update-meta', {
blockedInstances: this.blockedInstances ? this.blockedInstances.split('\n') : [],
selfSilencedInstances: this.selfSilencedInstances ? this.selfSilencedInstances.split('\n') : [],
mutedFiles: this.mutedFiles ? this.mutedFiles.split('\n') : [],
exposeHome: !!this.exposeHome,
}).then(() => {
this.$root.dialog({
Expand Down
1 change: 1 addition & 0 deletions src/misc/fetch-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const defaultMeta: any = {
hidedTags: [],
blockedInstances: [],
selfSilencedInstances: [],
mutedFiles: [],
exposeHome: false,
stats: {
// Object.assignじゃマージされない
Expand Down
1 change: 1 addition & 0 deletions src/models/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export type IMeta = {
hidedTags?: string[];
blockedInstances?: string[];
selfSilencedInstances?: string[];
mutedFiles?: string[];
exposeHome?: boolean;
mascotImageUrl?: string;
bannerUrl?: string;
Expand Down
1 change: 1 addition & 0 deletions src/server/api/endpoints/admin/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export default define(meta, async (ps, me) => {
response.hidedTags = instance.hidedTags;
response.blockedInstances = instance.blockedInstances;
response.selfSilencedInstances = instance.selfSilencedInstances;
response.mutedFiles = instance.mutedFiles;
response.exposeHome = instance.exposeHome;
response.recaptchaSecretKey = instance.recaptchaSecretKey;
response.proxyAccount = instance.proxyAccount;
Expand Down
13 changes: 12 additions & 1 deletion src/server/api/endpoints/admin/update-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ export const meta = {
}
},

mutedFiles: {
validator: $.optional.nullable.arr($.str),
desc: {
'ja-JP': 'ミュートする添付ファイル'
}
},

exposeHome: {
validator: $.optional.boolean,
desc: {
Expand Down Expand Up @@ -391,6 +398,10 @@ export default define(meta, async (ps) => {
set.selfSilencedInstances = ps.selfSilencedInstances.map(x => x.trim()).filter(x => x !== '').map(x => toApHost(x));
}

if (Array.isArray(ps.mutedFiles)) {
set.mutedFiles = ps.mutedFiles.map(x => x.trim()).filter(x => x !== '');
}

if (typeof ps.exposeHome === 'boolean') {
set.exposeHome = ps.exposeHome;
}
Expand Down Expand Up @@ -543,7 +554,7 @@ export default define(meta, async (ps) => {
$set: set
}, { upsert: true });

if (set.blockedInstances || set.selfSilencedInstances) {
if (set.blockedInstances || set.selfSilencedInstances || set.mutedFiles) {
publishInstanceModUpdated();
}

Expand Down
18 changes: 18 additions & 0 deletions src/services/instance-moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let blockedHostsRegExp: Set<RegExp>;
let selfSilencedHosts: Set<string>;
let selfSilencedHostsRegExp: Set<RegExp>;
let closedHosts: Set<string>;
let mutedFiles: Set<string>;

export async function isBlockedHost(host: string | null) {
if (host == null) return false;
Expand All @@ -31,6 +32,12 @@ export async function isSelfSilencedHost(host: string | null) {
return false;
}

export async function isMutedFile(md5: string | null | undefined) {
if (md5 == null) return false;
if (!mutedFiles) await Update();
return mutedFiles?.has(md5);
}

export async function isClosedHost(host: string | null) {
if (host == null) return false;
if (!closedHosts) await Update();
Expand Down Expand Up @@ -80,6 +87,17 @@ async function Update() {
selfSilencedHostsRegExp = regExps;
}

// mutedFiles from meta
{
const literals = new Set<string>();

for (const b of (meta.mutedFiles || [])) {
literals.add(b);
}

mutedFiles = literals;
}

// closed from instance
const closed = await Instance.find({
isMarkedAsClosed: true
Expand Down
13 changes: 13 additions & 0 deletions src/services/note/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import Following from '../../models/following';
import { IActivity } from '../../remote/activitypub/type';
import { normalizeTag } from '../../misc/normalize-tag';
import * as ms from 'ms';
import { isMutedFile } from '../instance-moderation';
import Logger from '../logger';
export const noteLogger = new Logger('note');


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

Expand Down Expand Up @@ -84,6 +88,15 @@ class NotificationManager {
return;
}

if (this.queue.length === 0) return;

for (const atc of this.note._files || []) {
if (await isMutedFile(atc.md5)) {
noteLogger.info(`muted file: note=${this.note._id} md5=${atc.md5}`);
return;
}
}

for (const x of this.queue) {
// ミュートされてたらスキップ
const mute = await getMute(x.target, this.notifier._id);
Expand Down
Loading