fix: lemmy integration, handle image property as topic thumb

This commit is contained in:
Julian Lam
2024-12-12 11:37:22 -05:00
parent 3439fdb600
commit b15a684a92
2 changed files with 26 additions and 3 deletions

View File

@@ -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;

View File

@@ -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);