diff options
| author | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-04-02 13:41:25 +0900 |
|---|---|---|
| committer | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-04-02 13:41:25 +0900 |
| commit | 4ef3d3a6d2865e8bb486d74c8fb3b6fdfde699ff (patch) | |
| tree | a61bdf12f02acd1aaada86fdc95f4c6e21cf5d57 /src/renderers | |
| parent | Introduce publishers directory (diff) | |
| download | sharkey-4ef3d3a6d2865e8bb486d74c8fb3b6fdfde699ff.tar.gz sharkey-4ef3d3a6d2865e8bb486d74c8fb3b6fdfde699ff.tar.bz2 sharkey-4ef3d3a6d2865e8bb486d74c8fb3b6fdfde699ff.zip | |
Introduce renderers directory
Diffstat (limited to 'src/renderers')
| -rw-r--r-- | src/renderers/get-notification-summary.ts | 27 | ||||
| -rw-r--r-- | src/renderers/get-post-summary.ts | 45 | ||||
| -rw-r--r-- | src/renderers/get-reaction-emoji.ts | 14 | ||||
| -rw-r--r-- | src/renderers/get-user-summary.ts | 18 |
4 files changed, 104 insertions, 0 deletions
diff --git a/src/renderers/get-notification-summary.ts b/src/renderers/get-notification-summary.ts new file mode 100644 index 0000000000..03db722c84 --- /dev/null +++ b/src/renderers/get-notification-summary.ts @@ -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}>`; + } +} diff --git a/src/renderers/get-post-summary.ts b/src/renderers/get-post-summary.ts new file mode 100644 index 0000000000..8d0033064f --- /dev/null +++ b/src/renderers/get-post-summary.ts @@ -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; diff --git a/src/renderers/get-reaction-emoji.ts b/src/renderers/get-reaction-emoji.ts new file mode 100644 index 0000000000..c661205379 --- /dev/null +++ b/src/renderers/get-reaction-emoji.ts @@ -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 ''; + } +} diff --git a/src/renderers/get-user-summary.ts b/src/renderers/get-user-summary.ts new file mode 100644 index 0000000000..2a9e8a5d04 --- /dev/null +++ b/src/renderers/get-user-summary.ts @@ -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}」`; +} |