Skip to content

Commit b45f18c

Browse files
fix(backend): ノート通知で公開範囲を考慮するように (#17335)
* fix(backend): ノート通知で公開範囲を考慮するように * refactor: remove unused imports * Update Changelog * Update Changelog * fix: フォロワー限定ノートは通知 --------- Co-authored-by: lqvp <[email protected]>
1 parent 6176cca commit b45f18c

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
(Cherry-picked from https://github.com/lqvp/misskey-tempura/commit/3f0f4bfe923f2b3a7837017b54841598f421c6ef)
3131
- Fix: support activity with `actor` as an id string or embedded object in inbox processor and ActivityPub inbox service
3232
- Fix: コンフィグファイルに `meilisearch` の設定がある状態でほかの検索プロバイダを利用すると、UI上からリモートのノートの検索ができない問題を修正
33+
- Fix: ノートに関する通知で公開範囲が考慮されていない問題を修正
34+
(Cherry-picked from https://github.com/lqvp/misskey-tempura/commit/cbce96c520a138b8bcd16890ff6f2952830fa166 originally presented in https://github.com/yojo-art/cherrypick/pull/743)
3335

3436
## 2026.3.2
3537

packages/backend/src/core/NoteCreateService.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class NotificationManager {
7171
constructor(
7272
private mutingsRepository: MutingsRepository,
7373
private notificationService: NotificationService,
74+
private followingsRepository: FollowingsRepository,
7475
notifier: { id: MiUser['id']; },
7576
note: MiNote,
7677
) {
@@ -101,7 +102,47 @@ class NotificationManager {
101102

102103
@bindThis
103104
public async notify() {
105+
if (this.queue.length === 0) {
106+
return;
107+
}
108+
109+
const targetUserIds = this.queue.map(x => x.target);
110+
let visibleUserIds: Set<string>;
111+
112+
switch (this.note.visibility) {
113+
case 'public':
114+
case 'home':
115+
visibleUserIds = new Set(targetUserIds);
116+
break;
117+
118+
case 'specified':
119+
visibleUserIds = new Set(this.note.visibleUserIds.filter(id => targetUserIds.includes(id)));
120+
break;
121+
122+
// TODO: フォロワー限定ノートにフォロワーではない人がメンションされた場合通知されるのが正しい挙動なのか確認(一部に挙動の不一致がありそう)。現状は通知されるためフィルタしない
123+
// case 'followers': {
124+
// const followers = await this.followingsRepository.find({
125+
// where: {
126+
// followeeId: this.note.userId,
127+
// followerId: In(targetUserIds),
128+
// isFollowerHibernated: false,
129+
// },
130+
// select: ['followerId'],
131+
// });
132+
// visibleUserIds = new Set(followers.map(f => f.followerId));
133+
// break;
134+
// }
135+
136+
default:
137+
visibleUserIds = new Set();
138+
break;
139+
}
140+
104141
for (const x of this.queue) {
142+
if (!visibleUserIds.has(x.target)) {
143+
continue;
144+
}
145+
105146
if (x.reason === 'renote') {
106147
this.notificationService.createNotification(x.target, 'renote', {
107148
noteId: this.note.id,
@@ -772,7 +813,7 @@ export class NoteCreateService implements OnApplicationShutdown {
772813

773814
this.webhookService.enqueueUserWebhook(user.id, 'note', { note: noteObj });
774815

775-
const nm = new NotificationManager(this.mutingsRepository, this.notificationService, user, note);
816+
const nm = new NotificationManager(this.mutingsRepository, this.notificationService, this.followingsRepository, user, note);
776817

777818
await this.createMentionedEvents(mentionedUsers, note, nm);
778819

0 commit comments

Comments
 (0)