summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-11-01 01:38:19 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-11-01 01:38:19 +0900
commit71c3e11708dad327924bdcb95193d44c2b11a907 (patch)
treefa5defe2a1cef98a799c02935bf482c35a728a11 /src/api
parentwip (diff)
downloadsharkey-71c3e11708dad327924bdcb95193d44c2b11a907.tar.gz
sharkey-71c3e11708dad327924bdcb95193d44c2b11a907.tar.bz2
sharkey-71c3e11708dad327924bdcb95193d44c2b11a907.zip
wip
Diffstat (limited to 'src/api')
-rw-r--r--src/api/endpoints/channels/create.ts3
-rw-r--r--src/api/endpoints/posts/create.ts17
-rw-r--r--src/api/models/channel.ts1
-rw-r--r--src/api/serializers/post.ts8
4 files changed, 27 insertions, 2 deletions
diff --git a/src/api/endpoints/channels/create.ts b/src/api/endpoints/channels/create.ts
index 74b089dfc3..e0c0e0192a 100644
--- a/src/api/endpoints/channels/create.ts
+++ b/src/api/endpoints/channels/create.ts
@@ -21,7 +21,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
const channel = await Channel.insert({
created_at: new Date(),
user_id: user._id,
- title: title
+ title: title,
+ index: 0
});
// Response
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index e0a02fa4a0..183cabf135 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -153,6 +153,16 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
if (repost && !isQuote) {
return rej('チャンネル内部では引用ではないRepostをすることはできません');
}
+ } else {
+ // 返信対象の投稿がチャンネルへの投稿だったらダメ
+ if (inReplyToPost && inReplyToPost.channel_id != null) {
+ return rej('チャンネル外部からチャンネル内部の投稿に返信することはできません');
+ }
+
+ // Repost対象の投稿がチャンネルへの投稿だったらダメ
+ if (repost && repost.channel_id != null) {
+ return rej('チャンネル外部からチャンネル内部の投稿をRepostすることはできません');
+ }
}
// Get 'poll' parameter
@@ -199,6 +209,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
const post = await Post.insert({
created_at: new Date(),
channel_id: channel ? channel._id : undefined,
+ index: channel ? channel.index + 1 : undefined,
media_ids: files ? files.map(file => file._id) : undefined,
reply_to_id: inReplyToPost ? inReplyToPost._id : undefined,
repost_id: repost ? repost._id : undefined,
@@ -217,6 +228,12 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// -----------------------------------------------------------
// Post processes
+ Channel.update({ _id: channel._id }, {
+ $inc: {
+ index: 1
+ }
+ });
+
User.update({ _id: user._id }, {
$set: {
latest_post: post
diff --git a/src/api/models/channel.ts b/src/api/models/channel.ts
index 79edb71367..c80e84dbc8 100644
--- a/src/api/models/channel.ts
+++ b/src/api/models/channel.ts
@@ -10,4 +10,5 @@ export type IChannel = {
created_at: Date;
title: string;
user_id: mongo.ObjectID;
+ index: number;
};
diff --git a/src/api/serializers/post.ts b/src/api/serializers/post.ts
index df917a8595..7d40df2d6a 100644
--- a/src/api/serializers/post.ts
+++ b/src/api/serializers/post.ts
@@ -8,6 +8,7 @@ import Reaction from '../models/post-reaction';
import { IUser } from '../models/user';
import Vote from '../models/poll-vote';
import serializeApp from './app';
+import serializeChannel from './channel';
import serializeUser from './user';
import serializeDriveFile from './drive-file';
import parse from '../common/text';
@@ -76,8 +77,13 @@ const self = (
_post.app = await serializeApp(_post.app_id);
}
+ // Populate channel
+ if (_post.channel_id) {
+ _post.channel = await serializeChannel(_post.channel_id);
+ }
+
+ // Populate media
if (_post.media_ids) {
- // Populate media
_post.media = await Promise.all(_post.media_ids.map(async fileId =>
await serializeDriveFile(fileId)
));