@@ -64,21 +64,38 @@ export class NotificationEntityService implements OnModuleInit {
64
64
packedNotes : Map < MiNote [ 'id' ] , Packed < 'Note' > > ;
65
65
packedUsers : Map < MiUser [ 'id' ] , Packed < 'UserLite' > > ;
66
66
} ,
67
- ) : Promise < Packed < 'Notification' > > {
67
+ ) : Promise < Packed < 'Notification' > | null > {
68
68
const notification = src ;
69
- const noteIfNeed = NOTE_REQUIRED_NOTIFICATION_TYPES . has ( notification . type ) && 'noteId' in notification ? (
69
+ const needsNote = NOTE_REQUIRED_NOTIFICATION_TYPES . has ( notification . type ) && 'noteId' in notification ;
70
+ const noteIfNeed = needsNote ? (
70
71
hint ?. packedNotes != null
71
72
? hint . packedNotes . get ( notification . noteId )
72
73
: this . noteEntityService . pack ( notification . noteId , { id : meId } , {
73
74
detail : true ,
74
75
} )
75
76
) : undefined ;
76
- const userIfNeed = 'notifierId' in notification ? (
77
+ // if the note has been deleted, don't show this notification
78
+ if ( needsNote && ! noteIfNeed ) {
79
+ return null ;
80
+ }
81
+
82
+ const needsUser = 'notifierId' in notification ;
83
+ const userIfNeed = needsUser ? (
77
84
hint ?. packedUsers != null
78
85
? hint . packedUsers . get ( notification . notifierId )
79
86
: this . userEntityService . pack ( notification . notifierId , { id : meId } )
80
87
) : undefined ;
81
- const role = notification . type === 'roleAssigned' ? await this . roleEntityService . pack ( notification . roleId ) : undefined ;
88
+ // if the user has been deleted, don't show this notification
89
+ if ( needsUser && ! userIfNeed ) {
90
+ return null ;
91
+ }
92
+
93
+ const needsRole = notification . type === 'roleAssigned' ;
94
+ const role = needsRole ? await this . roleEntityService . pack ( notification . roleId ) : undefined ;
95
+ // if the role has been deleted, don't show this notification
96
+ if ( needsRole && ! role ) {
97
+ return null ;
98
+ }
82
99
83
100
return await awaitAll ( {
84
101
id : notification . id ,
@@ -141,10 +158,10 @@ export class NotificationEntityService implements OnModuleInit {
141
158
validNotifications = validNotifications . filter ( x => ( x . type !== 'receiveFollowRequest' ) || reqs . some ( r => r . followerId === x . notifierId ) ) ;
142
159
}
143
160
144
- return await Promise . all ( validNotifications . map ( x => this . pack ( x , meId , { } , {
161
+ return ( await Promise . all ( validNotifications . map ( x => this . pack ( x , meId , { } , {
145
162
packedNotes,
146
163
packedUsers,
147
- } ) ) ) ;
164
+ } ) ) ) ) . filter ( n => n ) ;
148
165
}
149
166
150
167
@bindThis
@@ -159,31 +176,47 @@ export class NotificationEntityService implements OnModuleInit {
159
176
packedNotes : Map < MiNote [ 'id' ] , Packed < 'Note' > > ;
160
177
packedUsers : Map < MiUser [ 'id' ] , Packed < 'UserLite' > > ;
161
178
} ,
162
- ) : Promise < Packed < 'Notification' > > {
179
+ ) : Promise < Packed < 'Notification' > | null > {
163
180
const notification = src ;
164
- const noteIfNeed = NOTE_REQUIRED_GROUPED_NOTIFICATION_TYPES . has ( notification . type ) && 'noteId' in notification ? (
181
+ const needsNote = NOTE_REQUIRED_GROUPED_NOTIFICATION_TYPES . has ( notification . type ) && 'noteId' in notification ;
182
+ const noteIfNeed = needsNote ? (
165
183
hint ?. packedNotes != null
166
184
? hint . packedNotes . get ( notification . noteId )
167
185
: this . noteEntityService . pack ( notification . noteId , { id : meId } , {
168
186
detail : true ,
169
187
} )
170
188
) : undefined ;
171
- const userIfNeed = 'notifierId' in notification ? (
189
+ // if the note has been deleted, don't show this notification
190
+ if ( needsNote && ! noteIfNeed ) {
191
+ return null ;
192
+ }
193
+
194
+ const needsUser = 'notifierId' in notification ;
195
+ const userIfNeed = needsUser ? (
172
196
hint ?. packedUsers != null
173
197
? hint . packedUsers . get ( notification . notifierId )
174
198
: this . userEntityService . pack ( notification . notifierId , { id : meId } )
175
199
) : undefined ;
200
+ // if the user has been deleted, don't show this notification
201
+ if ( needsUser && ! userIfNeed ) {
202
+ return null ;
203
+ }
176
204
177
205
if ( notification . type === 'reaction:grouped' ) {
178
- const reactions = await Promise . all ( notification . reactions . map ( async reaction => {
206
+ const reactions = ( await Promise . all ( notification . reactions . map ( async reaction => {
179
207
const user = hint ?. packedUsers != null
180
208
? hint . packedUsers . get ( reaction . userId ) !
181
209
: await this . userEntityService . pack ( reaction . userId , { id : meId } ) ;
182
210
return {
183
211
user,
184
212
reaction : reaction . reaction ,
185
213
} ;
186
- } ) ) ;
214
+ } ) ) ) . filter ( r => r . user ) ;
215
+ // if all users have been deleted, don't show this notification
216
+ if ( ! reactions . length ) {
217
+ return null ;
218
+ }
219
+
187
220
return await awaitAll ( {
188
221
id : notification . id ,
189
222
createdAt : new Date ( notification . createdAt ) . toISOString ( ) ,
@@ -192,14 +225,19 @@ export class NotificationEntityService implements OnModuleInit {
192
225
reactions,
193
226
} ) ;
194
227
} else if ( notification . type === 'renote:grouped' ) {
195
- const users = await Promise . all ( notification . userIds . map ( userId => {
228
+ const users = ( await Promise . all ( notification . userIds . map ( userId => {
196
229
const packedUser = hint ?. packedUsers != null ? hint . packedUsers . get ( userId ) : null ;
197
230
if ( packedUser ) {
198
231
return packedUser ;
199
232
}
200
233
201
234
return this . userEntityService . pack ( userId , { id : meId } ) ;
202
- } ) ) ;
235
+ } ) ) ) . filter ( u => u ) ;
236
+ // if all users have been deleted, don't show this notification
237
+ if ( ! users . length ) {
238
+ return null ;
239
+ }
240
+
203
241
return await awaitAll ( {
204
242
id : notification . id ,
205
243
createdAt : new Date ( notification . createdAt ) . toISOString ( ) ,
@@ -209,7 +247,12 @@ export class NotificationEntityService implements OnModuleInit {
209
247
} ) ;
210
248
}
211
249
212
- const role = notification . type === 'roleAssigned' ? await this . roleEntityService . pack ( notification . roleId ) : undefined ;
250
+ const needsRole = notification . type === 'roleAssigned' ;
251
+ const role = needsRole ? await this . roleEntityService . pack ( notification . roleId ) : undefined ;
252
+ // if the role has been deleted, don't show this notification
253
+ if ( needsRole && ! role ) {
254
+ return null ;
255
+ }
213
256
214
257
return await awaitAll ( {
215
258
id : notification . id ,
@@ -277,9 +320,9 @@ export class NotificationEntityService implements OnModuleInit {
277
320
validNotifications = validNotifications . filter ( x => ( x . type !== 'receiveFollowRequest' ) || reqs . some ( r => r . followerId === x . notifierId ) ) ;
278
321
}
279
322
280
- return await Promise . all ( validNotifications . map ( x => this . packGrouped ( x , meId , { } , {
323
+ return ( await Promise . all ( validNotifications . map ( x => this . packGrouped ( x , meId , { } , {
281
324
packedNotes,
282
325
packedUsers,
283
- } ) ) ) ;
326
+ } ) ) ) ) . filter ( n => n ) ;
284
327
}
285
328
}
0 commit comments