Node.js based forum software built for the modern web
fix: remote follows, yet again
Julian Lamfef188247341
diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.jsindex fefeb8be06..be430eb2f5 100644--- a/src/activitypub/helpers.js+++ b/src/activitypub/helpers.js@@ -94,10 +94,9 @@ Helpers.resolveLocalUid = async (input) => {const { host, pathname } = new URL(input);if (host === nconf.get('url_parsed').host) {- slug = pathname.replace(nconf.get('relative_path'), '').split('/').filter(Boolean)[1];- } else {- throw new Error('[[error:activitypub.invalid-id]]');+ return pathname.replace(nconf.get('relative_path'), '').split('/').filter(Boolean)[1];}+ throw new Error('[[error:activitypub.invalid-id]]');} else if (input.indexOf('@') !== -1) { // Webfinger([slug] = input.replace(/^acct:/, '').split('@'));} else {diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.jsindex 4a5efec706..26be56e76a 100644--- a/src/activitypub/inbox.js+++ b/src/activitypub/inbox.js@@ -124,8 +124,8 @@ inbox.undo = async (req) => {if (type === 'Follow') {await Promise.all([- db.sortedSetRemove(`followingRemote:${uid}`, actor),- db.decrObjectField(`user:${uid}`, 'followingRemoteCount'),+ db.sortedSetRemove(`followersRemote:${uid}`, actor),+ db.decrObjectField(`user:${uid}`, 'followerRemoteCount'),]);}};diff --git a/src/activitypub/index.js b/src/activitypub/index.jsindex 6f276a4f06..d783f12e9a 100644--- a/src/activitypub/index.js+++ b/src/activitypub/index.js@@ -190,12 +190,11 @@ ActivityPub.send = async (uid, targets, payload) => {targets = [targets];}- const userslug = await user.getUserField(uid, 'userslug');const inboxes = await ActivityPub.resolveInboxes(targets);payload = {'@context': 'https://www.w3.org/ns/activitystreams',- actor: `${nconf.get('url')}/user/${userslug}`,+ actor: `${nconf.get('url')}/uid/${uid}`,...payload,};diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.jsindex 374d4dc994..982a840fee 100644--- a/src/activitypub/mocks.js+++ b/src/activitypub/mocks.js@@ -24,7 +24,6 @@ Mocks.profile = async (actors) => {postcount, inbox, endpoints,} = actor;const { hostname } = new URL(actor.id);- // const isFollowing = await db.isSortedSetMember(`followingRemote:${callerUid}`, uid);let picture;if (icon) {diff --git a/src/api/activitypub.js b/src/api/activitypub.jsindex 23b0d0363a..429c6e8afc 100644--- a/src/api/activitypub.js+++ b/src/api/activitypub.js@@ -12,7 +12,6 @@ const nconf = require('nconf');const db = require('../database');const activitypub = require('../activitypub');-const user = require('../user');const posts = require('../posts');const activitypubApi = module.exports;@@ -23,24 +22,23 @@ activitypubApi.follow = async (caller, { uid } = {}) => {throw new Error('[[error:activitypub.invalid-id]]');}- await activitypub.send(caller.uid, uid, {+ await activitypub.send(caller.uid, [result.actorUri], {type: 'Follow',object: result.actorUri,});};activitypubApi.unfollow = async (caller, { uid }) => {- const userslug = await user.getUserField(caller.uid, 'userslug');const result = await activitypub.helpers.query(uid);if (!result) {throw new Error('[[error:activitypub.invalid-id]]');}- await activitypub.send(caller.uid, uid, {+ await activitypub.send(caller.uid, [result.actorUri], {type: 'Undo',object: {type: 'Follow',- actor: `${nconf.get('url')}/user/${userslug}`,+ actor: `${nconf.get('url')}/uid/${caller.uid}`,object: result.actorUri,},});diff --git a/src/user/follow.js b/src/user/follow.jsindex a15ecb121f..ec7e36f10f 100644--- a/src/user/follow.js+++ b/src/user/follow.js@@ -2,6 +2,7 @@'use strict';const plugins = require('../plugins');+const activitypub = require('../activitypub');const db = require('../database');module.exports = function (User) {@@ -88,9 +89,11 @@ module.exports = function (User) {}User.isFollowing = async function (uid, theirid) {- if (parseInt(uid, 10) <= 0 || parseInt(theirid, 10) <= 0) {+ const isRemote = activitypub.helpers.isUri(theirid);+ if (parseInt(uid, 10) <= 0 || (!isRemote && (theirid, 10) <= 0)) {return false;}- return await db.isSortedSetMember(`following:${uid}`, theirid);+ const setPrefix = isRemote ? 'followingRemote' : 'following';+ return await db.isSortedSetMember(`${setPrefix}:${uid}`, theirid);};};diff --git a/test/activitypub.js b/test/activitypub.jsindex ca28f3423e..4221bee43c 100644--- a/test/activitypub.js+++ b/test/activitypub.js@@ -442,6 +442,8 @@ describe('ActivityPub integration', () => {it('should properly save the mainPid in the topic hash', async () => {assert.strictEqual(topic.mainPid, note.id);});++ // todo: test topic replies, too});});});