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';
|
2019-01-30 08:56:27 +01:00
|
|
|
import { toHtml } from '../../../mfm/toHtml';
|
|
|
|
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-07 14:50:36 +02:00
|
|
|
import { DriveFiles, UserServiceLinkings, UserKeypairs } from '../../../models';
|
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}`;
|
2018-04-01 12:18:36 +02:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
const [avatar, banner, links] = await Promise.all([
|
|
|
|
DriveFiles.findOne(user.avatarId),
|
|
|
|
DriveFiles.findOne(user.bannerId),
|
|
|
|
UserServiceLinkings.findOne({ userId: user.id })
|
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: {
|
|
|
|
type: string,
|
|
|
|
name: string,
|
|
|
|
value: string,
|
2019-01-24 09:33:39 +01:00
|
|
|
verified_at?: string,
|
|
|
|
identifier?: IIdentifier
|
2018-12-05 16:37:59 +01:00
|
|
|
}[] = [];
|
2018-12-06 11:15:09 +01:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
if (links.twitter) {
|
2018-12-06 11:15:09 +01:00
|
|
|
attachment.push({
|
|
|
|
type: 'PropertyValue',
|
|
|
|
name: 'Twitter',
|
2019-04-07 14:50:36 +02:00
|
|
|
value: `<a href="https://twitter.com/intent/user?user_id=${links.twitterUserId}" rel="me nofollow noopener" target="_blank"><span>@${links.twitterScreenName}</span></a>`,
|
2019-01-24 09:33:39 +01:00
|
|
|
identifier: {
|
|
|
|
type: 'PropertyValue',
|
|
|
|
name: 'misskey:authentication:twitter',
|
2019-04-07 14:50:36 +02:00
|
|
|
value: `${links.twitterUserId}@${links.twitterScreenName}`
|
2019-01-24 09:33:39 +01:00
|
|
|
}
|
2018-12-06 11:15:09 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
if (links.github) {
|
2018-12-06 11:15:09 +01:00
|
|
|
attachment.push({
|
|
|
|
type: 'PropertyValue',
|
|
|
|
name: 'GitHub',
|
2019-04-07 14:50:36 +02:00
|
|
|
value: `<a href="https://github.com/${links.githubLogin}" rel="me nofollow noopener" target="_blank"><span>@${links.githubLogin}</span></a>`,
|
2019-01-24 09:33:39 +01:00
|
|
|
identifier: {
|
|
|
|
type: 'PropertyValue',
|
|
|
|
name: 'misskey:authentication:github',
|
2019-04-07 14:50:36 +02:00
|
|
|
value: `${links.githubId}@${links.githubLogin}`
|
2019-01-24 09:33:39 +01:00
|
|
|
}
|
2018-12-06 11:15:09 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
if (links.discord) {
|
2018-12-06 11:15:09 +01:00
|
|
|
attachment.push({
|
|
|
|
type: 'PropertyValue',
|
|
|
|
name: 'Discord',
|
2019-04-07 14:50:36 +02:00
|
|
|
value: `<a href="https://discordapp.com/users/${links.discordId}" rel="me nofollow noopener" target="_blank"><span>${links.discordUsername}#${links.discordDiscriminator}</span></a>`,
|
2019-01-24 09:33:39 +01:00
|
|
|
identifier: {
|
|
|
|
type: 'PropertyValue',
|
|
|
|
name: 'misskey:authentication:discord',
|
2019-04-07 14:50:36 +02:00
|
|
|
value: `${links.discordId}@${links.discordUsername}#${links.discordDiscriminator}`
|
2019-01-24 09:33:39 +01:00
|
|
|
}
|
2018-12-06 11:15:09 +01:00
|
|
|
});
|
|
|
|
}
|
2018-07-19 19:40:37 +02:00
|
|
|
|
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-07 14:50:36 +02:00
|
|
|
const keypair = await UserKeypairs.findOne({
|
|
|
|
userId: user.id
|
|
|
|
});
|
|
|
|
|
2018-04-01 12:18:36 +02:00
|
|
|
return {
|
2018-06-23 12:16:50 +02:00
|
|
|
type: 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,
|
2018-06-26 11:34:17 +02:00
|
|
|
summary: toHtml(parse(user.description)),
|
2018-07-19 19:40:37 +02:00
|
|
|
icon: user.avatarId && renderImage(avatar),
|
|
|
|
image: user.bannerId && renderImage(banner),
|
2018-12-06 02:02:04 +01:00
|
|
|
tag,
|
2018-05-31 11:34:15 +02:00
|
|
|
manuallyApprovesFollowers: user.isLocked,
|
2019-04-07 14:50:36 +02:00
|
|
|
publicKey: renderKey(user, keypair),
|
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
|
|
|
}
|