Skip to content

Node.js based forum software built for the modern web

fix: lemmy integration, handle `image` property as topic thumb

Julian Lamb15a684a9200
diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js
index 83e4ef6151..55b3b7874f 100644
--- a/src/activitypub/mocks.js
+++ b/src/activitypub/mocks.js
@@ -165,8 +165,7 @@ Mocks.post = async (objects) => {
attributedTo: uid,
inReplyTo: toPid,
published, updated, name, content, source,
- to, cc, audience, attachment, tag,
- // conversation, // mastodon-specific, ignored.
+ to, cc, audience, attachment, tag, image,
} = object;
const resolved = await activitypub.helpers.resolveLocalId(toPid);
@@ -187,6 +186,22 @@ Mocks.post = async (objects) => {
content = '<em>This post did not contain any content.</em>';
}
+ switch (true) {
+ case image && image.hasOwnProperty('url') && image.url && mime.getType(image.url).startsWith('image/'): {
+ image = image.url;
+ break;
+ }
+
+ case image && typeof image === 'string' && mime.getType(image).startsWith('image/'): {
+ // no change
+ break;
+ }
+
+ default: {
+ image = null;
+ }
+ }
+
const payload = {
uid,
pid,
@@ -199,7 +214,7 @@ Mocks.post = async (objects) => {
edited,
editor: edited ? uid : undefined,
- _activitypub: { to, cc, audience, attachment, tag, url },
+ _activitypub: { to, cc, audience, attachment, tag, url, image },
};
return payload;
diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js
index ed7eb30676..592e966f89 100644
--- a/src/activitypub/notes.js
+++ b/src/activitypub/notes.js
@@ -187,6 +187,14 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
]);
unprocessed.shift();
+ // These must come after topic is posted
+ await Promise.all([
+ mainPost._activitypub.image ? topics.thumbs.associate({
+ id: tid,
+ path: mainPost._activitypub.image,
+ }) : null,
+ ]);
+
if (context) {
activitypub.helpers.log(`[activitypub/notes.assert] Associating tid ${tid} with context ${context}`);
await topics.setTopicField(tid, 'context', context);