From 168039e68299029b11161b53f90cc103788c0cd3 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 2 Mar 2017 15:25:27 +0900 Subject: [PATCH] :v: --- .../endpoints/posts/{create.js => create.ts} | 23 ++++++++++--------- src/api/validator.ts | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) rename src/api/endpoints/posts/{create.js => create.ts} (94%) diff --git a/src/api/endpoints/posts/create.js b/src/api/endpoints/posts/create.ts similarity index 94% rename from src/api/endpoints/posts/create.js rename to src/api/endpoints/posts/create.ts index eadc886c5..0ecce4e9a 100644 --- a/src/api/endpoints/posts/create.js +++ b/src/api/endpoints/posts/create.ts @@ -5,12 +5,12 @@ */ import validate from '../../validator'; import parse from '../../../common/text'; -import { Post, isValidText } from '../../models/post'; +import Post from '../../models/post'; +import { isValidText } from '../../models/post'; import User from '../../models/user'; import Following from '../../models/following'; import DriveFile from '../../models/drive-file'; import serialize from '../../serializers/post'; -import createFile from '../../common/add-file-to-drive'; import notify from '../../common/notify'; import event from '../../event'; import config from '../../../conf'; @@ -139,6 +139,7 @@ module.exports = (params, user, app) => if (typeof choice != 'string') return true; if (choice.trim().length == 0) return true; if (choice.trim().length > 50) return true; + return false; }); return shouldReject ? 'invalid poll choices' : true; }, @@ -167,7 +168,7 @@ module.exports = (params, user, app) => const post = await Post.insert({ created_at: new Date(), media_ids: files ? files.map(file => file._id) : undefined, - reply_to_id: replyTo ? replyTo._id : undefined, + reply_to_id: inReplyToPost ? inReplyToPost._id : undefined, repost_id: repost ? repost._id : undefined, poll: poll ? poll : undefined, text: text, @@ -225,21 +226,21 @@ module.exports = (params, user, app) => }); // If has in reply to post - if (replyTo) { + if (inReplyToPost) { // Increment replies count - Post.update({ _id: replyTo._id }, { + Post.update({ _id: inReplyToPost._id }, { $inc: { replies_count: 1 } }); // 自分自身へのリプライでない限りは通知を作成 - notify(replyTo.user_id, user._id, 'reply', { + notify(inReplyToPost.user_id, user._id, 'reply', { post_id: post._id }); // Add mention - addMention(replyTo.user_id, 'reply'); + addMention(inReplyToPost.user_id, 'reply'); } // If it is repost @@ -284,7 +285,7 @@ module.exports = (params, user, app) => if (text) { // Analyze const tokens = parse(text); - +/* // Extract a hashtags const hashtags = tokens .filter(t => t.type == 'hashtag') @@ -293,8 +294,8 @@ module.exports = (params, user, app) => .filter((v, i, s) => s.indexOf(v) == i); // ハッシュタグをデータベースに登録 - //registerHashtags(user, hashtags); - + registerHashtags(user, hashtags); +*/ // Extract an '@' mentions const atMentions = tokens .filter(t => t.type == 'mention') @@ -315,7 +316,7 @@ module.exports = (params, user, app) => if (mentionee == null) return; // 既に言及されたユーザーに対する返信や引用repostの場合も無視 - if (replyTo && replyTo.user_id.equals(mentionee._id)) return; + if (inReplyToPost && inReplyToPost.user_id.equals(mentionee._id)) return; if (repost && repost.user_id.equals(mentionee._id)) return; // Add mention diff --git a/src/api/validator.ts b/src/api/validator.ts index bc50da3a3..3f1678e35 100644 --- a/src/api/validator.ts +++ b/src/api/validator.ts @@ -10,8 +10,8 @@ function validate(value: any, type: 'string', isRequired?: boolean, validator?: function validate(value: any, type: 'number', isRequired?: boolean, validator?: Validator): [number, string]; function validate(value: any, type: 'boolean', isRequired?: boolean): [boolean, string]; function validate(value: any, type: 'array', isRequired?: boolean, validator?: Validator): [any[], string]; -function validate(value: any, type: 'set', isRequired?: boolean, validator?: Validator>): [Set, string]; -function validate(value: any, type: 'object', isRequired?: boolean, validator?: Validator): [Object, string]; +function validate(value: any, type: 'set', isRequired?: boolean, validator?: Validator): [any[], string]; +function validate(value: any, type: 'object', isRequired?: boolean, validator?: Validator): [any, string]; function validate(value: any, type: Type, isRequired?: boolean, validator?: Validator): [T, string] { if (value === undefined || value === null) { if (isRequired) {