2018-04-01 05:18:36 -05:00
|
|
|
import renderImage from './image';
|
|
|
|
import renderKey from './key';
|
2018-04-01 23:15:53 -05:00
|
|
|
import config from '../../../config';
|
2018-05-31 04:34:15 -05:00
|
|
|
import { ILocalUser } from '../../../models/user';
|
2018-06-26 04:34:17 -05:00
|
|
|
import toHtml from '../../../mfm/html';
|
|
|
|
import parse from '../../../mfm/parse';
|
2018-07-19 12:40:37 -05:00
|
|
|
import DriveFile from '../../../models/drive-file';
|
2018-12-05 19:02:04 -06:00
|
|
|
import { getEmojis } from './note';
|
|
|
|
import renderEmoji from './emoji';
|
2018-04-01 05:18:36 -05:00
|
|
|
|
2018-07-19 12:40:37 -05:00
|
|
|
export default async (user: ILocalUser) => {
|
2018-04-08 01:15:22 -05:00
|
|
|
const id = `${config.url}/users/${user._id}`;
|
2018-04-01 05:18:36 -05:00
|
|
|
|
2018-07-19 12:40:37 -05:00
|
|
|
const [avatar, banner] = await Promise.all([
|
|
|
|
DriveFile.findOne({ _id: user.avatarId }),
|
|
|
|
DriveFile.findOne({ _id: user.bannerId })
|
|
|
|
]);
|
2018-12-06 04:15:09 -06:00
|
|
|
|
2018-12-05 09:37:59 -06:00
|
|
|
const attachment: {
|
|
|
|
type: string,
|
|
|
|
name: string,
|
|
|
|
value: string,
|
|
|
|
verified_at?: string
|
|
|
|
}[] = [];
|
2018-12-06 04:15:09 -06:00
|
|
|
|
|
|
|
if (user.twitter) {
|
|
|
|
attachment.push({
|
|
|
|
type: 'PropertyValue',
|
|
|
|
name: 'Twitter',
|
|
|
|
value: `<a href="https://twitter.com/intent/user?user_id=${user.twitter.userId}" rel="me nofollow noopener" target="_blank"><span>@${user.twitter.screenName}</span></a>`
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user.github) {
|
|
|
|
attachment.push({
|
|
|
|
type: 'PropertyValue',
|
|
|
|
name: 'GitHub',
|
|
|
|
value: `<a href="https://github.com/${user.github.login}" rel="me nofollow noopener" target="_blank"><span>@${user.github.login}</span></a>`
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user.discord) {
|
|
|
|
attachment.push({
|
|
|
|
type: 'PropertyValue',
|
|
|
|
name: 'Discord',
|
|
|
|
value: `<a href="https://discordapp.com/users/${user.discord.id}" rel="me nofollow noopener" target="_blank"><span>@${user.discord.username}#${user.discord.discriminator}</span></a>`
|
|
|
|
});
|
|
|
|
}
|
2018-07-19 12:40:37 -05:00
|
|
|
|
2018-12-05 19:02:04 -06:00
|
|
|
const emojis = await getEmojis(user.emojis);
|
|
|
|
const apemojis = emojis.map(emoji => renderEmoji(emoji));
|
|
|
|
|
|
|
|
const tag = [
|
|
|
|
...apemojis,
|
|
|
|
];
|
|
|
|
|
2018-04-01 05:18:36 -05:00
|
|
|
return {
|
2018-06-23 05:16:50 -05:00
|
|
|
type: user.isBot ? 'Service' : 'Person',
|
2018-04-01 05:18:36 -05:00
|
|
|
id,
|
|
|
|
inbox: `${id}/inbox`,
|
|
|
|
outbox: `${id}/outbox`,
|
2018-08-12 13:49:17 -05:00
|
|
|
followers: `${id}/followers`,
|
|
|
|
following: `${id}/following`,
|
2018-09-17 23:08:27 -05:00
|
|
|
featured: `${id}/collections/featured`,
|
2018-04-23 01:37:27 -05:00
|
|
|
sharedInbox: `${config.url}/inbox`,
|
2018-04-08 04:21:02 -05:00
|
|
|
url: `${config.url}/@${user.username}`,
|
2018-04-01 05:18:36 -05:00
|
|
|
preferredUsername: user.username,
|
|
|
|
name: user.name,
|
2018-06-26 04:34:17 -05:00
|
|
|
summary: toHtml(parse(user.description)),
|
2018-07-19 12:40:37 -05:00
|
|
|
icon: user.avatarId && renderImage(avatar),
|
|
|
|
image: user.bannerId && renderImage(banner),
|
2018-12-05 19:02:04 -06:00
|
|
|
tag,
|
2018-05-31 04:34:15 -05:00
|
|
|
manuallyApprovesFollowers: user.isLocked,
|
2018-08-21 19:16:52 -05:00
|
|
|
publicKey: renderKey(user),
|
2018-12-05 09:37:59 -06:00
|
|
|
isCat: user.isCat,
|
|
|
|
attachment: attachment.length ? attachment : undefined
|
2018-04-01 05:18:36 -05:00
|
|
|
};
|
|
|
|
};
|