fix: remote follows, yet again

This commit is contained in:
Julian Lam
2024-01-26 22:35:02 -05:00
parent a3a0edb70b
commit fef1882473
7 changed files with 15 additions and 15 deletions

View File

@@ -94,10 +94,9 @@ Helpers.resolveLocalUid = async (input) => {
const { host, pathname } = new URL(input); const { host, pathname } = new URL(input);
if (host === nconf.get('url_parsed').host) { if (host === nconf.get('url_parsed').host) {
slug = pathname.replace(nconf.get('relative_path'), '').split('/').filter(Boolean)[1]; return pathname.replace(nconf.get('relative_path'), '').split('/').filter(Boolean)[1];
} else {
throw new Error('[[error:activitypub.invalid-id]]');
} }
throw new Error('[[error:activitypub.invalid-id]]');
} else if (input.indexOf('@') !== -1) { // Webfinger } else if (input.indexOf('@') !== -1) { // Webfinger
([slug] = input.replace(/^acct:/, '').split('@')); ([slug] = input.replace(/^acct:/, '').split('@'));
} else { } else {

View File

@@ -124,8 +124,8 @@ inbox.undo = async (req) => {
if (type === 'Follow') { if (type === 'Follow') {
await Promise.all([ await Promise.all([
db.sortedSetRemove(`followingRemote:${uid}`, actor), db.sortedSetRemove(`followersRemote:${uid}`, actor),
db.decrObjectField(`user:${uid}`, 'followingRemoteCount'), db.decrObjectField(`user:${uid}`, 'followerRemoteCount'),
]); ]);
} }
}; };

View File

@@ -190,12 +190,11 @@ ActivityPub.send = async (uid, targets, payload) => {
targets = [targets]; targets = [targets];
} }
const userslug = await user.getUserField(uid, 'userslug');
const inboxes = await ActivityPub.resolveInboxes(targets); const inboxes = await ActivityPub.resolveInboxes(targets);
payload = { payload = {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',
actor: `${nconf.get('url')}/user/${userslug}`, actor: `${nconf.get('url')}/uid/${uid}`,
...payload, ...payload,
}; };

View File

@@ -24,7 +24,6 @@ Mocks.profile = async (actors) => {
postcount, inbox, endpoints, postcount, inbox, endpoints,
} = actor; } = actor;
const { hostname } = new URL(actor.id); const { hostname } = new URL(actor.id);
// const isFollowing = await db.isSortedSetMember(`followingRemote:${callerUid}`, uid);
let picture; let picture;
if (icon) { if (icon) {

View File

@@ -12,7 +12,6 @@ const nconf = require('nconf');
const db = require('../database'); const db = require('../database');
const activitypub = require('../activitypub'); const activitypub = require('../activitypub');
const user = require('../user');
const posts = require('../posts'); const posts = require('../posts');
const activitypubApi = module.exports; const activitypubApi = module.exports;
@@ -23,24 +22,23 @@ activitypubApi.follow = async (caller, { uid } = {}) => {
throw new Error('[[error:activitypub.invalid-id]]'); throw new Error('[[error:activitypub.invalid-id]]');
} }
await activitypub.send(caller.uid, uid, { await activitypub.send(caller.uid, [result.actorUri], {
type: 'Follow', type: 'Follow',
object: result.actorUri, object: result.actorUri,
}); });
}; };
activitypubApi.unfollow = async (caller, { uid }) => { activitypubApi.unfollow = async (caller, { uid }) => {
const userslug = await user.getUserField(caller.uid, 'userslug');
const result = await activitypub.helpers.query(uid); const result = await activitypub.helpers.query(uid);
if (!result) { if (!result) {
throw new Error('[[error:activitypub.invalid-id]]'); throw new Error('[[error:activitypub.invalid-id]]');
} }
await activitypub.send(caller.uid, uid, { await activitypub.send(caller.uid, [result.actorUri], {
type: 'Undo', type: 'Undo',
object: { object: {
type: 'Follow', type: 'Follow',
actor: `${nconf.get('url')}/user/${userslug}`, actor: `${nconf.get('url')}/uid/${caller.uid}`,
object: result.actorUri, object: result.actorUri,
}, },
}); });

View File

@@ -2,6 +2,7 @@
'use strict'; 'use strict';
const plugins = require('../plugins'); const plugins = require('../plugins');
const activitypub = require('../activitypub');
const db = require('../database'); const db = require('../database');
module.exports = function (User) { module.exports = function (User) {
@@ -88,9 +89,11 @@ module.exports = function (User) {
} }
User.isFollowing = async function (uid, theirid) { 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 false;
} }
return await db.isSortedSetMember(`following:${uid}`, theirid); const setPrefix = isRemote ? 'followingRemote' : 'following';
return await db.isSortedSetMember(`${setPrefix}:${uid}`, theirid);
}; };
}; };

View File

@@ -442,6 +442,8 @@ describe('ActivityPub integration', () => {
it('should properly save the mainPid in the topic hash', async () => { it('should properly save the mainPid in the topic hash', async () => {
assert.strictEqual(topic.mainPid, note.id); assert.strictEqual(topic.mainPid, note.id);
}); });
// todo: test topic replies, too
}); });
}); });
}); });