Changeset e951b7c in Klonkt


Ignore:
Timestamp:
06/25/2026 05:22:51 AM (3 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
4c9c60b
Parents:
d7526bd
Message:

feat(fediverse): real bell badge for unseen notifications

Track a per-site 'seen' timestamp (app_settings); the top-bar bell shows a badge
with the count of fediverse notifications newer than last-seen, and opening
/meldingen marks them seen (clears the badge). Replaces the dead user_notifications
counter.

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

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/middleware/render.js

    rd7526bd re951b7c  
    1919import { getSetting } from '../services/SettingsService.js';
    2020import { isPremium as isPremiumInstance, premiumEnabled, premiumUnlocked } from '../services/PatreonService.js';
    21 import { unreadCount as notifUnreadCount } from '../services/NotificationService.js';
     21import ActivityPubService from '../services/ActivityPubService.js';
    2222import { audioEnabled as audioFeatureEnabled } from '../config/features.js';
    2323import { PLATFORMS as PLATFORMS_CATALOG } from '../services/PlatformIcons.js';
     
    118118    langs: LANGS.map((c) => ({ code: c, name: LANG_NAMES[c], active: c === _lang })),
    119119    timezone: getSetting('timezone') || '',
    120     notifUnread: _u ? notifUnreadCount(_u.id) : 0,
     120    notifUnread: (canManageFedi && _site) ? ActivityPubService.countUnseenNotifications(_site.slug) : 0,
    121121    userOwnsSite,
    122122    canSeeBeheer,
  • src/routes/posts.js

    rd7526bd re951b7c  
    581581  const site = res.locals.site;
    582582  const items = site ? ActivityPubService.getNotifications(site.slug, 80) : [];
     583  if (site) ActivityPubService.markNotificationsSeen(site.slug); // viewing = seen → clears the bell badge
    583584  renderPage(req, res, 'pages/fedi-notifications', { pageTitle: 'Meldingen', bodyClass: 'on-special', items });
    584585});
  • src/services/ActivityPubService.js

    rd7526bd re951b7c  
    169169  } catch { /* non-fatal */ }
    170170  return out;
     171}
     172
     173// Notifications "seen" tracking → a real bell badge. Stored per site in app_settings.
     174export function markNotificationsSeen(slug) {
     175  try {
     176    db.prepare("INSERT INTO app_settings (key, value, updated_at) VALUES (?, ?, CURRENT_TIMESTAMP) ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP")
     177      .run(`fedi_notif_seen:${slug}`, new Date().toISOString());
     178  } catch { /* non-fatal */ }
     179}
     180export function countUnseenNotifications(slug) {
     181  try {
     182    const row = db.prepare('SELECT value FROM app_settings WHERE key = ?').get(`fedi_notif_seen:${slug}`);
     183    const seen = row ? Date.parse(row.value) : 0;
     184    let n = 0;
     185    for (const it of getNotifications(slug, 50)) { if (Date.parse(it.created_at) > seen) n++; }
     186    return n;
     187  } catch { return 0; }
    171188}
    172189
     
    919936  getNotifications, listBlocks, isBlockedAny, blockTarget, unblock,
    920937  deliverWithRetry, enqueueDelivery, processDeliveryQueue, startDeliveryWorker,
    921   getReplyUris,
     938  getReplyUris, markNotificationsSeen, countUnseenNotifications,
    922939};
  • src/views/partials/topnav.ejs

    rd7526bd re951b7c  
    103103           hx-get="/meldingen?partial=1" hx-target="#pcms-main" hx-swap="innerHTML" hx-push-url="/meldingen" hx-indicator="#pcms-loading">
    104104          <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 8a6 6 0 0 0-12 0c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 0 1-3.46 0"/></svg>
     105          <% if (typeof notifUnread !== 'undefined' && notifUnread > 0) { %><span class="notif-badge"><%= notifUnread > 9 ? '9+' : notifUnread %></span><% } %>
    105106        </a>
    106107      <% } %>
Note: See TracChangeset for help on using the changeset viewer.