fix: remove unresolvable actors from parsing prior to mocking profile

This commit is contained in:
Julian Lam
2024-03-07 16:59:40 -05:00
parent 4a8b06e815
commit 39da3ab668

View File

@@ -43,7 +43,7 @@ Actors.assert = async (ids, options = {}) => {
const followersUrlMap = new Map();
const pubKeysMap = new Map();
const actors = await Promise.all(ids.map(async (id) => {
let actors = await Promise.all(ids.map(async (id) => {
try {
winston.verbose(`[activitypub/actors] Processing ${id}`);
const actor = (typeof id === 'object' && id.hasOwnProperty('id')) ? id : await activitypub.get('uid', 0, id);
@@ -83,17 +83,15 @@ Actors.assert = async (ids, options = {}) => {
return null;
}
}));
actors = actors.filter(Boolean); // remove unresolvable actors
// Build userData object for storage
const profiles = await activitypub.mocks.profile(actors);
const now = Date.now();
const bulkSet = profiles.reduce((memo, profile) => {
if (profile) {
const key = `userRemote:${profile.uid}`;
memo.push([key, profile], [`${key}:keys`, pubKeysMap.get(profile.uid)]);
}
return memo;
}, []);
if (followersUrlMap.size) {
@@ -104,7 +102,6 @@ Actors.assert = async (ids, options = {}) => {
const uidsForCurrent = profiles.map((p, idx) => (exists[idx] ? p.uid : 0));
const current = await user.getUsersFields(uidsForCurrent, ['username', 'fullname']);
const queries = profiles.reduce((memo, profile, idx) => {
if (profile) {
const { username, fullname } = current[idx];
if (username !== profile.username) {
@@ -124,7 +121,6 @@ Actors.assert = async (ids, options = {}) => {
memo.searchAdd.push(['ap.name:sorted', 0, `${profile.fullname.toLowerCase()}:${profile.uid}`]);
}
}
return memo;
}, { searchRemove: [], searchAdd: [], handleRemove: [], handleAdd: {} });
@@ -138,5 +134,5 @@ Actors.assert = async (ids, options = {}) => {
db.setObject('handle:uid', queries.handleAdd),
]);
return actors.every(Boolean);
return actors;
};