2018-04-01 12:18:36 +02:00
|
|
|
import renderImage from './image';
|
|
|
|
import renderKey from './key';
|
2018-04-02 06:15:53 +02:00
|
|
|
import config from '../../../config';
|
2019-04-07 14:50:36 +02:00
|
|
|
import { ILocalUser } from '../../../models/entities/user';
|
2020-04-26 04:48:09 +02:00
|
|
|
import { toHtml } from '../../../mfm/to-html';
|
2019-01-30 08:56:27 +01:00
|
|
|
import { parse } from '../../../mfm/parse';
|
2018-12-06 02:02:04 +01:00
|
|
|
import { getEmojis } from './note';
|
|
|
|
import renderEmoji from './emoji';
|
2019-01-24 09:33:39 +01:00
|
|
|
import { IIdentifier } from '../models/identifier';
|
2019-01-31 12:42:45 +01:00
|
|
|
import renderHashtag from './hashtag';
|
2019-04-10 08:04:27 +02:00
|
|
|
import { DriveFiles, UserProfiles, UserKeypairs } from '../../../models';
|
2019-04-12 18:43:22 +02:00
|
|
|
import { ensure } from '../../../prelude/ensure';
|
2018-04-01 12:18:36 +02:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
export async function renderPerson(user: ILocalUser) {
|
|
|
|
const id = `${config.url}/users/${user.id}`;
|
2020-05-10 11:42:31 +02:00
|
|
|
const isSystem = !!user.username.match(/\./);
|
2018-04-01 12:18:36 +02:00
|
|
|
|
2019-04-10 08:04:27 +02:00
|
|
|
const [avatar, banner, profile] = await Promise.all([
|
2019-04-12 18:43:22 +02:00
|
|
|
user.avatarId ? DriveFiles.findOne(user.avatarId) : Promise.resolve(undefined),
|
|
|
|
user.bannerId ? DriveFiles.findOne(user.bannerId) : Promise.resolve(undefined),
|
2019-04-17 07:32:59 +02:00
|
|
|
UserProfiles.findOne(user.id).then(ensure)
|
2018-07-19 19:40:37 +02:00
|
|
|
]);
|
2018-12-06 11:15:09 +01:00
|
|
|
|
2018-12-05 16:37:59 +01:00
|
|
|
const attachment: {
|
2019-07-17 17:11:39 +02:00
|
|
|
type: 'PropertyValue',
|
2018-12-05 16:37:59 +01:00
|
|
|
name: string,
|
|
|
|
value: string,
|
2019-01-24 09:33:39 +01:00
|
|
|
identifier?: IIdentifier
|
2018-12-05 16:37:59 +01:00
|
|
|
}[] = [];
|
2018-12-06 11:15:09 +01:00
|
|
|
|
2019-07-17 17:11:39 +02:00
|
|
|
if (profile.fields) {
|
|
|
|
for (const field of profile.fields) {
|
|
|
|
attachment.push({
|
|
|
|
type: 'PropertyValue',
|
|
|
|
name: field.name,
|
|
|
|
value: (field.value != null && field.value.match(/^https?:/))
|
|
|
|
? `<a href="${new URL(field.value).href}" rel="me nofollow noopener" target="_blank">${new URL(field.value).href}</a>`
|
|
|
|
: field.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 02:02:04 +01:00
|
|
|
const emojis = await getEmojis(user.emojis);
|
|
|
|
const apemojis = emojis.map(emoji => renderEmoji(emoji));
|
|
|
|
|
2019-01-31 12:42:45 +01:00
|
|
|
const hashtagTags = (user.tags || []).map(tag => renderHashtag(tag));
|
|
|
|
|
2018-12-06 02:02:04 +01:00
|
|
|
const tag = [
|
|
|
|
...apemojis,
|
2019-01-31 12:42:45 +01:00
|
|
|
...hashtagTags,
|
2018-12-06 02:02:04 +01:00
|
|
|
];
|
|
|
|
|
2019-04-12 18:43:22 +02:00
|
|
|
const keypair = await UserKeypairs.findOne(user.id).then(ensure);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2018-04-01 12:18:36 +02:00
|
|
|
return {
|
2020-05-10 11:42:31 +02:00
|
|
|
type: isSystem ? 'Application' : user.isBot ? 'Service' : 'Person',
|
2018-04-01 12:18:36 +02:00
|
|
|
id,
|
|
|
|
inbox: `${id}/inbox`,
|
|
|
|
outbox: `${id}/outbox`,
|
2018-08-12 20:49:17 +02:00
|
|
|
followers: `${id}/followers`,
|
|
|
|
following: `${id}/following`,
|
2018-09-18 06:08:27 +02:00
|
|
|
featured: `${id}/collections/featured`,
|
2018-04-23 08:37:27 +02:00
|
|
|
sharedInbox: `${config.url}/inbox`,
|
2018-12-21 16:12:34 +01:00
|
|
|
endpoints: { sharedInbox: `${config.url}/inbox` },
|
2018-04-08 11:21:02 +02:00
|
|
|
url: `${config.url}/@${user.username}`,
|
2018-04-01 12:18:36 +02:00
|
|
|
preferredUsername: user.username,
|
|
|
|
name: user.name,
|
2019-04-10 08:04:27 +02:00
|
|
|
summary: toHtml(parse(profile.description)),
|
2019-04-12 18:43:22 +02:00
|
|
|
icon: avatar ? renderImage(avatar) : null,
|
|
|
|
image: banner ? renderImage(banner) : null,
|
2018-12-06 02:02:04 +01:00
|
|
|
tag,
|
2018-05-31 11:34:15 +02:00
|
|
|
manuallyApprovesFollowers: user.isLocked,
|
2020-01-19 20:51:44 +01:00
|
|
|
publicKey: renderKey(user, keypair, `#main-key`),
|
2018-12-05 16:37:59 +01:00
|
|
|
isCat: user.isCat,
|
|
|
|
attachment: attachment.length ? attachment : undefined
|
2018-04-01 12:18:36 +02:00
|
|
|
};
|
2019-04-07 14:50:36 +02:00
|
|
|
}
|