fix: #13397, update getCidByHandle to work with remote categories, fix sync with handles causing issues with null entries

This commit is contained in:
Julian Lam
2025-05-08 13:41:43 -04:00
parent 10077d0f89
commit a9a5ab5e4b
2 changed files with 16 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ const winston = require('winston');
const db = require('../database'); const db = require('../database');
const user = require('../user'); const user = require('../user');
const categories = require('../categories');
const meta = require('../meta'); const meta = require('../meta');
const privileges = require('../privileges'); const privileges = require('../privileges');
const activitypub = require('../activitypub'); const activitypub = require('../activitypub');
@@ -43,7 +44,14 @@ activitypubApi.follow = enabledCheck(async (caller, { type, id, actor } = {}) =>
throw new Error('[[error:activitypub.invalid-id]]'); throw new Error('[[error:activitypub.invalid-id]]');
} }
actor = actor.includes('@') ? await user.getUidByUserslug(actor) : actor; if (actor.includes('@')) {
const [uid, cid] = await Promise.all([
user.getUidByUserslug(actor),
categories.getCidByHandle(actor),
]);
actor = uid || cid;
}
const [handle, isFollowing] = await Promise.all([ const [handle, isFollowing] = await Promise.all([
user.getUserField(actor, 'username'), user.getUserField(actor, 'username'),
db.isSortedSetMember(type === 'uid' ? `followingRemote:${id}` : `cid:${id}:following`, actor), db.isSortedSetMember(type === 'uid' ? `followingRemote:${id}` : `cid:${id}:following`, actor),

View File

@@ -85,7 +85,13 @@ Categories.getCategoryById = async function (data) {
}; };
Categories.getCidByHandle = async function (handle) { Categories.getCidByHandle = async function (handle) {
return await db.sortedSetScore('categoryhandle:cid', handle); let cid = await db.sortedSetScore('categoryhandle:cid', handle);
if (!cid) {
// remote cids
cid = await db.getObjectField('handle:cid', handle);
}
return cid;
}; };
Categories.getAllCidsFromSet = async function (key) { Categories.getAllCidsFromSet = async function (key) {