From fe98dd927de6906671dfd3aa9671080ab6a065c6 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 7 Oct 2017 06:58:50 +0900 Subject: :v: --- src/api/bot/core.ts | 6 ++-- src/common/get-post-summary.js | 39 ------------------------ src/common/get-post-summary.ts | 39 ++++++++++++++++++++++++ src/web/app/desktop/script.js | 2 +- src/web/app/desktop/tags/notifications.tag | 2 +- src/web/app/desktop/tags/pages/home.tag | 2 +- src/web/app/mobile/tags/notification-preview.tag | 2 +- src/web/app/mobile/tags/notification.tag | 2 +- src/web/app/mobile/tags/notifications.tag | 2 +- src/web/app/mobile/tags/page/home.tag | 2 +- src/web/app/mobile/tags/post-detail.tag | 2 +- src/web/app/mobile/tags/timeline.tag | 2 +- src/web/app/mobile/tags/user.tag | 2 +- 13 files changed, 53 insertions(+), 51 deletions(-) delete mode 100644 src/common/get-post-summary.js create mode 100644 src/common/get-post-summary.ts (limited to 'src') diff --git a/src/api/bot/core.ts b/src/api/bot/core.ts index cf2bdef1dc..57330e67eb 100644 --- a/src/api/bot/core.ts +++ b/src/api/bot/core.ts @@ -3,7 +3,7 @@ import * as bcrypt from 'bcryptjs'; import User, { IUser } from '../models/user'; -import getPostSummary from '../../common/get-post-summary.js'; +import getPostSummary from '../../common/get-post-summary'; export default class BotCore extends EventEmitter { public user: IUser = null; @@ -109,7 +109,9 @@ export default class BotCore extends EventEmitter { public async getTl() { if (this.user == null) return 'まずサインインしてください。'; - const tl = await require('../endpoints/posts/timeline')({}, this.user); + const tl = await require('../endpoints/posts/timeline')({ + limit: 5 + }, this.user); const text = tl .map(post => getPostSummary(post)) diff --git a/src/common/get-post-summary.js b/src/common/get-post-summary.js deleted file mode 100644 index f7a481a164..0000000000 --- a/src/common/get-post-summary.js +++ /dev/null @@ -1,39 +0,0 @@ -/** - * 投稿を表す文字列を取得します。 - * @param {*} post 投稿 - */ -const summarize = post => { - let summary = post.text ? post.text : ''; - - // メディアが添付されているとき - if (post.media) { - summary += ` (${post.media.length}つのメディア)`; - } - - // 投票が添付されているとき - if (post.poll) { - summary += ' (投票)'; - } - - // 返信のとき - if (post.reply_to_id) { - if (post.reply_to) { - summary += ` RE: ${summarize(post.reply_to)}`; - } else { - summary += ' RE: ...'; - } - } - - // Repostのとき - if (post.repost_id) { - if (post.repost) { - summary += ` RP: ${summarize(post.repost)}`; - } else { - summary += ' RP: ...'; - } - } - - return summary.trim(); -}; - -export default summarize; diff --git a/src/common/get-post-summary.ts b/src/common/get-post-summary.ts new file mode 100644 index 0000000000..f628a32b41 --- /dev/null +++ b/src/common/get-post-summary.ts @@ -0,0 +1,39 @@ +/** + * 投稿を表す文字列を取得します。 + * @param {*} post 投稿 + */ +const summarize = (post: any): string => { + let summary = post.text ? post.text : ''; + + // メディアが添付されているとき + if (post.media) { + summary += ` (${post.media.length}つのメディア)`; + } + + // 投票が添付されているとき + if (post.poll) { + summary += ' (投票)'; + } + + // 返信のとき + if (post.reply_to_id) { + if (post.reply_to) { + summary += ` RE: ${summarize(post.reply_to)}`; + } else { + summary += ' RE: ...'; + } + } + + // Repostのとき + if (post.repost_id) { + if (post.repost) { + summary += ` RP: ${summarize(post.repost)}`; + } else { + summary += ' RP: ...'; + } + } + + return summary.trim(); +}; + +export default summarize; diff --git a/src/web/app/desktop/script.js b/src/web/app/desktop/script.js index e3dc8b7d96..46a7fce700 100644 --- a/src/web/app/desktop/script.js +++ b/src/web/app/desktop/script.js @@ -11,7 +11,7 @@ import * as riot from 'riot'; import init from '../init'; import route from './router'; import fuckAdBlock from './scripts/fuck-ad-block'; -import getPostSummary from '../../../common/get-post-summary'; +import getPostSummary from '../../../common/get-post-summary.ts'; /** * init diff --git a/src/web/app/desktop/tags/notifications.tag b/src/web/app/desktop/tags/notifications.tag index 4747d1c0f4..1046358ce9 100644 --- a/src/web/app/desktop/tags/notifications.tag +++ b/src/web/app/desktop/tags/notifications.tag @@ -207,7 +207,7 @@ diff --git a/src/web/app/mobile/tags/notification.tag b/src/web/app/mobile/tags/notification.tag index 416493ee23..53222b9dbe 100644 --- a/src/web/app/mobile/tags/notification.tag +++ b/src/web/app/mobile/tags/notification.tag @@ -163,7 +163,7 @@ diff --git a/src/web/app/mobile/tags/notifications.tag b/src/web/app/mobile/tags/notifications.tag index 9985b3351c..7370aa84d3 100644 --- a/src/web/app/mobile/tags/notifications.tag +++ b/src/web/app/mobile/tags/notifications.tag @@ -78,7 +78,7 @@