diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-03-25 15:56:26 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-03-25 15:56:26 +0900 |
| commit | 47269a1782d56ae75d4cf210ad7eac1e3fb94a64 (patch) | |
| tree | 69d1fe73d1af0a6dc3fd7fc0018531b946c1aa38 /src/api/endpoints/posts/create.ts | |
| parent | Update CONTRIBUTING.md (diff) | |
| download | sharkey-47269a1782d56ae75d4cf210ad7eac1e3fb94a64.tar.gz sharkey-47269a1782d56ae75d4cf210ad7eac1e3fb94a64.tar.bz2 sharkey-47269a1782d56ae75d4cf210ad7eac1e3fb94a64.zip | |
[API] Check post dupulication
Diffstat (limited to 'src/api/endpoints/posts/create.ts')
| -rw-r--r-- | src/api/endpoints/posts/create.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts index 60b3592682..9ece143fa1 100644 --- a/src/api/endpoints/posts/create.ts +++ b/src/api/endpoints/posts/create.ts @@ -2,6 +2,7 @@ * Module dependencies */ import $ from 'cafy'; +import deepEqual = require('deep-equal'); import parse from '../../common/text'; import Post from '../../models/post'; import { isValidText } from '../../models/post'; @@ -142,6 +143,20 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { return rej('text, media_ids, repost_id or poll is required'); } + // 直近の投稿と重複してたらエラー + // TODO: 直近の投稿が一日前くらいなら重複とは見なさない + if (user.latest_post) { + if (deepEqual({ + text: user.latest_post.text, + media_ids: (user.latest_post.media_ids || []).map(id => id.toString()) + }, { + text: text, + media_ids: (files || []).map(file => file._id.toString()) + })) { + return rej('duplicate'); + } + } + // 投稿を作成 const post = await Post.insert({ created_at: new Date(), @@ -163,6 +178,12 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { //-------------------------------- // Post processes + User.update({ _id: user._id }, { + $set: { + latest_post: post + } + }); + let mentions = []; function addMention(mentionee, type) { |