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);
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 {

View File

@@ -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'),
]);
}
};

View File

@@ -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,
};

View File

@@ -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) {

View File

@@ -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,
},
});

View File

@@ -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);
};
};

View File

@@ -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
});
});
});