Changeset 9a00f28 in Klonkt for src/services/ActivityPubService.js
- Timestamp:
- 07/22/2026 08:18:39 AM (7 weeks ago)
- Branches:
- main
- Children:
- 6b5d7da
- Parents:
- 96c714f
- git-author:
- Robin <roboburr@…> (07/22/2026 08:18:19 AM)
- git-committer:
- Robin <roboburr@…> (07/22/2026 08:18:39 AM)
- File:
-
- 1 edited
-
src/services/ActivityPubService.js (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/services/ActivityPubService.js
r96c714f r9a00f28 24 24 import Push from './PushService.js'; 25 25 import { getTenancy } from './SettingsService.js'; 26 import { t as i18nT } from './i18n.js'; 26 27 27 28 const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'; … … 1273 1274 try { return getTenancy() === 'hub' ? `/user/${slug}` : ''; } catch { return ''; } 1274 1275 } 1276 // Notification language: the site's content language (fallback: instance default). 1277 function pushLang(slug) { 1278 try { const r = db.prepare('SELECT language FROM sites WHERE slug = ?').get(slug); return (r && r.language) || process.env.KLONKT_DEFAULT_LANG || 'nl'; } catch { return 'nl'; } 1279 } 1275 1280 // Site slug, target URL and title for a post-scoped notification. 1276 1281 function pushPostCtx(postId) { … … 1343 1348 fStmts().ins.run(slug, who, remote.inbox, sharedInbox, fi.name, fi.handle, fi.icon); 1344 1349 try { _updFDisp.run(fi.name, fi.handle, fi.icon, slug, who); } catch { /* best effort */ } 1345 pushEvent(slug, { type: 'follow', title: 'Nieuwe volger', body: `${fi.name || fi.handle || 'Iemand'} volgt je nu`, url: `${pushPrefix(slug)}/connect` });1350 { const L = pushLang(slug); pushEvent(slug, { type: 'follow', title: i18nT(L, 'push.n_follow_t'), body: i18nT(L, 'push.n_follow_b', { who: fi.name || fi.handle || i18nT(L, 'notif.someone') }), url: `${pushPrefix(slug)}/connect` }); } 1346 1351 const me = actorId(base, slug); 1347 1352 const keys = getOrCreateKeys(slug); … … 1413 1418 const vis = noteVisibility(o); 1414 1419 const priv = vis === 'direct' || vis === 'followers'; 1415 const who = ai.name || ai.handle || 'Iemand';1416 1420 if (ctx) { 1417 if (priv) pushEvent(ctx.site, { type: 'dm', title: 'Privébericht', body: `Nieuw bericht van ${who}`, url: `${pushPrefix(ctx.site)}/messages` }); 1418 else pushEvent(ctx.site, { type: 'reply', title: `Reactie op "${ctx.title}"`, body: `${who}: ${HtmlSanitizerService.toPlainText(html).slice(0, 90)}`, url: ctx.url }); 1421 const L = pushLang(ctx.site); 1422 const who = ai.name || ai.handle || i18nT(L, 'notif.someone'); 1423 if (priv) pushEvent(ctx.site, { type: 'dm', title: i18nT(L, 'push.n_dm_t'), body: i18nT(L, 'push.n_dm_b', { who }), url: `${pushPrefix(ctx.site)}/messages` }); 1424 else pushEvent(ctx.site, { type: 'reply', title: i18nT(L, 'push.n_reply_t', { title: ctx.title }), body: `${who}: ${HtmlSanitizerService.toPlainText(html).slice(0, 90)}`, url: ctx.url }); 1419 1425 } 1420 1426 } … … 1465 1471 const vis = noteVisibility(o); 1466 1472 const priv = vis === 'direct' || vis === 'followers'; 1467 const who = ai.name || ai.handle || 'Iemand'; 1473 const L = pushLang(slug); 1474 const who = ai.name || ai.handle || i18nT(L, 'notif.someone'); 1468 1475 // Same privacy rule as replies: private mentions push without content. 1469 if (priv) pushEvent(slug, { type: 'dm', title: 'Privébericht', body: `Nieuw bericht van ${who}`, url: `${pushPrefix(slug)}/messages` });1470 else pushEvent(slug, { type: 'reply', title: 'Vermelding', body: `${who}: ${HtmlSanitizerService.toPlainText(html).slice(0, 90)}`, url: `${pushPrefix(slug)}/messages` });1476 if (priv) pushEvent(slug, { type: 'dm', title: i18nT(L, 'push.n_dm_t'), body: i18nT(L, 'push.n_dm_b', { who }), url: `${pushPrefix(slug)}/messages` }); 1477 else pushEvent(slug, { type: 'reply', title: i18nT(L, 'push.n_mention_t'), body: `${who}: ${HtmlSanitizerService.toPlainText(html).slice(0, 90)}`, url: `${pushPrefix(slug)}/messages` }); 1471 1478 } 1472 1479 } catch { /* ignore */ } … … 1526 1533 { 1527 1534 const ctx = pushPostCtx(pid); 1528 const who = ai.name || ai.handle || 'Iemand';1529 1535 if (ctx) { 1530 if (type === 'Like') pushEvent(ctx.site, { type: 'like', title: 'Nieuwe waardering', body: `${who} waardeerde "${ctx.title}"`, url: ctx.url }); 1531 else pushEvent(ctx.site, { type: 'boost', title: 'Geboost', body: `${who} boostte "${ctx.title}"`, url: ctx.url }); 1536 const L = pushLang(ctx.site); 1537 const who = ai.name || ai.handle || i18nT(L, 'notif.someone'); 1538 if (type === 'Like') pushEvent(ctx.site, { type: 'like', title: i18nT(L, 'push.n_like_t'), body: i18nT(L, 'push.n_like_b', { who, title: ctx.title }), url: ctx.url }); 1539 else pushEvent(ctx.site, { type: 'boost', title: i18nT(L, 'push.n_boost_t'), body: i18nT(L, 'push.n_boost_b', { who, title: ctx.title }), url: ctx.url }); 1532 1540 } 1533 1541 } … … 2969 2977 } catch { /* ignore */ } 2970 2978 try { 2971 for (const r of db.prepare('SELECT actor_uri, actor_name, actor_handle, actor_icon, content, created_at FROM ap_reports WHERE slug = ? ORDER BY created_at DESC LIMIT ?').all(slug, L)) { 2972 out.push({ type: 'report', name: r.actor_name, handle: r.actor_handle, url: r.actor_uri, icon: r.actor_icon, content: r.content, created_at: r.created_at }); 2979 for (const r of db.prepare('SELECT actor_uri, actor_name, actor_handle, actor_icon, content, objects, created_at FROM ap_reports WHERE slug = ? ORDER BY created_at DESC LIMIT ?').all(slug, L)) { 2980 // The reported objects: our own notes resolve to post links so the owner 2981 // sees WHICH post the report is about; other URIs (e.g. the actor itself) 2982 // are skipped — the report row already names the account. 2983 const about = []; 2984 try { 2985 for (const u of JSON.parse(r.objects || '[]')) { 2986 const m = String(u).match(/\/ap\/notes\/([^/?#]+)/); 2987 if (!m) continue; 2988 const p = db.prepare('SELECT slug, title FROM posts WHERE id = ?').get(decodeURIComponent(m[1])); 2989 if (p) about.push({ slug: p.slug, title: p.title || p.slug }); 2990 } 2991 } catch { /* malformed objects json → no links */ } 2992 out.push({ type: 'report', name: r.actor_name, handle: r.actor_handle, url: r.actor_uri, icon: r.actor_icon, content: r.content, objects: about, created_at: r.created_at }); 2973 2993 } 2974 2994 } catch { /* ignore */ }
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)