source: Klonkt/src/views/pages/fedi-notifications.ejs@ fe97cc3

main
Last change on this file since fe97cc3 was fe97cc3, checked in by roboburr <roboburr@…>, 2 months ago

feat(fediverse): notification when mentioned in a non-reply post

An inbound Create whose Mention tag targets one of our actors — but which isn't a
reply to our content — was silently ignored. It's now stored and shown in the
fediverse notifications (@ icon, snippet, link to the original note). Only hrefs on
our own base count (a /ap/users/<slug> path on a remote host is someone else's actor).

  • src/config/database.js — ap_mentions table (per-site, UNIQUE(slug, object_uri)).
  • src/services/ActivityPubService.js — localMentionSlugs(tags, base) detection helper (own-base guard, slug must exist, deduped); the Create branch stores a mention per targeted site; getNotifications includes mentions.
  • src/views/pages/fedi-notifications.ejs — mention item (@ icon, content, view-original link).
  • src/services/i18n.js — notif.mentioned (nl/en/de).
  • test/inbound-mentions.test.js — detection guards + notification surfacing.
  • CHANGELOG(.nl/.de).md — "A mention is now a notification" under Added.

Closes prutfolio-src-xgg.

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

  • Property mode set to 100644
File size: 6.3 KB
Line 
1<div class="nt-wrap">
2 <%- include('../partials/fedi-tabs', { active: 'meldingen' }) %>
3 <h1 class="nt-title"><%= t('notif.title') %></h1>
4 <% if (!items || !items.length) { %>
5 <p class="nt-empty"><%= t('notif.empty') %></p>
6 <% } else { %>
7 <ul class="nt-list">
8 <% items.forEach(function(n){
9 var _ic = n.type === 'follow' ? 'follow' : (n.type === 'like' ? 'like' : (n.type === 'announce' ? 'boost' : (n.type === 'report' ? 'report' : (n.type === 'mention' ? 'mention' : 'reply'))));
10 %>
11 <li class="nt-item nt-<%= _ic %>">
12 <span class="nt-icon" aria-hidden="true">
13 <% if (_ic === 'like') { %><svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 2.6l2.9 5.88 6.49.95-4.7 4.58 1.11 6.46L12 17.96l-5.8 3.06 1.1-6.46-4.69-4.58 6.49-.95z"/></svg>
14 <% } else if (_ic === 'boost') { %><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="17 1 21 5 17 9"/><path d="M3 11V9a4 4 0 0 1 4-4h14"/><polyline points="7 23 3 19 7 15"/><path d="M21 13v2a4 4 0 0 1-4 4H3"/></svg>
15 <% } else if (_ic === 'follow') { %><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><line x1="19" y1="8" x2="19" y2="14"/><line x1="22" y1="11" x2="16" y2="11"/></svg>
16 <% } else if (_ic === 'report') { %><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z"/><line x1="4" y1="22" x2="4" y2="15"/></svg>
17 <% } else if (_ic === 'mention') { %><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-3.92 7.94"/></svg>
18 <% } else { %><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg><% } %>
19 </span>
20 <div class="nt-body">
21 <div class="nt-line">
22 <a class="nt-who" href="<%= n.url %>" target="_blank" rel="nofollow noopener"><%= n.name || n.handle %></a>
23 <% if (n.handle && n.name) { %><span class="nt-handle"><%= n.handle %></span><% } %>
24 <% if (n.created_at) { %><span class="nt-time"><%= formatDateTime(n.created_at) %></span><% } %>
25 </div>
26 <div class="nt-what">
27 <% if (n.type === 'follow') { %><%= t('notif.followed') %>
28 <% } else if (n.type === 'like') { %><%= t('notif.liked') %>
29 <% } else if (n.type === 'announce') { %><%= t('notif.boosted') %>
30 <% } else if (n.type === 'report') { %><%= t('notif.reported') %>
31 <% } else if (n.type === 'mention') { %><%= t('notif.mentioned') %>
32 <% } else { %><%= t('notif.replied') %><% } %>
33 <% if (n.post_slug) { %><a class="nt-post" href="/<%= n.post_slug %>"><%= n.post_title || n.post_slug %></a><% } %>
34 <% if (n.type === 'mention' && n.note_url) { %><a class="nt-post" href="<%= n.note_url %>" target="_blank" rel="nofollow noopener"><%= t('tl.view_original') %></a><% } %>
35 </div>
36 <% if (n.type === 'report' && n.content) { %><div class="nt-content"><%= n.content %></div>
37 <% } else if ((n.type === 'reply' || n.type === 'mention') && n.content) { %><div class="nt-content"><%- n.content %></div><% } %>
38 </div>
39 </li>
40 <% }); %>
41 </ul>
42 <% } %>
43</div>
44
45<style>
46 .nt-wrap { max-width: 640px; margin: 1rem auto; padding: 0 1rem; }
47 .fedi-back { margin: 0 0 1.25rem; }
48 .nt-title { margin: 0 0 1.25rem; }
49 .nt-empty { color: var(--ink-soft, #888); }
50 .nt-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .6rem; }
51 .nt-item { display: flex; gap: .85rem; padding: .9rem 1rem; border-radius: 14px; align-items: flex-start;
52 background: color-mix(in srgb, var(--ink, #000) 3.5%, transparent);
53 border: 1px solid color-mix(in srgb, var(--ink, #000) 9%, transparent);
54 transition: border-color .15s ease, box-shadow .15s ease; }
55 .nt-item:hover { border-color: color-mix(in srgb, var(--accent, #888) 30%, transparent);
56 box-shadow: 0 2px 12px color-mix(in srgb, var(--ink, #000) 6%, transparent); }
57 .nt-icon { flex: 0 0 38px; width: 38px; height: 38px; border-radius: 50%;
58 display: inline-flex; align-items: center; justify-content: center; }
59 .nt-icon svg { width: 18px; height: 18px; }
60 .nt-like .nt-icon { background: color-mix(in srgb, #e8b04b 16%, transparent); color: #e8b04b; }
61 .nt-boost .nt-icon { background: color-mix(in srgb, #2fa85a 16%, transparent); color: #2fa85a; }
62 .nt-follow .nt-icon, .nt-reply .nt-icon { background: color-mix(in srgb, var(--accent, #888) 16%, transparent); color: var(--accent, #06c); }
63 .nt-report .nt-icon { background: color-mix(in srgb, #c0392b 16%, transparent); color: #c0392b; }
64 .nt-mention .nt-icon { background: color-mix(in srgb, #8e6cf0 16%, transparent); color: #8e6cf0; }
65 .nt-body { flex: 1; min-width: 0; }
66 .nt-line { display: flex; align-items: baseline; gap: .4rem; }
67 .nt-who { font-weight: 700; color: var(--ink, inherit); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
68 .nt-who:hover { text-decoration: underline; }
69 .nt-handle { color: var(--ink-soft, #888); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
70 .nt-time { color: var(--ink-soft, #999); font-size: .76rem; margin-left: auto; flex: 0 0 auto; white-space: nowrap; }
71 .nt-what { color: var(--ink-soft, #aaa); margin-top: .12rem; line-height: 1.4; }
72 .nt-post { color: var(--accent, #06c); font-weight: 600; }
73 .nt-content { margin: .45rem 0 0; padding: .55rem .75rem; border-radius: 10px; line-height: 1.5;
74 background: color-mix(in srgb, var(--ink, #000) 4%, transparent); color: var(--ink, inherit); overflow-wrap: anywhere; }
75 .nt-content p { margin: .2rem 0; } .nt-content p:first-child { margin-top: 0; } .nt-content p:last-child { margin-bottom: 0; }
76</style>
Note: See TracBrowser for help on using the repository browser.