mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 00:56:13 +01:00
feat: #12924, parse incoming custom fields from remote users
This commit is contained in:
@@ -68,6 +68,11 @@ Mocks.profile = async (actors, hostMap) => {
|
|||||||
let bgColor = Array.prototype.reduce.call(preferredUsername, (cur, next) => cur + next.charCodeAt(), 0);
|
let bgColor = Array.prototype.reduce.call(preferredUsername, (cur, next) => cur + next.charCodeAt(), 0);
|
||||||
bgColor = iconBackgrounds[bgColor % iconBackgrounds.length];
|
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 = {
|
const payload = {
|
||||||
uid,
|
uid,
|
||||||
username: `${preferredUsername}@${hostname}`,
|
username: `${preferredUsername}@${hostname}`,
|
||||||
@@ -90,6 +95,7 @@ Mocks.profile = async (actors, hostMap) => {
|
|||||||
inbox,
|
inbox,
|
||||||
sharedInbox: endpoints ? endpoints.sharedInbox : null,
|
sharedInbox: endpoints ? endpoints.sharedInbox : null,
|
||||||
followersUrl: followers,
|
followersUrl: followers,
|
||||||
|
customFields: new URLSearchParams(customFields).toString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return payload;
|
return payload;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const categories = require('../../categories');
|
|||||||
const posts = require('../../posts');
|
const posts = require('../../posts');
|
||||||
const activitypub = require('../../activitypub');
|
const activitypub = require('../../activitypub');
|
||||||
const flags = require('../../flags');
|
const flags = require('../../flags');
|
||||||
|
const slugify = require('../../slugify');
|
||||||
|
|
||||||
const relative_path = nconf.get('relative_path');
|
const relative_path = nconf.get('relative_path');
|
||||||
|
|
||||||
@@ -144,6 +145,27 @@ helpers.getUserDataByUserSlug = async function (userslug, callerUID, query = {})
|
|||||||
};
|
};
|
||||||
|
|
||||||
helpers.getCustomUserFields = async function (userData) {
|
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 keys = await db.getSortedSetRange('user-custom-fields', 0, -1);
|
||||||
const allFields = (await db.getObjects(keys.map(k => `user-custom-field:${k}`))).filter(Boolean);
|
const allFields = (await db.getObjects(keys.map(k => `user-custom-field:${k}`))).filter(Boolean);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user