Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: アンテナでセンシティブなチャンネルからのノートを除外できるように #15346

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
66f23a2
feat(db): マイグレーションを追加
sevenc-nanashi Jan 7, 2025
3deaf92
feat(backend): カラムの定義を追加
sevenc-nanashi Jan 7, 2025
bc8250b
wip
sevenc-nanashi Jan 24, 2025
6216235
feat: フラグを設定出来るように
sevenc-nanashi Jan 25, 2025
3ec48a2
feat: /notesエンドポイントを対応
sevenc-nanashi Jan 25, 2025
da6c80a
feat: websocketを対応
sevenc-nanashi Jan 25, 2025
eb9d1e9
test: テストを追加
sevenc-nanashi Jan 25, 2025
7fff5b3
docs: CHANGELOGを更新
sevenc-nanashi Jan 25, 2025
1e0a3b1
docs: CHANGELOGの追加場所を修正
sevenc-nanashi Jan 25, 2025
f98076e
chore: api.jsonを更新
sevenc-nanashi Jan 25, 2025
799af23
Merge branch 'develop' into feat/hide-sensitive-from-antenna
sevenc-nanashi Jan 29, 2025
8e95c9d
docs(CHANGELOG): General欄に移動
sevenc-nanashi Jan 29, 2025
812c3a1
Merge branch 'develop' into feat/hide-sensitive-from-antenna
sevenc-nanashi Feb 1, 2025
1a15156
Merge branch 'develop' into feat/hide-sensitive-from-antenna
sevenc-nanashi Feb 5, 2025
3a71cc7
Merge branch 'develop' into feat/hide-sensitive-from-antenna
sevenc-nanashi Feb 6, 2025
283bb82
Merge branch 'develop' into feat/hide-sensitive-from-antenna
sevenc-nanashi Feb 12, 2025
369e98b
docs: フォーマットを揃える
sevenc-nanashi Feb 13, 2025
493a5d7
chore: クエリを削除
sevenc-nanashi Feb 20, 2025
46a13d0
Merge: upstream/develop -> feat/hide-sensitive-from-antenna
sevenc-nanashi Feb 20, 2025
4bbd8d5
revert: 英訳を消す
sevenc-nanashi Feb 21, 2025
a6f1d44
chore: note.channelを追加するところを変える
sevenc-nanashi Feb 21, 2025
db4e53d
Merge branch 'develop' into feat/hide-sensitive-from-antenna
sevenc-nanashi Mar 1, 2025
49553cb
docs: CHANGELOGを更新する
sevenc-nanashi Mar 1, 2025
f7649c0
Merge branch 'develop' into feat/hide-sensitive-from-antenna
sevenc-nanashi Mar 3, 2025
5fb6631
Merge branch 'develop' into feat/hide-sensitive-from-antenna
sevenc-nanashi Mar 4, 2025
327e7af
Merge branch 'develop' into feat/hide-sensitive-from-antenna
sevenc-nanashi Mar 9, 2025
c743a3a
docs(CHANGELOG): 2025.3.2に移動
sevenc-nanashi Mar 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 2025.2.1

### General
- Enhance: アンテナでセンシティブなチャンネルのノートを除外できるように `#14177`
- Feat: アクセストークン発行時に通知するように
- 依存関係の更新

Expand Down
1 change: 1 addition & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ antennaExcludeBots: "Exclude bot accounts"
antennaKeywordsDescription: "Separate with spaces for an AND condition or with line breaks for an OR condition."
notifyAntenna: "Notify about new notes"
withFileAntenna: "Only notes with files"
hideNotesInSensitiveChannel: "Hide notes in sensitive channels"
enableServiceworker: "Enable Push-Notifications for your Browser"
antennaUsersDescription: "List one username per line"
caseSensitive: "Case sensitive"
Expand Down
4 changes: 4 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,10 @@ export interface Locale extends ILocale {
* ファイルが添付されたノートのみ
*/
"withFileAntenna": string;
/**
* センシティブなチャンネルのノートを非表示
*/
"hideNotesInSensitiveChannel": string;
/**
* ブラウザへのプッシュ通知を有効にする
*/
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ antennaExcludeBots: "Botアカウントを除外"
antennaKeywordsDescription: "スペースで区切るとAND指定になり、改行で区切るとOR指定になります"
notifyAntenna: "新しいノートを通知する"
withFileAntenna: "ファイルが添付されたノートのみ"
hideNotesInSensitiveChannel: "センシティブなチャンネルのノートを非表示"
enableServiceworker: "ブラウザへのプッシュ通知を有効にする"
antennaUsersDescription: "ユーザー名を改行で区切って指定します"
caseSensitive: "大文字小文字を区別する"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/

export class AddAntennaHideNotesInSensitiveChannel1736230492103 {
name = 'AddAntennaHideNotesInSensitiveChannel1736230492103'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "antenna" ADD "hideNotesInSensitiveChannel" boolean NOT NULL DEFAULT false`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "antenna" DROP COLUMN "hideNotesInSensitiveChannel"`);
}
}
2 changes: 2 additions & 0 deletions packages/backend/src/core/AntennaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export class AntennaService implements OnApplicationShutdown {
if (note.visibility === 'specified') return false;
if (note.visibility === 'followers') return false;

if (antenna.hideNotesInSensitiveChannel && note.channel?.isSensitive) return false;

if (antenna.excludeBots && noteUser.isBot) return false;

if (antenna.localOnly && noteUser.host != null) return false;
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ export class NoteCreateService implements OnApplicationShutdown {
replyId: data.reply ? data.reply.id : null,
renoteId: data.renote ? data.renote.id : null,
channelId: data.channel ? data.channel.id : null,
channel: data.channel,
threadId: data.reply
? data.reply.threadId
? data.reply.threadId
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/entities/AntennaEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class AntennaEntityService {
excludeBots: antenna.excludeBots,
withReplies: antenna.withReplies,
withFile: antenna.withFile,
hideNotesInSensitiveChannel: antenna.hideNotesInSensitiveChannel,
isActive: antenna.isActive,
hasUnreadNote: false, // TODO
notify: false, // 後方互換性のため
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/models/Antenna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,9 @@ export class MiAntenna {
default: false,
})
public localOnly: boolean;

@Column('boolean', {
default: false,
})
public hideNotesInSensitiveChannel: boolean;
}
5 changes: 5 additions & 0 deletions packages/backend/src/models/json-schema/antenna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,10 @@ export const packedAntennaSchema = {
optional: false, nullable: false,
default: false,
},
hideNotesInSensitiveChannel: {
type: 'boolean',
optional: false, nullable: false,
default: false,
},
},
} as const;
2 changes: 2 additions & 0 deletions packages/backend/src/server/api/endpoints/antennas/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const paramDef = {
excludeBots: { type: 'boolean' },
withReplies: { type: 'boolean' },
withFile: { type: 'boolean' },
hideNotesInSensitiveChannel: { type: 'boolean' },
},
required: ['name', 'src', 'keywords', 'excludeKeywords', 'users', 'caseSensitive', 'withReplies', 'withFile'],
} as const;
Expand Down Expand Up @@ -133,6 +134,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
excludeBots: ps.excludeBots,
withReplies: ps.withReplies,
withFile: ps.withFile,
hideNotesInSensitiveChannel: ps.hideNotesInSensitiveChannel,
});

this.globalEventService.publishInternalEvent('antennaCreated', antenna);
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/server/api/endpoints/antennas/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('reply.user', 'replyUser')
.leftJoinAndSelect('renote.user', 'renoteUser');

// NOTE: センシティブ除外の設定はこのエンドポイントでは無視する。
// https://github.com/misskey-dev/misskey/pull/15346#discussion_r1929950255

this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateMutedUserQuery(query, me);
this.queryService.generateBlockedUserQuery(query, me);
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/server/api/endpoints/antennas/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const paramDef = {
excludeBots: { type: 'boolean' },
withReplies: { type: 'boolean' },
withFile: { type: 'boolean' },
hideNotesInSensitiveChannel: { type: 'boolean' },
},
required: ['antennaId'],
} as const;
Expand Down Expand Up @@ -129,6 +130,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
excludeBots: ps.excludeBots,
withReplies: ps.withReplies,
withFile: ps.withFile,
hideNotesInSensitiveChannel: ps.hideNotesInSensitiveChannel,
isActive: true,
lastUsedAt: new Date(),
});
Expand Down
39 changes: 39 additions & 0 deletions packages/backend/test/e2e/antennas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ describe('アンテナ', () => {
caseSensitive: false,
createdAt: new Date(response.createdAt).toISOString(),
excludeKeywords: [['']],
hideNotesInSensitiveChannel: false,
hasUnreadNote: false,
isActive: true,
keywords: [['keyword']],
Expand Down Expand Up @@ -217,6 +218,8 @@ describe('アンテナ', () => {
{ parameters: () => ({ withReplies: true }) },
{ parameters: () => ({ withFile: false }) },
{ parameters: () => ({ withFile: true }) },
{ parameters: () => ({ hideNotesInSensitiveChannel: false }) },
{ parameters: () => ({ hideNotesInSensitiveChannel: true }) },
];
test.each(antennaParamPattern)('を作成できること($#)', async ({ parameters }) => {
const response = await successfulApiCall({
Expand Down Expand Up @@ -626,6 +629,42 @@ describe('アンテナ', () => {
assert.deepStrictEqual(response, expected);
});

test('が取得できること(センシティブチャンネルのノートを除く)', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これだけチャンネル作成が必要になってくるので上のeachとは別に書いています。

const keyword = 'キーワード';
const antenna = await successfulApiCall({
endpoint: 'antennas/create',
parameters: { ...defaultParam, keywords: [[keyword]], hideNotesInSensitiveChannel: true },
user: alice,
});
const nonSensitiveChannel = await successfulApiCall({
endpoint: 'channels/create',
parameters: { name: 'test', isSensitive: false },
user: alice,
});
const sensitiveChannel = await successfulApiCall({
endpoint: 'channels/create',
parameters: { name: 'test', isSensitive: true },
user: alice,
});

const noteInLocal = await post(bob, { text: `test ${keyword}` });
const noteInNonSensitiveChannel = await post(bob, { text: `test ${keyword}`, channelId: nonSensitiveChannel.id });
await post(bob, { text: `test ${keyword}`, channelId: sensitiveChannel.id });

const response = await successfulApiCall({
endpoint: 'antennas/notes',
parameters: { antennaId: antenna.id },
user: alice,
});
// 最後に投稿したものが先頭に来る。
const expected = [
noteInNonSensitiveChannel,
noteInLocal,
];
assert.deepStrictEqual(response, expected);
});


test.skip('が取得でき、日付指定のPaginationに一貫性があること', async () => { });
test.each([
{ label: 'ID指定', offsetBy: 'id' },
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/src/components/MkAntennaEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSwitch v-model="localOnly">{{ i18n.ts.localOnly }}</MkSwitch>
<MkSwitch v-model="caseSensitive">{{ i18n.ts.caseSensitive }}</MkSwitch>
<MkSwitch v-model="withFile">{{ i18n.ts.withFileAntenna }}</MkSwitch>
<MkSwitch v-model="hideNotesInSensitiveChannel">{{ i18n.ts.hideNotesInSensitiveChannel }}</MkSwitch>
</div>
<div :class="$style.actions">
<div class="_buttons">
Expand Down Expand Up @@ -86,6 +87,7 @@ const initialAntenna = deepMerge<PartialAllowedAntenna>(props.antenna ?? {}, {
caseSensitive: false,
localOnly: false,
withFile: false,
hideNotesInSensitiveChannel: false,
isActive: true,
hasUnreadNote: false,
notify: false,
Expand All @@ -108,6 +110,7 @@ const localOnly = ref<boolean>(initialAntenna.localOnly);
const excludeBots = ref<boolean>(initialAntenna.excludeBots);
const withReplies = ref<boolean>(initialAntenna.withReplies);
const withFile = ref<boolean>(initialAntenna.withFile);
const hideNotesInSensitiveChannel = ref<boolean>(initialAntenna.hideNotesInSensitiveChannel);
const userLists = ref<Misskey.entities.UserList[] | null>(null);

watch(() => src.value, async () => {
Expand All @@ -124,6 +127,7 @@ async function saveAntenna() {
excludeBots: excludeBots.value,
withReplies: withReplies.value,
withFile: withFile.value,
hideNotesInSensitiveChannel: hideNotesInSensitiveChannel.value,
caseSensitive: caseSensitive.value,
localOnly: localOnly.value,
users: users.value.trim().split('\n').map(x => x.trim()),
Expand Down
4 changes: 4 additions & 0 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4661,6 +4661,8 @@ export type components = {
hasUnreadNote: boolean;
/** @default false */
notify: boolean;
/** @default false */
hideNotesInSensitiveChannel: boolean;
};
Clip: {
/**
Expand Down Expand Up @@ -10926,6 +10928,7 @@ export type operations = {
excludeBots?: boolean;
withReplies: boolean;
withFile: boolean;
hideNotesInSensitiveChannel?: boolean;
};
};
};
Expand Down Expand Up @@ -11207,6 +11210,7 @@ export type operations = {
excludeBots?: boolean;
withReplies?: boolean;
withFile?: boolean;
hideNotesInSensitiveChannel?: boolean;
};
};
};
Expand Down
Loading