Skip to content

Node.js based forum software built for the modern web

fix: remove unresolvable actors from parsing prior to mocking profile

Julian Lam39da3ab6687c
diff --git a/src/activitypub/actors.js b/src/activitypub/actors.js
index 250afc4fc9..10de404c66 100644
--- a/src/activitypub/actors.js
+++ b/src/activitypub/actors.js
@@ -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)]);
- }
-
+ const key = `userRemote:${profile.uid}`;
+ memo.push([key, profile], [`${key}:keys`, pubKeysMap.get(profile.uid)]);
return memo;
}, []);
if (followersUrlMap.size) {
@@ -104,26 +102,24 @@ 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) {
- if (uidsForCurrent[idx] !== 0) {
- memo.searchRemove.push(['ap.preferredUsername:sorted', `${username.toLowerCase()}:${profile.uid}`]);
- memo.handleRemove.push(username.toLowerCase());
- }
+ const { username, fullname } = current[idx];
- memo.searchAdd.push(['ap.preferredUsername:sorted', 0, `${profile.username.toLowerCase()}:${profile.uid}`]);
- memo.handleAdd[profile.username.toLowerCase()] = profile.uid;
+ if (username !== profile.username) {
+ if (uidsForCurrent[idx] !== 0) {
+ memo.searchRemove.push(['ap.preferredUsername:sorted', `${username.toLowerCase()}:${profile.uid}`]);
+ memo.handleRemove.push(username.toLowerCase());
}
- if (fullname !== profile.fullname) {
- if (uidsForCurrent[idx] !== 0) {
- memo.searchRemove.push(['ap.name:sorted', `${fullname.toLowerCase()}:${profile.uid}`]);
- }
+ memo.searchAdd.push(['ap.preferredUsername:sorted', 0, `${profile.username.toLowerCase()}:${profile.uid}`]);
+ memo.handleAdd[profile.username.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;
@@ -138,5 +134,5 @@ Actors.assert = async (ids, options = {}) => {
db.setObject('handle:uid', queries.handleAdd),
]);
- return actors.every(Boolean);
+ return actors;
};