fix: icon text and bgColor in remote profiles

This commit is contained in:
Julian Lam
2023-12-07 13:10:06 -05:00
parent 5e693702a4
commit 4324f09c85

View File

@@ -1,6 +1,7 @@
'use strict'; 'use strict';
const db = require('../../database'); const db = require('../../database');
const user = require('../../user');
const { getActor } = require('../../activitypub'); const { getActor } = require('../../activitypub');
const controller = module.exports; 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 { preferredUsername, published, icon, image, name, summary, hostname } = actor;
const isFollowing = await db.isSortedSetMember(`followingRemote:${req.uid}`, uid); 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 = { const payload = {
uid, uid,
username: `${preferredUsername}@${hostname}`, username: `${preferredUsername}@${hostname}`,
userslug: `${preferredUsername}@${hostname}`, userslug: `${preferredUsername}@${hostname}`,
fullname: name, fullname: name,
joindate: new Date(published).getTime(), joindate: new Date(published).getTime(),
picture: typeof icon === 'string' ? icon : icon.url, picture,
uploadedpicture: typeof icon === 'string' ? icon : icon.url, 'icon:text': (preferredUsername[0] || '').toUpperCase(),
'icon:bgColor': bgColor,
uploadedpicture: undefined,
'cover:url': !image || typeof image === 'string' ? image : image.url, 'cover:url': !image || typeof image === 'string' ? image : image.url,
'cover:position': '50% 50%', 'cover:position': '50% 50%',
aboutme: summary, aboutme: summary,