diff --git a/src/controllers/activitypub/profiles.js b/src/controllers/activitypub/profiles.js index 10ca171dc9..738902998c 100644 --- a/src/controllers/activitypub/profiles.js +++ b/src/controllers/activitypub/profiles.js @@ -1,6 +1,7 @@ 'use strict'; const db = require('../../database'); +const user = require('../../user'); const { getActor } = require('../../activitypub'); const controller = module.exports; @@ -14,14 +15,24 @@ controller.get = async function (req, res, next) { const { preferredUsername, published, icon, image, name, summary, hostname } = actor; const isFollowing = await db.isSortedSetMember(`followingRemote:${req.uid}`, uid); + 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: typeof icon === 'string' ? icon : icon.url, - uploadedpicture: typeof icon === 'string' ? icon : icon.url, + 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,