Skip to content

Commit

Permalink
chore: 特定のユーザに対するリプライはブロックしないように
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Jun 29, 2024
1 parent 3a31224 commit 751653a
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: anatawa12
* SPDX-License-Identifier: AGPL-3.0-only
*/

export class NirilaAllowedUnfamiliarRemoteUserIds1719664479666 {
name = 'NirilaAllowedUnfamiliarRemoteUserIds1719664479666'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "nirilaAllowedUnfamiliarRemoteUserIds" character varying(32) array NOT NULL DEFAULT '{}'`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "nirilaAllowedUnfamiliarRemoteUserIds"`);
}
}
22 changes: 21 additions & 1 deletion packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,27 @@ export class NoteCreateService implements OnApplicationShutdown {
|| (data.visibility === 'specified' && data.visibleUsers?.some(u => u.host === null))
|| data.reply?.userHost === null || (this.isRenote(data) && this.isQuote(data) && data.renote?.userHost === null) || false;

if (meta.nirilaBlockMentionsFromUnfamiliarRemoteUsers && user.host !== null && willCauseNotification) {
const isAllowedToCreateNotification = () => {
const targetUserIds: string[][] = [];
targetUserIds.push(mentionedUsers.filter(x => x.host == null).map(x => x.id))

Check failure on line 382 in packages/backend/src/core/NoteCreateService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

Missing semicolon
if (data.visibility === 'specified' && data.visibleUsers != null)
targetUserIds.push(data.visibleUsers.filter(x => x.host == null).map(x => x.id));

Check failure on line 384 in packages/backend/src/core/NoteCreateService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

Expected no linebreak before this statement
if (data.reply != null && data.reply.userHost == null)
targetUserIds.push([data.reply.userId]);

Check failure on line 386 in packages/backend/src/core/NoteCreateService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

Expected no linebreak before this statement
if (this.isRenote(data) && this.isQuote(data) && data.renote.userHost === null)
targetUserIds.push([data.renote.userId]);

Check failure on line 388 in packages/backend/src/core/NoteCreateService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

Expected no linebreak before this statement
const allowedIds = new Set(meta.nirilaAllowedUnfamiliarRemoteUserIds);
for (let targetUserIds1 of targetUserIds) {

Check failure on line 390 in packages/backend/src/core/NoteCreateService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

'targetUserIds1' is never reassigned. Use 'const' instead
for (let targetUserId of targetUserIds1) {

Check failure on line 391 in packages/backend/src/core/NoteCreateService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

'targetUserId' is never reassigned. Use 'const' instead
if (allowedIds.has(targetUserId)) {
return true;
}
}
}
return false;
}

Check failure on line 398 in packages/backend/src/core/NoteCreateService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

Missing semicolon

if (meta.nirilaBlockMentionsFromUnfamiliarRemoteUsers && user.host !== null && willCauseNotification && !isAllowedToCreateNotification()) {
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
7 changes: 7 additions & 0 deletions packages/backend/src/models/Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,4 +630,11 @@ export class MiMeta {
default: false,
})
public nirilaBlockMentionsFromUnfamiliarRemoteUsers: boolean;

@Column('varchar', {
length: 32,
array: true,
default: '{}',
})
public nirilaAllowedUnfamiliarRemoteUserIds: string[];
}
11 changes: 11 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,16 @@ export const meta = {
type: 'boolean',
optional: false, nullable: false,
},
nirilaAllowedUnfamiliarRemoteUserIds: {
type: 'array',
optional: false,
nullable: false,
items: {
type: 'string',
optional: false,
nullable: false,
},
},
},
},
} as const;
Expand Down Expand Up @@ -620,6 +630,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
urlPreviewUserAgent: instance.urlPreviewUserAgent,
urlPreviewSummaryProxyUrl: instance.urlPreviewSummaryProxyUrl,
nirilaBlockMentionsFromUnfamiliarRemoteUsers: instance.nirilaBlockMentionsFromUnfamiliarRemoteUsers,
nirilaAllowedUnfamiliarRemoteUserIds: instance.nirilaAllowedUnfamiliarRemoteUserIds,
};
});
}
Expand Down
12 changes: 12 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/update-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ export const paramDef = {
urlPreviewUserAgent: { type: 'string', nullable: true },
urlPreviewSummaryProxyUrl: { type: 'string', nullable: true },
nirilaBlockMentionsFromUnfamiliarRemoteUsers: { type: 'boolean', nullable: false },
nirilaAllowedUnfamiliarRemoteUserIds: {
type: 'array',
nullable: false,
items: {
type: 'string',
nullable: false,
},
}
},
required: [],
} as const;
Expand Down Expand Up @@ -627,6 +635,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.nirilaBlockMentionsFromUnfamiliarRemoteUsers = ps.nirilaBlockMentionsFromUnfamiliarRemoteUsers;
}

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

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

await this.metaService.update(set);
Expand Down
9 changes: 9 additions & 0 deletions packages/frontend/src/pages/admin/moderation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSwitch v-model="nirilaBlockMentionsFromUnfamiliarRemoteUsers">
<template #label>未知のリモートユーザからの通知を生成するノートをブロックする</template>
</MkSwitch>

<MkTextarea v-model="hiddenTags">
<template #label>未知のリモートユーザからの通知を許可するローカルユーザのid</template>
<template #caption>9grmcrkrslのようなユーザのidであって@adminのようなユーザ名ではないことに気をつけてください。</template>
</MkTextarea>
</div>
</FormSuspense>
</MkSpacer>
Expand Down Expand Up @@ -98,6 +103,7 @@ const tosUrl = ref<string | null>(null);
const privacyPolicyUrl = ref<string | null>(null);
const inquiryUrl = ref<string | null>(null);
const nirilaBlockMentionsFromUnfamiliarRemoteUsers = ref<boolean>(false);
const nirilaAllowedUnfamiliarRemoteUserIds = ref<string>('');

async function init() {
const meta = await misskeyApi('admin/meta');
Expand All @@ -111,6 +117,7 @@ async function init() {
privacyPolicyUrl.value = meta.privacyPolicyUrl;
inquiryUrl.value = meta.inquiryUrl;
nirilaBlockMentionsFromUnfamiliarRemoteUsers.value = meta.nirilaBlockMentionsFromUnfamiliarRemoteUsers;
nirilaAllowedUnfamiliarRemoteUserIds.value = meta.nirilaAllowedUnfamiliarRemoteUserIds.join('\n');
}

function save() {
Expand All @@ -125,6 +132,8 @@ function save() {
hiddenTags: hiddenTags.value.split('\n'),
preservedUsernames: preservedUsernames.value.split('\n'),
nirilaBlockMentionsFromUnfamiliarRemoteUsers: nirilaBlockMentionsFromUnfamiliarRemoteUsers.value,
nirilaAllowedUnfamiliarRemoteUserIds: nirilaAllowedUnfamiliarRemoteUserIds.value == ''

Check failure on line 135 in packages/frontend/src/pages/admin/moderation.vue

View workflow job for this annotation

GitHub Actions / lint (frontend)

Expected '===' and instead saw '=='
? [] : nirilaAllowedUnfamiliarRemoteUserIds.value.split('\n'),
}).then(() => {
fetchInstance(true);
});
Expand Down
2 changes: 2 additions & 0 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5101,6 +5101,7 @@ export type operations = {
urlPreviewUserAgent: string | null;
urlPreviewSummaryProxyUrl: string | null;
nirilaBlockMentionsFromUnfamiliarRemoteUsers: boolean;
nirilaAllowedUnfamiliarRemoteUserIds: string[];
};
};
};
Expand Down Expand Up @@ -9112,6 +9113,7 @@ export type operations = {
urlPreviewUserAgent?: string | null;
urlPreviewSummaryProxyUrl?: string | null;
nirilaBlockMentionsFromUnfamiliarRemoteUsers?: boolean;
nirilaAllowedUnfamiliarRemoteUserIds?: string[];
};
};
};
Expand Down

0 comments on commit 751653a

Please sign in to comment.