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