summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md11
-rw-r--r--packages/backend/src/core/HashtagService.ts3
-rw-r--r--packages/backend/src/core/NoteCreateService.ts27
-rw-r--r--packages/backend/src/core/UtilityService.ts28
4 files changed, 43 insertions, 26 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ac31bc0d28..af2aea7996 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,17 @@
-->
+## 2023.12.1
+
+### General
+-
+
+### Client
+-
+
+### Server
+- Enhance: センシティブワードの設定がハッシュタグトレンドにも適用されるようになりました
+
## 2023.12.0
### Note
diff --git a/packages/backend/src/core/HashtagService.ts b/packages/backend/src/core/HashtagService.ts
index d378999907..5a2417c9cd 100644
--- a/packages/backend/src/core/HashtagService.ts
+++ b/packages/backend/src/core/HashtagService.ts
@@ -15,6 +15,7 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { bindThis } from '@/decorators.js';
import { FeaturedService } from '@/core/FeaturedService.js';
import { MetaService } from '@/core/MetaService.js';
+import { UtilityService } from '@/core/UtilityService.js';
@Injectable()
export class HashtagService {
@@ -29,6 +30,7 @@ export class HashtagService {
private featuredService: FeaturedService,
private idService: IdService,
private metaService: MetaService,
+ private utilityService: UtilityService,
) {
}
@@ -161,6 +163,7 @@ export class HashtagService {
const instance = await this.metaService.fetch();
const hiddenTags = instance.hiddenTags.map(t => normalizeForSearch(t));
if (hiddenTags.includes(hashtag)) return;
+ if (this.utilityService.isSensitiveWordIncluded(hashtag, instance.sensitiveWords)) return;
// YYYYMMDDHHmm (10分間隔)
const now = new Date();
diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts
index 2bdff872ad..35baa1447d 100644
--- a/packages/backend/src/core/NoteCreateService.ts
+++ b/packages/backend/src/core/NoteCreateService.ts
@@ -253,7 +253,7 @@ export class NoteCreateService implements OnApplicationShutdown {
if (data.visibility === 'public' && data.channel == null) {
const sensitiveWords = meta.sensitiveWords;
- if (this.isSensitive(data, sensitiveWords)) {
+ if (this.utilityService.isSensitiveWordIncluded(data.cw ?? data.text ?? '', sensitiveWords)) {
data.visibility = 'home';
} else if ((await this.roleService.getUserPolicies(user.id)).canPublicNote === false) {
data.visibility = 'home';
@@ -705,31 +705,6 @@ export class NoteCreateService implements OnApplicationShutdown {
}
@bindThis
- private isSensitive(note: Option, sensitiveWord: string[]): boolean {
- if (sensitiveWord.length > 0) {
- const text = note.cw ?? note.text ?? '';
- if (text === '') return false;
- const matched = sensitiveWord.some(filter => {
- // represents RegExp
- const regexp = filter.match(/^\/(.+)\/(.*)$/);
- // This should never happen due to input sanitisation.
- if (!regexp) {
- const words = filter.split(' ');
- return words.every(keyword => text.includes(keyword));
- }
- try {
- return new RE2(regexp[1], regexp[2]).test(text);
- } catch (err) {
- // This should never happen due to input sanitisation.
- return false;
- }
- });
- if (matched) return true;
- }
- return false;
- }
-
- @bindThis
private isQuote(note: Option): note is Option & { renote: MiNote } {
// sync with misc/is-quote.ts
return !!note.renote && (!!note.text || !!note.cw || (!!note.files && !!note.files.length) || !!note.poll);
diff --git a/packages/backend/src/core/UtilityService.ts b/packages/backend/src/core/UtilityService.ts
index b95e41167b..5dec36c89e 100644
--- a/packages/backend/src/core/UtilityService.ts
+++ b/packages/backend/src/core/UtilityService.ts
@@ -6,6 +6,7 @@
import { URL } from 'node:url';
import { toASCII } from 'punycode';
import { Inject, Injectable } from '@nestjs/common';
+import RE2 from 're2';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import { bindThis } from '@/decorators.js';
@@ -42,6 +43,33 @@ export class UtilityService {
}
@bindThis
+ public isSensitiveWordIncluded(text: string, sensitiveWords: string[]): boolean {
+ if (sensitiveWords.length === 0) return false;
+ if (text === '') return false;
+
+ const regexpregexp = /^\/(.+)\/(.*)$/;
+
+ const matched = sensitiveWords.some(filter => {
+ // represents RegExp
+ const regexp = filter.match(regexpregexp);
+ // This should never happen due to input sanitisation.
+ if (!regexp) {
+ const words = filter.split(' ');
+ return words.every(keyword => text.includes(keyword));
+ }
+ try {
+ // TODO: RE2インスタンスをキャッシュ
+ return new RE2(regexp[1], regexp[2]).test(text);
+ } catch (err) {
+ // This should never happen due to input sanitisation.
+ return false;
+ }
+ });
+
+ return matched;
+ }
+
+ @bindThis
public extractDbHost(uri: string): string {
const url = new URL(uri);
return this.toPuny(url.hostname);