summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-02-26 00:39:05 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-02-26 00:39:05 +0900
commit3ae824c3542b0e232b9847ae702956e631acb276 (patch)
treefe6183d41238471019539c4e4c14ccde995d8222 /src/api
parentv3886 (diff)
downloadsharkey-3ae824c3542b0e232b9847ae702956e631acb276.tar.gz
sharkey-3ae824c3542b0e232b9847ae702956e631acb276.tar.bz2
sharkey-3ae824c3542b0e232b9847ae702956e631acb276.zip
:v:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/endpoints/posts/create.ts24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index 0fa52221f9..075e1ac9f0 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