From f216585421542aeb6210897ac5311b5795d91a6c Mon Sep 17 00:00:00 2001 From: Tatsuya Koishi Date: Sun, 28 Jan 2024 11:14:44 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=A2=E3=83=AD=E3=83=98=E3=82=A4=E3=83=A4?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=81=AE=E5=A0=B4=E5=90=88=E7=AD=89=E3=80=81?= =?UTF-8?q?=E3=82=BF=E3=82=B0=E3=81=AE=E8=BF=BD=E8=A8=98=E3=81=AF=E3=82=AA?= =?UTF-8?q?=E3=83=95=E3=81=AB=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/docker_example.yml | 5 +++-- .config/example.yml | 5 +++-- packages/backend/src/config.ts | 12 +++++++----- packages/backend/src/core/NoteCreateService.ts | 14 +++++++------- .../server/api/endpoints/notes/hybrid-timeline.ts | 2 +- .../server/api/endpoints/notes/local-timeline.ts | 2 +- .../server/api/stream/channels/hybrid-timeline.ts | 2 +- .../server/api/stream/channels/local-timeline.ts | 2 +- 8 files changed, 24 insertions(+), 20 deletions(-) diff --git a/.config/docker_example.yml b/.config/docker_example.yml index afef8f650b..292f79e696 100644 --- a/.config/docker_example.yml +++ b/.config/docker_example.yml @@ -194,5 +194,6 @@ signToActivityPubGet: true # Upload or download file size limits (bytes) #maxFileSize: 262144000 -tagging: - defaultTag: null +defaultTag: + tag: null + append: true diff --git a/.config/example.yml b/.config/example.yml index d2f1660c77..42f460ed07 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -226,5 +226,6 @@ signToActivityPubGet: true # PID File of master process #pidFile: /tmp/misskey.pid -tagging: - defaultTag: null +defaultTag: + tag: null + append: true diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index 281b0892e4..797fe5ae4d 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -56,8 +56,9 @@ type Source = { index: string; scope?: 'local' | 'global' | string[]; }; - tagging: { - defaultTag: string; + defaultTag: { + tag: string; + append: boolean; }; proxy?: string; @@ -127,8 +128,9 @@ export type Config = { index: string; scope?: 'local' | 'global' | string[]; } | undefined; - tagging: { - defaultTag: string; + defaultTag: { + tag: string; + append: boolean; }; proxy: string | undefined; proxySmtp: string | undefined; @@ -267,7 +269,7 @@ export function loadConfig(): Config { perUserNotificationsMaxCount: config.perUserNotificationsMaxCount ?? 500, deactivateAntennaThreshold: config.deactivateAntennaThreshold ?? (1000 * 60 * 60 * 24 * 7), pidFile: config.pidFile, - tagging: config.tagging, + defaultTag: config.defaultTag, }; } diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index 5460735799..35694f727d 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -320,10 +320,10 @@ 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 (this.config.defaultTag?.append && ['public', 'home'].includes(data.visibility)) { + if (this.config.defaultTag?.tag != null) { + const tag = `#${this.config.defaultTag?.tag}`; if (String(data.text).match(tag)) { data.text = `${data.text}\n\n${tag}`; } @@ -923,10 +923,10 @@ export class NoteCreateService implements OnApplicationShutdown { } } - // デフォルトハッシュタグ - if (this.config.tagging?.defaultTag != null) { + // デフォルトハッシュタグを含む投稿は、リモートであってもローカルタイムラインに含める + if (this.config.defaultTag?.tag != null) { const noteTags = note.tags ? note.tags.map((t: string) => t.toLowerCase()) : []; - if (note.visibility === 'public' && noteTags.includes(normalizeForSearch(this.config.tagging?.defaultTag))) { + if (note.visibility === 'public' && noteTags.includes(normalizeForSearch(this.config.defaultTag?.tag))) { 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 2b25bec1c5..855cbd1852 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(); - const defaultTag: string | null = config.tagging?.defaultTag; + const defaultTag: string | null = config.defaultTag?.tag; 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 1c49023073..8c6b605e67 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(); - const defaultTag: string | null = config.tagging?.defaultTag; + const defaultTag: string | null = config.defaultTag?.tag; 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 38196a9c68..d6759845ab 100644 --- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts @@ -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.defaultTag?.tag; // 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 f8d97a6aab..15b4d60786 100644 --- a/packages/backend/src/server/api/stream/channels/local-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts @@ -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.defaultTag?.tag; // Subscribe events this.subscriber.on('notesStream', this.onNote);