Skip to content

Node.js based forum software built for the modern web

feat: #12924, parse incoming custom fields from remote users

Julian Lam0f351ba70d7d
diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js
index f1817a3f3a..e255757c54 100644
--- a/src/activitypub/mocks.js
+++ b/src/activitypub/mocks.js
@@ -68,6 +68,11 @@ Mocks.profile = async (actors, hostMap) => {
let bgColor = Array.prototype.reduce.call(preferredUsername, (cur, next) => cur + next.charCodeAt(), 0);
bgColor = iconBackgrounds[bgColor % iconBackgrounds.length];
+ // Add custom fields into user hash
+ const customFields = actor.attachment
+ .filter(attachment => attachment.type === 'PropertyValue')
+ .reduce((map, { name, value }) => map.set(name, value), new Map());
+
const payload = {
uid,
username: `${preferredUsername}@${hostname}`,
@@ -90,6 +95,7 @@ Mocks.profile = async (actors, hostMap) => {
inbox,
sharedInbox: endpoints ? endpoints.sharedInbox : null,
followersUrl: followers,
+ customFields: new URLSearchParams(customFields).toString(),
};
return payload;
diff --git a/src/controllers/accounts/helpers.js b/src/controllers/accounts/helpers.js
index a53a75e27f..d55d58c2ef 100644
--- a/src/controllers/accounts/helpers.js
+++ b/src/controllers/accounts/helpers.js
@@ -16,6 +16,7 @@ const categories = require('../../categories');
const posts = require('../../posts');
const activitypub = require('../../activitypub');
const flags = require('../../flags');
+const slugify = require('../../slugify');
const relative_path = nconf.get('relative_path');
@@ -144,6 +145,27 @@ helpers.getUserDataByUserSlug = async function (userslug, callerUID, query = {})
};
helpers.getCustomUserFields = async function (userData) {
+ // Remote users' fields are serialized in hash
+ if (!utils.isNumber(userData.uid)) {
+ const customFields = await user.getUserField(userData.uid, 'customFields');
+ const fields = Array
+ .from(new URLSearchParams(customFields))
+ .reduce((memo, [name, value]) => {
+ memo.push({
+ key: slugify(name),
+ name,
+ value,
+ type: 'input-text',
+ 'min-rep': '',
+ icon: 'fa-solid fa-circle-info',
+ });
+
+ return memo;
+ }, []);
+
+ return fields;
+ }
+
const keys = await db.getSortedSetRange('user-custom-fields', 0, -1);
const allFields = (await db.getObjects(keys.map(k => `user-custom-field:${k}`))).filter(Boolean);