Changeset c9c6a2d in Klonkt for src/routes/posts.js


Ignore:
Timestamp:
06/21/2026 06:38:24 PM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
9a34d31
Parents:
d41f4be
Message:

feat(meldingen): notifications — reply on comment, comment on post, like on post

For every logged-in user (Google visitors/fans and admin). Bell icon in the
header with unread counter + notifications page /notifications (via user menu
desktop + profile sheet mobile; badge also on the mobile Profile tab). Opening =
read. Triggers in comments (reply→comment author, top-level→post author) and
like (→post author); notify() skips notifying yourself. Table notifications
+ NotificationService. NL/EN/DE.

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/posts.js

    rd41f4be rc9c6a2d  
    1010import { renderPage } from '../middleware/render.js';
    1111import { recordPageview, recordPostView } from '../services/StatsService.js';
     12import { notify } from '../services/NotificationService.js';
    1213import PermissionsService from '../services/PermissionsService.js';
    1314import MarkdownService from '../services/MarkdownService.js';
     
    405406router.post('/posts/:id/like', requireAuth, (req, res) => {
    406407  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);
    408409  if (!post) return res.status(404).send('Post niet gevonden');
    409410  if (post.status !== 'published') return res.status(403).send('Niet beschikbaar');
     
    414415  } else {
    415416    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    });
    416422  }
    417423  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.