Introduce renderers directory
This commit is contained in:
27
src/renderers/get-notification-summary.ts
Normal file
27
src/renderers/get-notification-summary.ts
Normal 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}>`;
|
||||
}
|
||||
}
|
45
src/renderers/get-post-summary.ts
Normal file
45
src/renderers/get-post-summary.ts
Normal 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;
|
14
src/renderers/get-reaction-emoji.ts
Normal file
14
src/renderers/get-reaction-emoji.ts
Normal 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 '';
|
||||
}
|
||||
}
|
18
src/renderers/get-user-summary.ts
Normal file
18
src/renderers/get-user-summary.ts
Normal 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}」`;
|
||||
}
|
Reference in New Issue
Block a user