mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-05 07:10:30 +01:00
fix: category following and acceptance logic
This commit is contained in:
@@ -109,13 +109,10 @@ inbox.follow = async (req) => {
|
||||
}
|
||||
|
||||
const watchState = await categories.getWatchState([id], req.body.actor);
|
||||
if (watchState === categories.watchStates.tracking) {
|
||||
// No additional parsing required
|
||||
return;
|
||||
if (watchState[0] !== categories.watchStates.tracking) {
|
||||
await user.setCategoryWatchState(req.body.actor, id, categories.watchStates.tracking);
|
||||
}
|
||||
|
||||
await user.setCategoryWatchState(req.body.actor, id, categories.watchStates.tracking);
|
||||
|
||||
await activitypub.send('cid', id, req.body.actor, {
|
||||
type: 'Accept',
|
||||
object: {
|
||||
@@ -149,10 +146,9 @@ inbox.accept = async (req) => {
|
||||
|
||||
if (type === 'Follow') {
|
||||
const now = Date.now();
|
||||
await Promise.all([
|
||||
db.sortedSetAdd(`followingRemote:${uid}`, now, actor),
|
||||
db.incrObjectField(`user:${uid}`, 'followingRemoteCount'),
|
||||
]);
|
||||
await db.sortedSetAdd(`followingRemote:${uid}`, now, actor);
|
||||
const followingRemoteCount = await db.sortedSetCard(`followingRemote:${uid}`);
|
||||
await user.setUserField(uid, 'followingRemoteCount', followingRemoteCount);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -177,10 +173,9 @@ inbox.undo = async (req) => {
|
||||
throw new Error('[[error:invalid-uid]]');
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
db.sortedSetRemove(`followersRemote:${id}`, actor),
|
||||
db.decrObjectField(`user:${id}`, 'followerRemoteCount'),
|
||||
]);
|
||||
await db.sortedSetRemove(`followersRemote:${id}`, actor);
|
||||
const followerRemoteCount = await db.sortedSetCard(`followerRemote:${id}`);
|
||||
await user.setUserField(id, 'followerRemoteCount', followerRemoteCount);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ ActivityPub.getPublicKey = async (type, id) => {
|
||||
let publicKey;
|
||||
|
||||
try {
|
||||
({ publicKey } = await db.getObject(`uid:${id}:keys`));
|
||||
({ publicKey } = await db.getObject(`${type}:${id}:keys`));
|
||||
} catch (e) {
|
||||
({ publicKey } = await ActivityPub.helpers.generateKeys(type, id));
|
||||
}
|
||||
@@ -145,6 +145,7 @@ ActivityPub.verify = async (req) => {
|
||||
return memo;
|
||||
}, []).join('\n');
|
||||
|
||||
|
||||
// Verify the signature string via public key
|
||||
try {
|
||||
// Retrieve public key from remote instance
|
||||
@@ -196,9 +197,25 @@ ActivityPub.send = async (type, id, targets, payload) => {
|
||||
|
||||
const inboxes = await ActivityPub.resolveInboxes(targets);
|
||||
|
||||
let actor;
|
||||
switch (type) {
|
||||
case 'uid': {
|
||||
actor = `${nconf.get('url')}/uid/${id}`;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'cid': {
|
||||
actor = `${nconf.get('url')}/category/${id}`;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error('[[error:activitypub.invalid-id]]');
|
||||
}
|
||||
|
||||
payload = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
actor: `${nconf.get('url')}/uid/${id}`,
|
||||
actor,
|
||||
...payload,
|
||||
};
|
||||
|
||||
@@ -220,3 +237,10 @@ ActivityPub.send = async (type, id, targets, payload) => {
|
||||
}
|
||||
}));
|
||||
};
|
||||
|
||||
setTimeout(async () => {
|
||||
await ActivityPub.send('uid', 1, 'https://localhost/category/1', {
|
||||
type: 'Follow',
|
||||
object: 'https://localhost/category/1',
|
||||
});
|
||||
}, 2000);
|
||||
|
||||
@@ -164,6 +164,7 @@ Mocks.actors.user = async (uid) => {
|
||||
|
||||
Mocks.actors.category = async (cid) => {
|
||||
let { name, slug, description: summary, backgroundImage } = await categories.getCategoryData(cid);
|
||||
const publicKey = await activitypub.getPublicKey('cid', cid);
|
||||
|
||||
if (backgroundImage) {
|
||||
const filename = utils.decodeHTMLEntities(backgroundImage).split('/').pop();
|
||||
@@ -189,6 +190,12 @@ Mocks.actors.category = async (cid) => {
|
||||
preferredUsername: `cid.${cid}`,
|
||||
summary,
|
||||
icon: backgroundImage,
|
||||
|
||||
publicKey: {
|
||||
id: `${nconf.get('url')}/category/${cid}#key`,
|
||||
owner: `${nconf.get('url')}/category/${cid}`,
|
||||
publicKeyPem: publicKey,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user