diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index 4719735dfd..42d6aa4683 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -59,7 +59,6 @@ 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 { loadConfig } from '@/config.js'; type NotificationType = 'reply' | 'renote' | 'quote' | 'mention'; @@ -321,6 +320,16 @@ export class NoteCreateService implements OnApplicationShutdown { data.localOnly = true; } + // デフォルトハッシュタグ処理 + if (['public', 'home'].includes(data.visibility)) { + if (this.config.tagging.defaultTag != null) { + const tag = `#${this.config.tagging.defaultTag}`; + if (String(data.text).match(tag)) { + data.text = `${data.text}\n\n${tag}`; + } + } + } + if (data.text) { if (data.text.length > DB_MAX_NOTE_TEXT_LENGTH) { data.text = data.text.slice(0, DB_MAX_NOTE_TEXT_LENGTH); @@ -915,11 +924,9 @@ export class NoteCreateService implements OnApplicationShutdown { } // デフォルトハッシュタグ - const config = loadConfig(); - let defaultTag:string | null = config.tagging.defaultTag; - if (defaultTag != null) { + if (this.config.tagging.defaultTag != null) { const noteTags = note.tags ? note.tags.map((t: string) => t.toLowerCase()) : []; - if (note.visibility === 'public' && noteTags.includes(normalizeForSearch(defaultTag))) { + if (note.visibility === 'public' && noteTags.includes(normalizeForSearch(this.config.tagging.defaultTag))) { this.fanoutTimelineService.push('localTimelineWithReplies', note.id, 300, r); this.fanoutTimelineService.push('localTimeline', note.id, 1000, r); if (note.fileIds.length > 0) { diff --git a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts index c6d6c55e9b..d328f4d846 100644 --- a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts @@ -201,7 +201,7 @@ export default class extends Endpoint { // eslint- } const config = loadConfig(); - let defaultTag:string | null = config.tagging.defaultTag; + const defaultTag: string | null = config.tagging.defaultTag; if (defaultTag == null) { qb.orWhere('(note.visibility = \'public\') AND (note.userHost IS NULL)'); } else { diff --git a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts index f4b962f465..24f8a303e8 100644 --- a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts @@ -152,7 +152,7 @@ export default class extends Endpoint { // eslint- withReplies: boolean, }, me: MiLocalUser | null) { const config = loadConfig(); - let defaultTag:string | null = config.tagging.defaultTag; + const defaultTag: string | null = config.tagging.defaultTag; const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId) .andWhere(new Brackets(qb => { diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts index 29bdb8d327..dab99ba400 100644 --- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts @@ -24,7 +24,7 @@ class HybridTimelineChannel extends Channel { private withRenotes: boolean; private withReplies: boolean; private withFiles: boolean; - private defaultTag: string; + private defaultTag: string | null; constructor( private metaService: MetaService, @@ -47,7 +47,7 @@ class HybridTimelineChannel extends Channel { this.withReplies = params.withReplies ?? false; this.withFiles = params.withFiles ?? false; const config = loadConfig(); - this.defaultTag = config.tagging.defaultTag; + this.defaultTag = config.tagging.defaultTag; // Subscribe events this.subscriber.on('notesStream', this.onNote); diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts index 00908b9164..e166af413d 100644 --- a/packages/backend/src/server/api/stream/channels/local-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts @@ -22,7 +22,7 @@ class LocalTimelineChannel extends Channel { private withRenotes: boolean; private withReplies: boolean; private withFiles: boolean; - private defaultTag: string; + private defaultTag: string | null; constructor( private metaService: MetaService, @@ -45,7 +45,7 @@ class LocalTimelineChannel extends Channel { this.withReplies = params.withReplies ?? false; this.withFiles = params.withFiles ?? false; const config = loadConfig(); - this.defaultTag = config.tagging.defaultTag; + this.defaultTag = config.tagging.defaultTag; // Subscribe events this.subscriber.on('notesStream', this.onNote);