mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
fix: remote follows, yet again
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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'),
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user