From 3ebed5aa3e18cb66359c62f1f77443d120aa9f02 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 16 Oct 2023 15:06:00 +0900 Subject: [PATCH] feat: local-only antenna Resolve #11869 --- CHANGELOG.md | 2 +- .../migration/1697436246389-antenna-localOnly.js | 16 ++++++++++++++++ packages/backend/src/core/AntennaService.ts | 2 ++ .../src/core/entities/AntennaEntityService.ts | 1 + packages/backend/src/models/Antenna.ts | 5 +++++ .../backend/src/models/json-schema/antenna.ts | 5 +++++ .../processors/ExportAntennasProcessorService.ts | 1 + .../processors/ImportAntennasProcessorService.ts | 2 ++ .../src/server/api/endpoints/antennas/create.ts | 2 ++ .../src/server/api/endpoints/antennas/update.ts | 2 ++ packages/backend/test/e2e/move.ts | 2 ++ .../frontend/src/pages/my-antennas/create.vue | 3 ++- .../frontend/src/pages/my-antennas/editor.vue | 3 +++ packages/misskey-js/etc/misskey-js.api.md | 3 ++- packages/misskey-js/src/entities.ts | 1 + 15 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 packages/backend/migration/1697436246389-antenna-localOnly.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 85a998de1..ee14d361f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ ## 2023.x.x (unreleased) ### General -- +- Feat: アンテナでローカルの投稿のみ収集できるようになりました ### Client - Enhance: TLの返信表示オプションを記憶するように diff --git a/packages/backend/migration/1697436246389-antenna-localOnly.js b/packages/backend/migration/1697436246389-antenna-localOnly.js new file mode 100644 index 000000000..022867329 --- /dev/null +++ b/packages/backend/migration/1697436246389-antenna-localOnly.js @@ -0,0 +1,16 @@ +/* + * SPDX-FileCopyrightText: syuilo and other misskey contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +export class AntennaLocalOnly1697436246389 { + name = 'AntennaLocalOnly1697436246389' + + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "antenna" ADD "localOnly" boolean NOT NULL DEFAULT false`); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "antenna" DROP COLUMN "localOnly"`); + } +} diff --git a/packages/backend/src/core/AntennaService.ts b/packages/backend/src/core/AntennaService.ts index 60569c44f..94c8ad0cf 100644 --- a/packages/backend/src/core/AntennaService.ts +++ b/packages/backend/src/core/AntennaService.ts @@ -98,6 +98,8 @@ export class AntennaService implements OnApplicationShutdown { if (note.visibility === 'specified') return false; if (note.visibility === 'followers') return false; + if (antenna.localOnly && noteUser.host != null) return false; + if (!antenna.withReplies && note.replyId != null) return false; if (antenna.src === 'home') { diff --git a/packages/backend/src/core/entities/AntennaEntityService.ts b/packages/backend/src/core/entities/AntennaEntityService.ts index a9e504d37..265a61e8a 100644 --- a/packages/backend/src/core/entities/AntennaEntityService.ts +++ b/packages/backend/src/core/entities/AntennaEntityService.ts @@ -37,6 +37,7 @@ export class AntennaEntityService { userListId: antenna.userListId, users: antenna.users, caseSensitive: antenna.caseSensitive, + localOnly: antenna.localOnly, notify: antenna.notify, withReplies: antenna.withReplies, withFile: antenna.withFile, diff --git a/packages/backend/src/models/Antenna.ts b/packages/backend/src/models/Antenna.ts index 0bc0084fc..b74c61b72 100644 --- a/packages/backend/src/models/Antenna.ts +++ b/packages/backend/src/models/Antenna.ts @@ -93,4 +93,9 @@ export class MiAntenna { default: true, }) public isActive: boolean; + + @Column('boolean', { + default: false, + }) + public localOnly: boolean; } diff --git a/packages/backend/src/models/json-schema/antenna.ts b/packages/backend/src/models/json-schema/antenna.ts index 7b6475919..4a9f0ed35 100644 --- a/packages/backend/src/models/json-schema/antenna.ts +++ b/packages/backend/src/models/json-schema/antenna.ts @@ -67,6 +67,11 @@ export const packedAntennaSchema = { optional: false, nullable: false, default: false, }, + localOnly: { + type: 'boolean', + optional: false, nullable: false, + default: false, + }, notify: { type: 'boolean', optional: false, nullable: false, diff --git a/packages/backend/src/queue/processors/ExportAntennasProcessorService.ts b/packages/backend/src/queue/processors/ExportAntennasProcessorService.ts index a0afbee3b..d0968d292 100644 --- a/packages/backend/src/queue/processors/ExportAntennasProcessorService.ts +++ b/packages/backend/src/queue/processors/ExportAntennasProcessorService.ts @@ -80,6 +80,7 @@ export class ExportAntennasProcessorService { return this.utilityService.getFullApAccount(u.username, u.host); // acct }) : null, caseSensitive: antenna.caseSensitive, + localOnly: antenna.localOnly, withReplies: antenna.withReplies, withFile: antenna.withFile, notify: antenna.notify, diff --git a/packages/backend/src/queue/processors/ImportAntennasProcessorService.ts b/packages/backend/src/queue/processors/ImportAntennasProcessorService.ts index 3e93b7b50..291ea14b6 100644 --- a/packages/backend/src/queue/processors/ImportAntennasProcessorService.ts +++ b/packages/backend/src/queue/processors/ImportAntennasProcessorService.ts @@ -43,6 +43,7 @@ const validate = new Ajv().compile({ type: 'string', } }, caseSensitive: { type: 'boolean' }, + localOnly: { type: 'boolean' }, withReplies: { type: 'boolean' }, withFile: { type: 'boolean' }, notify: { type: 'boolean' }, @@ -86,6 +87,7 @@ export class ImportAntennasProcessorService { excludeKeywords: antenna.excludeKeywords, users: (antenna.src === 'list' && antenna.userListAccts !== null ? antenna.userListAccts : antenna.users).filter(Boolean), caseSensitive: antenna.caseSensitive, + localOnly: antenna.localOnly, withReplies: antenna.withReplies, withFile: antenna.withFile, notify: antenna.notify, diff --git a/packages/backend/src/server/api/endpoints/antennas/create.ts b/packages/backend/src/server/api/endpoints/antennas/create.ts index 687893398..b029493d3 100644 --- a/packages/backend/src/server/api/endpoints/antennas/create.ts +++ b/packages/backend/src/server/api/endpoints/antennas/create.ts @@ -63,6 +63,7 @@ export const paramDef = { type: 'string', } }, caseSensitive: { type: 'boolean' }, + localOnly: { type: 'boolean' }, withReplies: { type: 'boolean' }, withFile: { type: 'boolean' }, notify: { type: 'boolean' }, @@ -122,6 +123,7 @@ export default class extends Endpoint { // eslint- excludeKeywords: ps.excludeKeywords, users: ps.users, caseSensitive: ps.caseSensitive, + localOnly: ps.localOnly, withReplies: ps.withReplies, withFile: ps.withFile, notify: ps.notify, diff --git a/packages/backend/src/server/api/endpoints/antennas/update.ts b/packages/backend/src/server/api/endpoints/antennas/update.ts index 0e9874688..3457bb6f6 100644 --- a/packages/backend/src/server/api/endpoints/antennas/update.ts +++ b/packages/backend/src/server/api/endpoints/antennas/update.ts @@ -62,6 +62,7 @@ export const paramDef = { type: 'string', } }, caseSensitive: { type: 'boolean' }, + localOnly: { type: 'boolean' }, withReplies: { type: 'boolean' }, withFile: { type: 'boolean' }, notify: { type: 'boolean' }, @@ -116,6 +117,7 @@ export default class extends Endpoint { // eslint- excludeKeywords: ps.excludeKeywords, users: ps.users, caseSensitive: ps.caseSensitive, + localOnly: ps.localOnly, withReplies: ps.withReplies, withFile: ps.withFile, notify: ps.notify, diff --git a/packages/backend/test/e2e/move.ts b/packages/backend/test/e2e/move.ts index 3f158f9f1..b009ef124 100644 --- a/packages/backend/test/e2e/move.ts +++ b/packages/backend/test/e2e/move.ts @@ -188,6 +188,7 @@ describe('Account Move', () => { excludeKeywords: [], users: [], caseSensitive: false, + localOnly: false, withReplies: false, withFile: false, notify: false, @@ -431,6 +432,7 @@ describe('Account Move', () => { excludeKeywords: [], users: [eve.id], caseSensitive: false, + localOnly: false, withReplies: false, withFile: false, notify: false, diff --git a/packages/frontend/src/pages/my-antennas/create.vue b/packages/frontend/src/pages/my-antennas/create.vue index 2e08c13f1..6c963cdb5 100644 --- a/packages/frontend/src/pages/my-antennas/create.vue +++ b/packages/frontend/src/pages/my-antennas/create.vue @@ -14,7 +14,7 @@ import XAntenna from './editor.vue'; import { i18n } from '@/i18n.js'; import { definePageMetadata } from '@/scripts/page-metadata.js'; import { useRouter } from '@/router.js'; -import { antennasCache } from '@/cache'; +import { antennasCache } from '@/cache.js'; const router = useRouter(); @@ -27,6 +27,7 @@ let draft = $ref({ excludeKeywords: [], withReplies: false, caseSensitive: false, + localOnly: false, withFile: false, notify: false, }); diff --git a/packages/frontend/src/pages/my-antennas/editor.vue b/packages/frontend/src/pages/my-antennas/editor.vue index 4add66c39..16b8b848f 100644 --- a/packages/frontend/src/pages/my-antennas/editor.vue +++ b/packages/frontend/src/pages/my-antennas/editor.vue @@ -35,6 +35,7 @@ SPDX-License-Identifier: AGPL-3.0-only + {{ i18n.ts.localOnly }} {{ i18n.ts.caseSensitive }} {{ i18n.ts.withFileAntenna }} {{ i18n.ts.notifyAntenna }} @@ -75,6 +76,7 @@ let users: string = $ref(props.antenna.users.join('\n')); let keywords: string = $ref(props.antenna.keywords.map(x => x.join(' ')).join('\n')); let excludeKeywords: string = $ref(props.antenna.excludeKeywords.map(x => x.join(' ')).join('\n')); let caseSensitive: boolean = $ref(props.antenna.caseSensitive); +let localOnly: boolean = $ref(props.antenna.localOnly); let withReplies: boolean = $ref(props.antenna.withReplies); let withFile: boolean = $ref(props.antenna.withFile); let notify: boolean = $ref(props.antenna.notify); @@ -95,6 +97,7 @@ async function saveAntenna() { withFile, notify, caseSensitive, + localOnly, users: users.trim().split('\n').map(x => x.trim()), keywords: keywords.trim().split('\n').map(x => x.trim().split(' ')), excludeKeywords: excludeKeywords.trim().split('\n').map(x => x.trim().split(' ')), diff --git a/packages/misskey-js/etc/misskey-js.api.md b/packages/misskey-js/etc/misskey-js.api.md index 1a0bbeac7..b9777993f 100644 --- a/packages/misskey-js/etc/misskey-js.api.md +++ b/packages/misskey-js/etc/misskey-js.api.md @@ -61,6 +61,7 @@ type Antenna = { userGroupId: ID | null; users: string[]; caseSensitive: boolean; + localOnly: boolean; notify: boolean; withReplies: boolean; withFile: boolean; @@ -2984,7 +2985,7 @@ type UserSorting = '+follower' | '-follower' | '+createdAt' | '-createdAt' | '+u // src/api.types.ts:18:25 - (ae-forgotten-export) The symbol "NoParams" needs to be exported by the entry point index.d.ts // src/api.types.ts:630:18 - (ae-forgotten-export) The symbol "ShowUserReq" needs to be exported by the entry point index.d.ts // src/entities.ts:107:2 - (ae-forgotten-export) The symbol "notificationTypes_2" needs to be exported by the entry point index.d.ts -// src/entities.ts:600:2 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts +// src/entities.ts:601:2 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts // src/streaming.types.ts:33:4 - (ae-forgotten-export) The symbol "FIXME" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/packages/misskey-js/src/entities.ts b/packages/misskey-js/src/entities.ts index aed242d8a..bcf553853 100644 --- a/packages/misskey-js/src/entities.ts +++ b/packages/misskey-js/src/entities.ts @@ -470,6 +470,7 @@ export type Antenna = { userGroupId: ID | null; // TODO users: string[]; // TODO caseSensitive: boolean; + localOnly: boolean; notify: boolean; withReplies: boolean; withFile: boolean;