Introduce renderers directory

This commit is contained in:
Akihiko Odaki
2018-04-02 13:41:25 +09:00
parent ad38cd2605
commit 4ef3d3a6d2
14 changed files with 14 additions and 14 deletions

View File

@ -0,0 +1,27 @@
import getPostSummary from './get-post-summary';
import getReactionEmoji from './get-reaction-emoji';
/**
* 通知を表す文字列を取得します。
* @param notification 通知
*/
export default function(notification: any): string {
switch (notification.type) {
case 'follow':
return `${notification.user.name}にフォローされました`;
case 'mention':
return `言及されました:\n${notification.user.name}${getPostSummary(notification.post)}`;
case 'reply':
return `返信されました:\n${notification.user.name}${getPostSummary(notification.post)}`;
case 'repost':
return `Repostされました:\n${notification.user.name}${getPostSummary(notification.post)}`;
case 'quote':
return `引用されました:\n${notification.user.name}${getPostSummary(notification.post)}`;
case 'reaction':
return `リアクションされました:\n${notification.user.name} <${getReactionEmoji(notification.reaction)}>「${getPostSummary(notification.post)}`;
case 'poll_vote':
return `投票されました:\n${notification.user.name}${getPostSummary(notification.post)}`;
default:
return `<不明な通知タイプ: ${notification.type}>`;
}
}

View File

@ -0,0 +1,45 @@
/**
* 投稿を表す文字列を取得します。
* @param {*} post 投稿
*/
const summarize = (post: any): string => {
let summary = '';
// チャンネル
summary += post.channel ? `${post.channel.title}:` : '';
// 本文
summary += post.text ? post.text : '';
// メディアが添付されているとき
if (post.media) {
summary += ` (${post.media.length}つのメディア)`;
}
// 投票が添付されているとき
if (post.poll) {
summary += ' (投票)';
}
// 返信のとき
if (post.replyId) {
if (post.reply) {
summary += ` RE: ${summarize(post.reply)}`;
} else {
summary += ' RE: ...';
}
}
// Repostのとき
if (post.repostId) {
if (post.repost) {
summary += ` RP: ${summarize(post.repost)}`;
} else {
summary += ' RP: ...';
}
}
return summary.trim();
};
export default summarize;

View File

@ -0,0 +1,14 @@
export default function(reaction: string): string {
switch (reaction) {
case 'like': return '👍';
case 'love': return '❤️';
case 'laugh': return '😆';
case 'hmm': return '🤔';
case 'surprise': return '😮';
case 'congrats': return '🎉';
case 'angry': return '💢';
case 'confused': return '😥';
case 'pudding': return '🍮';
default: return '';
}
}

View File

@ -0,0 +1,18 @@
import { IUser, isLocalUser } from '../models/user';
import getAcct from '../user/get-acct';
/**
* ユーザーを表す文字列を取得します。
* @param user ユーザー
*/
export default function(user: IUser): string {
let string = `${user.name} (@${getAcct(user)})\n` +
`${user.postsCount}投稿、${user.followingCount}フォロー、${user.followersCount}フォロワー\n`;
if (isLocalUser(user)) {
const account = user.account;
string += `場所: ${account.profile.location}、誕生日: ${account.profile.birthday}\n`;
}
return string + `${user.description}`;
}