mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-17 14:00:29 +01:00
fix: remove unresolvable actors from parsing prior to mocking profile
This commit is contained in:
@@ -43,7 +43,7 @@ Actors.assert = async (ids, options = {}) => {
|
|||||||
|
|
||||||
const followersUrlMap = new Map();
|
const followersUrlMap = new Map();
|
||||||
const pubKeysMap = 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 {
|
try {
|
||||||
winston.verbose(`[activitypub/actors] Processing ${id}`);
|
winston.verbose(`[activitypub/actors] Processing ${id}`);
|
||||||
const actor = (typeof id === 'object' && id.hasOwnProperty('id')) ? id : await activitypub.get('uid', 0, 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;
|
return null;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
actors = actors.filter(Boolean); // remove unresolvable actors
|
||||||
|
|
||||||
// Build userData object for storage
|
// Build userData object for storage
|
||||||
const profiles = await activitypub.mocks.profile(actors);
|
const profiles = await activitypub.mocks.profile(actors);
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
const bulkSet = profiles.reduce((memo, profile) => {
|
const bulkSet = profiles.reduce((memo, profile) => {
|
||||||
if (profile) {
|
const key = `userRemote:${profile.uid}`;
|
||||||
const key = `userRemote:${profile.uid}`;
|
memo.push([key, profile], [`${key}:keys`, pubKeysMap.get(profile.uid)]);
|
||||||
memo.push([key, profile], [`${key}:keys`, pubKeysMap.get(profile.uid)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return memo;
|
return memo;
|
||||||
}, []);
|
}, []);
|
||||||
if (followersUrlMap.size) {
|
if (followersUrlMap.size) {
|
||||||
@@ -104,26 +102,24 @@ Actors.assert = async (ids, options = {}) => {
|
|||||||
const uidsForCurrent = profiles.map((p, idx) => (exists[idx] ? p.uid : 0));
|
const uidsForCurrent = profiles.map((p, idx) => (exists[idx] ? p.uid : 0));
|
||||||
const current = await user.getUsersFields(uidsForCurrent, ['username', 'fullname']);
|
const current = await user.getUsersFields(uidsForCurrent, ['username', 'fullname']);
|
||||||
const queries = profiles.reduce((memo, profile, idx) => {
|
const queries = profiles.reduce((memo, profile, idx) => {
|
||||||
if (profile) {
|
const { username, fullname } = current[idx];
|
||||||
const { username, fullname } = current[idx];
|
|
||||||
|
|
||||||
if (username !== profile.username) {
|
if (username !== profile.username) {
|
||||||
if (uidsForCurrent[idx] !== 0) {
|
if (uidsForCurrent[idx] !== 0) {
|
||||||
memo.searchRemove.push(['ap.preferredUsername:sorted', `${username.toLowerCase()}:${profile.uid}`]);
|
memo.searchRemove.push(['ap.preferredUsername:sorted', `${username.toLowerCase()}:${profile.uid}`]);
|
||||||
memo.handleRemove.push(username.toLowerCase());
|
memo.handleRemove.push(username.toLowerCase());
|
||||||
}
|
|
||||||
|
|
||||||
memo.searchAdd.push(['ap.preferredUsername:sorted', 0, `${profile.username.toLowerCase()}:${profile.uid}`]);
|
|
||||||
memo.handleAdd[profile.username.toLowerCase()] = profile.uid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fullname !== profile.fullname) {
|
memo.searchAdd.push(['ap.preferredUsername:sorted', 0, `${profile.username.toLowerCase()}:${profile.uid}`]);
|
||||||
if (uidsForCurrent[idx] !== 0) {
|
memo.handleAdd[profile.username.toLowerCase()] = profile.uid;
|
||||||
memo.searchRemove.push(['ap.name:sorted', `${fullname.toLowerCase()}:${profile.uid}`]);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
memo.searchAdd.push(['ap.name:sorted', 0, `${profile.fullname.toLowerCase()}:${profile.uid}`]);
|
if (fullname !== profile.fullname) {
|
||||||
|
if (uidsForCurrent[idx] !== 0) {
|
||||||
|
memo.searchRemove.push(['ap.name:sorted', `${fullname.toLowerCase()}:${profile.uid}`]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memo.searchAdd.push(['ap.name:sorted', 0, `${profile.fullname.toLowerCase()}:${profile.uid}`]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return memo;
|
return memo;
|
||||||
@@ -138,5 +134,5 @@ Actors.assert = async (ids, options = {}) => {
|
|||||||
db.setObject('handle:uid', queries.handleAdd),
|
db.setObject('handle:uid', queries.handleAdd),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return actors.every(Boolean);
|
return actors;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user