Node.js based forum software built for the modern web
fix: some wip code regarding handling a follow activity, remove unfollow activity as that does not exist
Julian Lamf3b0794d179f
diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.jsindex de64dcde6c..78de0bfb69 100644--- a/src/activitypub/inbox.js+++ b/src/activitypub/inbox.js@@ -8,69 +8,44 @@ const helpers = require('./helpers');const inbox = module.exports;-inbox.follow = async (actorId, objectId) => {- await handleFollow('follow', actorId, objectId);-};--inbox.unfollow = async (actorId, objectId) => {- await handleFollow('unfollow', actorId, objectId);-};--inbox.isFollowed = async (actorId, uid) => {- if (actorId.indexOf('@') === -1 || parseInt(uid, 10) <= 0) {- return false;- }- return await db.isSortedSetMember(`followersRemote:${uid}`, actorId);-};--async function handleFollow(type, actorId, objectId) {+inbox.follow = async (req) => {// Sanity checks- const from = await helpers.query(actorId);- if (!actorId || !from) {- throw new Error('[[error:invalid-uid]]'); // should probably be AP specific- }-- if (!objectId) {+ const from = await activitypub.getActor(req.body.actor);+ if (!from) {throw new Error('[[error:invalid-uid]]'); // should probably be AP specific}- const localUid = await helpers.resolveLocalUid(objectId);+ const localUid = await helpers.resolveLocalUid(req.body.object);if (!localUid) {throw new Error('[[error:invalid-uid]]');}- // matches toggleFollow() in src/user/follow.js- const isFollowed = await inbox.isFollowed(actorId, localUid);- if (type === 'follow') {- if (isFollowed) {- throw new Error('[[error:already-following]]');- }- const now = Date.now();- await db.sortedSetAdd(`followersRemote:${localUid}`, now, actorId);- await activitypub.send(localUid, actorId, {- type: 'Accept',- object: {- type: 'Follow',- actor: from.actorUri,- },- });- } else {- if (!isFollowed) {- throw new Error('[[error:not-following]]');- }- await db.sortedSetRemove(`followersRemote:${localUid}`, actorId);- await activitypub.send(localUid, actorId, {- type: 'Undo',- object: {- type: 'Follow',- actor: from.actorUri,- },- });+ const isFollowed = await inbox.isFollowed(from.id, localUid);+ if (isFollowed) {+ // No additional parsing required+ return;}+ const now = Date.now();+ await db.sortedSetAdd(`followersRemote:${localUid}`, now, from.id);+ await activitypub.send(localUid, from.id, {+ type: 'Accept',+ object: {+ type: 'Follow',+ actor: from.actorUri,+ },+ });+const followerRemoteCount = await db.sortedSetCard(`followersRemote:${localUid}`);await user.setUserField(localUid, 'followerRemoteCount', followerRemoteCount);-}+};++inbox.isFollowed = async (actorId, uid) => {+ if (actorId.indexOf('@') === -1 || parseInt(uid, 10) <= 0) {+ return false;+ }+ return await db.isSortedSetMember(`followersRemote:${uid}`, actorId);+};inbox.accept = async (req) => {const { actor, object } = req.body;diff --git a/src/controllers/activitypub/index.js b/src/controllers/activitypub/index.jsindex cc23b1c8b0..4477efeb38 100644--- a/src/controllers/activitypub/index.js+++ b/src/controllers/activitypub/index.js@@ -104,12 +104,7 @@ Controller.postInbox = async (req, res) => {// Note: underlying methods are internal use only, hence no exposure via src/apiswitch (req.body.type) {case 'Follow': {- await activitypub.inbox.follow(req.body.actor.name, req.body.object.name);- break;- }-- case 'Unfollow': {- await activitypub.inbox.unfollow(req.body.actor.name, req.body.object.name);+ await activitypub.inbox.follow(req);break;}