feat: Implement individual notification click handling, differentiate notification types for replies and subscriptions, and refine notification display text.
This commit is contained in:
@@ -110,23 +110,38 @@ export default (router, tpl) => {
|
||||
parentAuthor = await db`SELECT user_id FROM comments WHERE id = ${parent_id}`;
|
||||
}
|
||||
|
||||
// 3. Collect unique recipients
|
||||
const recipients = new Set();
|
||||
subscribers.forEach(s => recipients.add(s.user_id));
|
||||
parentAuthor.forEach(p => recipients.add(p.user_id));
|
||||
// 3. Prepare notifications
|
||||
const notificationsToAdd = [];
|
||||
|
||||
// Remove self
|
||||
recipients.delete(req.session.id);
|
||||
// Parent author gets 'comment_reply'
|
||||
if (parentAuthor.length > 0) {
|
||||
const pid = parentAuthor[0].user_id;
|
||||
if (pid !== req.session.id) {
|
||||
notificationsToAdd.push({
|
||||
user_id: pid,
|
||||
type: 'comment_reply',
|
||||
item_id: item_id,
|
||||
reference_id: commentId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Subscribers get 'subscription' (unless they already got comment_reply)
|
||||
const parentUserId = parentAuthor.length > 0 ? parentAuthor[0].user_id : -1;
|
||||
|
||||
subscribers.forEach(s => {
|
||||
if (s.user_id !== req.session.id && s.user_id !== parentUserId) {
|
||||
notificationsToAdd.push({
|
||||
user_id: s.user_id,
|
||||
type: 'subscription',
|
||||
item_id: item_id,
|
||||
reference_id: commentId
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 4. Batch insert
|
||||
if (recipients.size > 0) {
|
||||
const notificationsToAdd = Array.from(recipients).map(uid => ({
|
||||
user_id: uid,
|
||||
type: 'comment_reply',
|
||||
item_id: item_id,
|
||||
reference_id: commentId
|
||||
}));
|
||||
|
||||
if (notificationsToAdd.length > 0) {
|
||||
await db`INSERT INTO notifications ${db(notificationsToAdd)}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user