mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +01:00
feat: update mockProfile to accept actor uris as well as actor objects
This commit is contained in:
@@ -46,39 +46,54 @@ ActivityPub.getActor = async (input) => {
|
|||||||
return actor;
|
return actor;
|
||||||
};
|
};
|
||||||
|
|
||||||
ActivityPub.mockProfile = async (callerUid, actor) => {
|
ActivityPub.mockProfile = async (actors, callerUid = 0) => {
|
||||||
// Accepts an actor object; the output of getActor()
|
// Accepts an array containing actor objects (the output of getActor()), or uris
|
||||||
const uid = actor.id;
|
let single = false;
|
||||||
const { preferredUsername, published, icon, image, name, summary, hostname } = actor;
|
if (!Array.isArray(actors)) {
|
||||||
const isFollowing = await db.isSortedSetMember(`followingRemote:${callerUid}`, uid);
|
single = true;
|
||||||
|
actors = [actors];
|
||||||
let picture;
|
|
||||||
if (icon) {
|
|
||||||
picture = typeof icon === 'string' ? icon : icon.url;
|
|
||||||
}
|
}
|
||||||
const iconBackgrounds = await user.getIconBackgrounds();
|
|
||||||
let bgColor = Array.prototype.reduce.call(preferredUsername, (cur, next) => cur + next.charCodeAt(), 0);
|
|
||||||
bgColor = iconBackgrounds[bgColor % iconBackgrounds.length];
|
|
||||||
|
|
||||||
const payload = {
|
const profiles = await Promise.all(actors.map(async (actor) => {
|
||||||
uid,
|
// convert uri to actor object
|
||||||
username: `${preferredUsername}@${hostname}`,
|
if (typeof actor === 'string' && ActivityPub.helpers.isUri(actor)) {
|
||||||
userslug: `${preferredUsername}@${hostname}`,
|
actor = await ActivityPub.getActor(actor);
|
||||||
fullname: name,
|
}
|
||||||
joindate: new Date(published).getTime(),
|
|
||||||
picture,
|
|
||||||
'icon:text': (preferredUsername[0] || '').toUpperCase(),
|
|
||||||
'icon:bgColor': bgColor,
|
|
||||||
uploadedpicture: undefined,
|
|
||||||
'cover:url': !image || typeof image === 'string' ? image : image.url,
|
|
||||||
'cover:position': '50% 50%',
|
|
||||||
aboutme: summary,
|
|
||||||
aboutmeParsed: summary,
|
|
||||||
|
|
||||||
isFollowing,
|
const uid = actor.id;
|
||||||
};
|
const { preferredUsername, published, icon, image, name, summary, hostname } = actor;
|
||||||
|
const isFollowing = await db.isSortedSetMember(`followingRemote:${callerUid}`, uid);
|
||||||
|
|
||||||
return payload;
|
let picture;
|
||||||
|
if (icon) {
|
||||||
|
picture = typeof icon === 'string' ? icon : icon.url;
|
||||||
|
}
|
||||||
|
const iconBackgrounds = await user.getIconBackgrounds();
|
||||||
|
let bgColor = Array.prototype.reduce.call(preferredUsername, (cur, next) => cur + next.charCodeAt(), 0);
|
||||||
|
bgColor = iconBackgrounds[bgColor % iconBackgrounds.length];
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
uid,
|
||||||
|
username: `${preferredUsername}@${hostname}`,
|
||||||
|
userslug: `${preferredUsername}@${hostname}`,
|
||||||
|
fullname: name,
|
||||||
|
joindate: new Date(published).getTime(),
|
||||||
|
picture,
|
||||||
|
'icon:text': (preferredUsername[0] || '').toUpperCase(),
|
||||||
|
'icon:bgColor': bgColor,
|
||||||
|
uploadedpicture: undefined,
|
||||||
|
'cover:url': !image || typeof image === 'string' ? image : image.url,
|
||||||
|
'cover:position': '50% 50%',
|
||||||
|
aboutme: summary,
|
||||||
|
aboutmeParsed: summary,
|
||||||
|
|
||||||
|
isFollowing,
|
||||||
|
};
|
||||||
|
|
||||||
|
return payload;
|
||||||
|
}));
|
||||||
|
|
||||||
|
return single ? profiles.pop() : profiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
ActivityPub.resolveInboxes = async ids => await Promise.all(ids.map(async (id) => {
|
ActivityPub.resolveInboxes = async ids => await Promise.all(ids.map(async (id) => {
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ controller.get = async function (req, res, next) {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = await mockProfile(req.uid, actor);
|
const payload = await mockProfile(actor, req.uid);
|
||||||
res.render('account/profile', payload);
|
res.render('account/profile', payload);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user