From b252f69f0573ee41588cb3e84a87050403201fef Mon Sep 17 00:00:00 2001 From: Nathan Byrd Date: Fri, 6 Jan 2023 16:09:08 -0600 Subject: [PATCH] Changes to work with Mastodon. Also fixed variable rename issue --- core/activitypub_util.js | 6 +++++- core/servers/content/web_handlers/activitypub.js | 9 +++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/activitypub_util.js b/core/activitypub_util.js index ba8f23c5..5e3259e0 100644 --- a/core/activitypub_util.js +++ b/core/activitypub_util.js @@ -45,6 +45,10 @@ function selfUrl(webServer, user) { } function userFromAccount(accountName, cb) { + if (accountName.startsWith('@')) { + accountName = accountName.slice(1); + } + User.getUserIdAndName(accountName, (err, userId) => { if (err) { return cb(err); @@ -58,7 +62,7 @@ function userFromAccount(accountName, cb) { const accountStatus = user.getPropertyAsNumber(UserProps.AccountStatus); if ( User.AccountStatus.disabled == accountStatus || - User.AccountStatus.inactive == accountStatus + User.AccountStatus.inactive == accountStatus ) { return cb(Errors.AccessDenied('Account disabled', ErrorReasons.Disabled)); } diff --git a/core/servers/content/web_handlers/activitypub.js b/core/servers/content/web_handlers/activitypub.js index 7c3ffa0d..7fec6644 100644 --- a/core/servers/content/web_handlers/activitypub.js +++ b/core/servers/content/web_handlers/activitypub.js @@ -66,7 +66,8 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule { } const accept = req.headers['accept'] || '*/*'; - if (accept === 'application/activity+json') { + const headerValues = ['application/activity+json', 'application/ld+json', 'application/json']; + if (headerValues.some(mime => accept.includes(mime))) { sendActor = true; } @@ -81,14 +82,14 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule { } _selfAsActorHandler(user, req, resp) { - const selfUrl = selfUrl(this.webServer, user); + const sUrl = selfUrl(this.webServer, user); const bodyJson = { '@context': [ 'https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', ], - id: selfUrl, + id: sUrl, type: 'Person', preferredUsername: user.username, name: user.getSanitizedName('real'), @@ -108,7 +109,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule { const publicKeyPem = user.getProperty(UserProps.PublicKeyMain); if (!_.isEmpty(publicKeyPem)) { bodyJson['publicKey'] = { - id: selfUrl + '#main-key', + id: sUrl + '#main-key', owner: sUrl, publicKeyPem: user.getProperty(UserProps.PublicKeyMain), };