diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js index ec293504f1..35fd9eb75d 100644 --- a/src/activitypub/helpers.js +++ b/src/activitypub/helpers.js @@ -367,13 +367,25 @@ Helpers.generateTitle = (html) => { return title; }; -Helpers.remoteAnchorToLocalProfile = async (content) => { - const anchorRegex = /(.*?)<\/a>/ig; +Helpers.remoteAnchorToLocalProfile = async (content, isMarkdown = false) => { + let anchorRegex; + if (isMarkdown) { + anchorRegex = /\[(.*?)\]\((.+?)\)/ig; + } else { + anchorRegex = /(.*?)<\/a>/ig; + } + const anchors = content.matchAll(anchorRegex); const urls = new Set(); const matches = []; for (const anchor of anchors) { - const [match, url] = anchor; + let match; + let url; + if (isMarkdown) { + [match,, url] = anchor; + } else { + [match, url] = anchor; + } matches.push([match, url]); urls.add(url); } diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js index 0c17f83304..67c6636bc4 100644 --- a/src/activitypub/mocks.js +++ b/src/activitypub/mocks.js @@ -176,9 +176,10 @@ Mocks.post = async (objects) => { let edited = new Date(updated); edited = Number.isNaN(edited.valueOf()) ? undefined : edited; - const sourceContent = source && source.mediaType === 'text/markdown' ? source.content : undefined; + let sourceContent = source && source.mediaType === 'text/markdown' ? source.content : undefined; if (sourceContent) { content = null; + sourceContent = await activitypub.helpers.remoteAnchorToLocalProfile(sourceContent, true); } else if (content && content.length) { content = sanitize(content, sanitizeConfig); content = await activitypub.helpers.remoteAnchorToLocalProfile(content); diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js index 0e9df7bcb3..eb22dc292c 100644 --- a/src/activitypub/notes.js +++ b/src/activitypub/notes.js @@ -183,7 +183,6 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => { _activitypub: mainPost._activitypub, }), Notes.updateLocalRecipients(mainPid, { to, cc }), - posts.attachments.update(mainPid, attachment), ]); unprocessed.shift(); @@ -193,6 +192,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => { id: tid, path: mainPost._activitypub.image, }) : null, + posts.attachments.update(mainPid, attachment), ]); if (context) {