mirror of
https://github.com/svemagie/indiekit-endpoint-activitypub.git
synced 2026-04-02 15:44:58 +02:00
fix: synthesize timeline content for likes/bookmarks/reposts
Interaction types (likes, bookmarks, reposts) have no body content in their JF2 properties. The timeline entry was created with empty content, showing blank posts in Phanpy/Moshidon. Now synthesizes display content (e.g. "Liked: https://...") matching backfill-timeline.js behavior.
This commit is contained in:
@@ -224,7 +224,7 @@ export function createSyndicator(plugin) {
|
||||
// timelines (Phanpy/Moshidon). Uses $setOnInsert — idempotent.
|
||||
try {
|
||||
const profile = await plugin._collections.ap_profile?.findOne({});
|
||||
const content = normalizeContent(properties.content);
|
||||
const content = buildTimelineContent(properties);
|
||||
const timelineItem = {
|
||||
uid: properties.url,
|
||||
url: properties.url,
|
||||
@@ -289,13 +289,51 @@ export function createSyndicator(plugin) {
|
||||
|
||||
// ─── Timeline helpers ───────────────────────────────────────────────────────
|
||||
|
||||
function normalizeContent(content) {
|
||||
if (!content) return { text: "", html: "" };
|
||||
if (typeof content === "string") return { text: content, html: `<p>${content}</p>` };
|
||||
return {
|
||||
text: content.text || content.value || "",
|
||||
html: content.html || content.text || content.value || "",
|
||||
};
|
||||
/**
|
||||
* Build content from JF2 properties. Synthesizes content for interaction
|
||||
* types (likes, bookmarks, reposts) that have no body text.
|
||||
*/
|
||||
function buildTimelineContent(properties) {
|
||||
const content = properties.content;
|
||||
if (content) {
|
||||
if (typeof content === "string") return { text: content, html: `<p>${content}</p>` };
|
||||
if (content.text || content.html) {
|
||||
return {
|
||||
text: content.text || content.value || "",
|
||||
html: content.html || content.text || content.value || "",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Synthesize for interaction types
|
||||
const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
||||
const likeOf = properties["like-of"];
|
||||
if (likeOf) {
|
||||
return {
|
||||
text: `Liked: ${likeOf}`,
|
||||
html: `<p>Liked: <a href="${esc(likeOf)}">${esc(likeOf)}</a></p>`,
|
||||
};
|
||||
}
|
||||
const bookmarkOf = properties["bookmark-of"];
|
||||
if (bookmarkOf) {
|
||||
const label = properties.name || bookmarkOf;
|
||||
return {
|
||||
text: `Bookmarked: ${label}`,
|
||||
html: `<p>Bookmarked: <a href="${esc(bookmarkOf)}">${esc(label)}</a></p>`,
|
||||
};
|
||||
}
|
||||
const repostOf = properties["repost-of"];
|
||||
if (repostOf) {
|
||||
const label = properties.name || repostOf;
|
||||
return {
|
||||
text: `Reposted: ${label}`,
|
||||
html: `<p>Reposted: <a href="${esc(repostOf)}">${esc(label)}</a></p>`,
|
||||
};
|
||||
}
|
||||
if (properties.name) {
|
||||
return { text: properties.name, html: `<p>${esc(properties.name)}</p>` };
|
||||
}
|
||||
return { text: "", html: "" };
|
||||
}
|
||||
|
||||
function mapPostType(postType) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@rmdes/indiekit-endpoint-activitypub",
|
||||
"version": "3.10.1",
|
||||
"version": "3.10.2",
|
||||
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
|
||||
"keywords": [
|
||||
"indiekit",
|
||||
|
||||
Reference in New Issue
Block a user