From 3ae824c3542b0e232b9847ae702956e631acb276 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 26 Feb 2018 00:39:05 +0900 Subject: [PATCH] :v: --- src/api/endpoints/posts/create.ts | 24 +++++++- .../desktop/views/components/post-detail.vue | 29 +++++++++ .../desktop/views/components/posts.post.vue | 35 ++++++++++- .../app/desktop/views/components/timeline.vue | 14 ++++- src/web/app/desktop/views/pages/search.vue | 55 ++++++++++++----- .../mobile/views/components/post-detail.vue | 25 ++++++++ .../mobile/views/components/posts.post.vue | 30 ++++++++-- src/web/app/mobile/views/pages/search.vue | 59 +++++++++++++------ 8 files changed, 227 insertions(+), 44 deletions(-) diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts index 0fa52221f..075e1ac9f 100644 --- a/src/api/endpoints/posts/create.ts +++ b/src/api/endpoints/posts/create.ts @@ -31,6 +31,10 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$; if (textErr) return rej('invalid text'); + // Get 'tags' parameter + const [tags = [], tagsErr] = $(params.tags).optional.array('string').unique().eachQ(t => t.range(1, 32)).$; + if (tagsErr) return rej('invalid tags'); + // Get 'media_ids' parameter const [mediaIds, mediaIdsErr] = $(params.media_ids).optional.array('id').unique().range(1, 4).$; if (mediaIdsErr) return rej('invalid media_ids'); @@ -205,6 +209,23 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { } } + let tokens = null; + if (text) { + // Analyze + tokens = parse(text); + + // Extract hashtags + const hashtags = tokens + .filter(t => t.type == 'hashtag') + .map(t => t.hashtag); + + hashtags.forEach(tag => { + if (tags.indexOf(tag) == -1) { + tags.push(tag); + } + }); + } + // 投稿を作成 const post = await Post.insert({ created_at: new Date(), @@ -215,6 +236,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { repost_id: repost ? repost._id : undefined, poll: poll, text: text, + tags: tags, user_id: user._id, app_id: app ? app._id : null, @@ -423,8 +445,6 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // If has text content if (text) { - // Analyze - const tokens = parse(text); /* // Extract a hashtags const hashtags = tokens diff --git a/src/web/app/desktop/views/components/post-detail.vue b/src/web/app/desktop/views/components/post-detail.vue index c453867df..1e31752fe 100644 --- a/src/web/app/desktop/views/components/post-detail.vue +++ b/src/web/app/desktop/views/components/post-detail.vue @@ -44,6 +44,9 @@ +
+ {{ tag }} +