Changeset c9c6a2d in Klonkt for src/routes
- Timestamp:
- 06/21/2026 06:38:24 PM (3 months ago)
- Branches:
- main
- Children:
- 9a34d31
- Parents:
- d41f4be
- Location:
- src/routes
- Files:
-
- 1 added
- 2 edited
-
comments.js (modified) (4 diffs)
-
notifications.js (added)
-
posts.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/comments.js
rd41f4be rc9c6a2d 19 19 import { requireAuth } from '../middleware/auth.js'; 20 20 import PermissionsService from '../services/PermissionsService.js'; 21 import { notify } from '../services/NotificationService.js'; 21 22 22 23 const router = express.Router(); … … 39 40 40 41 const post = db.prepare( 41 'SELECT id, slug FROM posts WHERE site_id = ? AND slug = ? AND status = ?'42 'SELECT id, slug, title, author_id FROM posts WHERE site_id = ? AND slug = ? AND status = ?' 42 43 ).get(site.id, postSlug, 'published'); 43 44 if (!post) return res.status(404).send('Post not found'); … … 50 51 // up to the top-level parent so we never go deeper than 1) 51 52 let resolvedParent = null; 53 let parentAuthorId = null; 52 54 if (parentId) { 53 55 const parent = db.prepare( 54 'SELECT id, parent_comment_id FROM comments WHERE id = ? AND post_id = ?'56 'SELECT id, parent_comment_id, author_id FROM comments WHERE id = ? AND post_id = ?' 55 57 ).get(parentId, post.id); 56 58 if (!parent) return res.status(400).send('Invalid parent comment'); 57 59 resolvedParent = parent.parent_comment_id || parent.id; 60 parentAuthorId = parent.author_id; // ontvanger van de "antwoord"-melding 58 61 } 59 62 … … 73 76 VALUES (?, ?, ?, ?, ?, ?) 74 77 `).run(commentId, post.id, req.session.user.id, resolvedParent, rawContent, status); 78 79 // Melding (alleen bij een zichtbare reactie): antwoord → de auteur van de reactie 80 // waarop gereageerd is; top-level reactie → de auteur van de post. notify() slaat 81 // jezelf-notificeren over. 82 if (status === 'approved') { 83 const url = `${res.locals.siteUrlBase || ''}/${post.slug}#comment-${commentId}`; 84 const actorId = req.session.user.id; 85 const actorName = req.session.user.username; 86 if (parentId) { 87 notify({ userId: parentAuthorId, actorId, actorName, type: 'reply', postSlug: post.slug, postTitle: post.title, url }); 88 } else { 89 notify({ userId: post.author_id, actorId, actorName, type: 'comment', postSlug: post.slug, postTitle: post.title, url }); 90 } 91 } 75 92 76 93 // Where to land after submit: -
src/routes/posts.js
rd41f4be rc9c6a2d 10 10 import { renderPage } from '../middleware/render.js'; 11 11 import { recordPageview, recordPostView } from '../services/StatsService.js'; 12 import { notify } from '../services/NotificationService.js'; 12 13 import PermissionsService from '../services/PermissionsService.js'; 13 14 import MarkdownService from '../services/MarkdownService.js'; … … 405 406 router.post('/posts/:id/like', requireAuth, (req, res) => { 406 407 const userId = req.session.user.id; 407 const post = db.prepare('SELECT id, status FROM posts WHERE id = ?').get(req.params.id);408 const post = db.prepare('SELECT id, status, slug, title, author_id FROM posts WHERE id = ?').get(req.params.id); 408 409 if (!post) return res.status(404).send('Post niet gevonden'); 409 410 if (post.status !== 'published') return res.status(403).send('Niet beschikbaar'); … … 414 415 } else { 415 416 db.prepare('INSERT OR IGNORE INTO post_likes (post_id, user_id) VALUES (?, ?)').run(post.id, userId); 417 // Melding voor de post-auteur (notify slaat jezelf-liken over). 418 notify({ 419 userId: post.author_id, actorId: userId, actorName: req.session.user.username, type: 'like', 420 postSlug: post.slug, postTitle: post.title, url: (res.locals.siteUrlBase || '') + '/' + post.slug, 421 }); 416 422 } 417 423 const likeCount = db.prepare('SELECT COUNT(*) AS c FROM post_likes WHERE post_id = ?').get(post.id).c;
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)