Skip to content

Node.js based forum software built for the modern web

fix: #13224, handle note attributedTo when it is of type object

Julian Lamd948334713dc
diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js
index 3164fd85e1..2f7b157d2b 100644
--- a/src/activitypub/mocks.js
+++ b/src/activitypub/mocks.js
@@ -170,21 +170,28 @@ Mocks.post = async (objects) => {
type, to, cc, audience, attachment, tag, image,
} = object;
- if (Array.isArray(uid)) { // Handle array attributedTo
- uid = uid.reduce((valid, cur) => {
- if (typeof cur === 'string') {
- valid.push(cur);
- } else if (typeof cur === 'object') {
- if (cur.type === 'Person' && cur.id) {
- valid.push(cur.id);
+ switch (true) { // non-string attributedTo handling
+ case Array.isArray(uid): {
+ uid = uid.reduce((valid, cur) => {
+ if (typeof cur === 'string') {
+ valid.push(cur);
+ } else if (typeof cur === 'object') {
+ if (cur.type === 'Person' && cur.id) {
+ valid.push(cur.id);
+ }
}
- }
- return valid;
- }, []);
- uid = uid.shift(); // take first valid uid
- await activitypub.actors.assert(uid);
+ return valid;
+ }, []);
+ uid = uid.shift(); // take first valid uid
+ break;
+ }
+
+ case typeof uid === 'object' && uid.hasOwnProperty('id'): {
+ uid = uid.id;
+ }
}
+ await activitypub.actors.assert(uid);
const resolved = await activitypub.helpers.resolveLocalId(toPid);
if (resolved.type === 'post') {