@@ -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