-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix(backend): 破損した通知をクライアントに送信しないように #13284
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
417bb2d
Never return broken notifications #409
dakkar fae7cb2
Update Changelog
kakkokari-gtyih 9ce9c6e
Merge branch 'develop' into fix-10650
kakkokari-gtyih 7db0971
Merge branch 'develop' into fix-10650
kakkokari-gtyih 56bbb52
Merge branch 'develop' into fix-10650
kakkokari-gtyih 8d68c50
Update CHANGELOG.md
kakkokari-gtyih File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,21 +64,38 @@ export class NotificationEntityService implements OnModuleInit { | |
packedNotes: Map<MiNote['id'], Packed<'Note'>>; | ||
packedUsers: Map<MiUser['id'], Packed<'UserLite'>>; | ||
}, | ||
): Promise<Packed<'Notification'>> { | ||
): Promise<Packed<'Notification'> | null> { | ||
const notification = src; | ||
const noteIfNeed = NOTE_REQUIRED_NOTIFICATION_TYPES.has(notification.type) && 'noteId' in notification ? ( | ||
const needsNote = NOTE_REQUIRED_NOTIFICATION_TYPES.has(notification.type) && 'noteId' in notification; | ||
const noteIfNeed = needsNote ? ( | ||
hint?.packedNotes != null | ||
? hint.packedNotes.get(notification.noteId) | ||
: this.noteEntityService.pack(notification.noteId, { id: meId }, { | ||
detail: true, | ||
}) | ||
) : undefined; | ||
const userIfNeed = 'notifierId' in notification ? ( | ||
// if the note has been deleted, don't show this notification | ||
if (needsNote && !noteIfNeed) { | ||
return null; | ||
} | ||
|
||
const needsUser = 'notifierId' in notification; | ||
const userIfNeed = needsUser ? ( | ||
hint?.packedUsers != null | ||
? hint.packedUsers.get(notification.notifierId) | ||
: this.userEntityService.pack(notification.notifierId, { id: meId }) | ||
) : undefined; | ||
const role = notification.type === 'roleAssigned' ? await this.roleEntityService.pack(notification.roleId) : undefined; | ||
// if the user has been deleted, don't show this notification | ||
if (needsUser && !userIfNeed) { | ||
return null; | ||
} | ||
|
||
const needsRole = notification.type === 'roleAssigned'; | ||
const role = needsRole ? await this.roleEntityService.pack(notification.roleId) : undefined; | ||
// if the role has been deleted, don't show this notification | ||
if (needsRole && !role) { | ||
return null; | ||
} | ||
|
||
return await awaitAll({ | ||
id: notification.id, | ||
|
@@ -141,10 +158,10 @@ export class NotificationEntityService implements OnModuleInit { | |
validNotifications = validNotifications.filter(x => (x.type !== 'receiveFollowRequest') || reqs.some(r => r.followerId === x.notifierId)); | ||
} | ||
|
||
return await Promise.all(validNotifications.map(x => this.pack(x, meId, {}, { | ||
return (await Promise.all(validNotifications.map(x => this.pack(x, meId, {}, { | ||
packedNotes, | ||
packedUsers, | ||
}))); | ||
})))).filter(n => n); | ||
} | ||
|
||
@bindThis | ||
|
@@ -159,31 +176,47 @@ export class NotificationEntityService implements OnModuleInit { | |
packedNotes: Map<MiNote['id'], Packed<'Note'>>; | ||
packedUsers: Map<MiUser['id'], Packed<'UserLite'>>; | ||
}, | ||
): Promise<Packed<'Notification'>> { | ||
): Promise<Packed<'Notification'> | null> { | ||
const notification = src; | ||
const noteIfNeed = NOTE_REQUIRED_GROUPED_NOTIFICATION_TYPES.has(notification.type) && 'noteId' in notification ? ( | ||
const needsNote = NOTE_REQUIRED_GROUPED_NOTIFICATION_TYPES.has(notification.type) && 'noteId' in notification; | ||
const noteIfNeed = needsNote ? ( | ||
hint?.packedNotes != null | ||
? hint.packedNotes.get(notification.noteId) | ||
: this.noteEntityService.pack(notification.noteId, { id: meId }, { | ||
detail: true, | ||
}) | ||
) : undefined; | ||
const userIfNeed = 'notifierId' in notification ? ( | ||
// if the note has been deleted, don't show this notification | ||
if (needsNote && !noteIfNeed) { | ||
return null; | ||
} | ||
|
||
const needsUser = 'notifierId' in notification; | ||
const userIfNeed = needsUser ? ( | ||
hint?.packedUsers != null | ||
? hint.packedUsers.get(notification.notifierId) | ||
: this.userEntityService.pack(notification.notifierId, { id: meId }) | ||
) : undefined; | ||
// if the user has been deleted, don't show this notification | ||
if (needsUser && !userIfNeed) { | ||
return null; | ||
} | ||
|
||
if (notification.type === 'reaction:grouped') { | ||
const reactions = await Promise.all(notification.reactions.map(async reaction => { | ||
const reactions = (await Promise.all(notification.reactions.map(async reaction => { | ||
const user = hint?.packedUsers != null | ||
? hint.packedUsers.get(reaction.userId)! | ||
: await this.userEntityService.pack(reaction.userId, { id: meId }); | ||
return { | ||
user, | ||
reaction: reaction.reaction, | ||
}; | ||
})); | ||
}))).filter(r => r.user); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここも |
||
// if all users have been deleted, don't show this notification | ||
if (!reactions.length) { | ||
return null; | ||
} | ||
|
||
return await awaitAll({ | ||
id: notification.id, | ||
createdAt: new Date(notification.createdAt).toISOString(), | ||
|
@@ -192,14 +225,19 @@ export class NotificationEntityService implements OnModuleInit { | |
reactions, | ||
}); | ||
} else if (notification.type === 'renote:grouped') { | ||
const users = await Promise.all(notification.userIds.map(userId => { | ||
const users = (await Promise.all(notification.userIds.map(userId => { | ||
const packedUser = hint?.packedUsers != null ? hint.packedUsers.get(userId) : null; | ||
if (packedUser) { | ||
return packedUser; | ||
} | ||
|
||
return this.userEntityService.pack(userId, { id: meId }); | ||
})); | ||
}))).filter(u => u); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. これも |
||
// if all users have been deleted, don't show this notification | ||
if (!users.length) { | ||
return null; | ||
} | ||
|
||
return await awaitAll({ | ||
id: notification.id, | ||
createdAt: new Date(notification.createdAt).toISOString(), | ||
|
@@ -209,7 +247,12 @@ export class NotificationEntityService implements OnModuleInit { | |
}); | ||
} | ||
|
||
const role = notification.type === 'roleAssigned' ? await this.roleEntityService.pack(notification.roleId) : undefined; | ||
const needsRole = notification.type === 'roleAssigned'; | ||
const role = needsRole ? await this.roleEntityService.pack(notification.roleId) : undefined; | ||
// if the role has been deleted, don't show this notification | ||
if (needsRole && !role) { | ||
return null; | ||
} | ||
|
||
return await awaitAll({ | ||
id: notification.id, | ||
|
@@ -277,9 +320,9 @@ export class NotificationEntityService implements OnModuleInit { | |
validNotifications = validNotifications.filter(x => (x.type !== 'receiveFollowRequest') || reqs.some(r => r.followerId === x.notifierId)); | ||
} | ||
|
||
return await Promise.all(validNotifications.map(x => this.packGrouped(x, meId, {}, { | ||
return (await Promise.all(validNotifications.map(x => this.packGrouped(x, meId, {}, { | ||
packedNotes, | ||
packedUsers, | ||
}))); | ||
})))).filter(n => n); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
型のわかりやすさの問題で
みたいなやつのほうがいい可能性