From e36a7081324b9e538ae40918072edd93ebc9b2cb Mon Sep 17 00:00:00 2001
From: syuilo
Date: Mon, 11 Dec 2017 13:33:33 +0900
Subject: #986
---
src/api/endpoints/drive/files/create.ts | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/drive/files/create.ts b/src/api/endpoints/drive/files/create.ts
index 7546eca309..437348a1ef 100644
--- a/src/api/endpoints/drive/files/create.ts
+++ b/src/api/endpoints/drive/files/create.ts
@@ -38,9 +38,15 @@ module.exports = async (file, params, user): Promise => {
const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
if (folderIdErr) throw 'invalid folder_id param';
- // Create file
- const driveFile = await create(user, file.path, name, null, folderId);
+ try {
+ // Create file
+ const driveFile = await create(user, file.path, name, null, folderId);
- // Serialize
- return serialize(driveFile);
+ // Serialize
+ return serialize(driveFile);
+ } catch (e) {
+ console.error(e);
+
+ throw e;
+ }
};
--
cgit v1.2.3-freya
From aff688d9bf7f55a6f91a9b50f2dd6809f13683a1 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Thu, 14 Dec 2017 13:31:17 +0900
Subject: :v:
---
docs/api/endpoints/posts/create.yaml | 53 ++++++++++++++++++++++++++++++++++++
src/api/endpoints/posts/create.ts | 4 ++-
test/api.js | 34 +++++++++++++----------
3 files changed, 76 insertions(+), 15 deletions(-)
create mode 100644 docs/api/endpoints/posts/create.yaml
(limited to 'src/api/endpoints')
diff --git a/docs/api/endpoints/posts/create.yaml b/docs/api/endpoints/posts/create.yaml
new file mode 100644
index 0000000000..db91775cb6
--- /dev/null
+++ b/docs/api/endpoints/posts/create.yaml
@@ -0,0 +1,53 @@
+endpoint: "posts/create"
+
+desc:
+ ja: "投稿します。"
+ en: "Compose new post."
+
+params:
+ - name: "text"
+ type: "string"
+ required: true
+ desc:
+ ja: "投稿の本文"
+ en: "Text of a post"
+ - name: "media_ids"
+ type: "id(DriveFile)[]"
+ required: false
+ desc:
+ ja: "添付するメディア"
+ en: "Media you want to attach"
+ - name: "reply_id"
+ type: "id(Post)"
+ required: false
+ desc:
+ ja: "返信する投稿"
+ en: "A post you want to reply"
+ - name: "repost_id"
+ type: "id(Post)"
+ required: false
+ desc:
+ ja: "引用する投稿"
+ en: "A post you want to quote"
+ - name: "poll"
+ type: "object(poll)"
+ required: false
+ desc:
+ ja: "投票"
+ en: "A poll"
+
+paramDefs:
+ poll:
+ - name: "choices"
+ type: "string[]"
+ required: true
+ desc:
+ ja: "投票の選択肢"
+ en: "Choices of a poll"
+
+res:
+ - name: "created_post"
+ type: "entity(Post)"
+ desc:
+ ja: "作成した投稿"
+ en: "A post that created"
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index ae4959dae4..7270efaf71 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -222,7 +222,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
const postObj = await serialize(post);
// Reponse
- res(postObj);
+ res({
+ created_post: postObj
+ });
//#region Post processes
diff --git a/test/api.js b/test/api.js
index 49f1faa53a..500b9adb72 100644
--- a/test/api.js
+++ b/test/api.js
@@ -224,7 +224,8 @@ describe('API', () => {
const res = await request('/posts/create', post, me);
res.should.have.status(200);
res.body.should.be.a('object');
- res.body.should.have.property('text').eql(post.text);
+ res.body.should.have.property('created_post');
+ res.body.created_post.should.have.property('text').eql(post.text);
}));
it('ファイルを添付できる', async(async () => {
@@ -237,7 +238,8 @@ describe('API', () => {
}, me);
res.should.have.status(200);
res.body.should.be.a('object');
- res.body.should.have.property('media_ids').eql([file._id.toString()]);
+ res.body.should.have.property('created_post');
+ res.body.created_post.should.have.property('media_ids').eql([file._id.toString()]);
}));
it('他人のファイルは添付できない', async(async () => {
@@ -283,10 +285,11 @@ describe('API', () => {
const res = await request('/posts/create', post, me);
res.should.have.status(200);
res.body.should.be.a('object');
- res.body.should.have.property('text').eql(post.text);
- res.body.should.have.property('reply_id').eql(post.reply_id);
- res.body.should.have.property('reply');
- res.body.reply.should.have.property('text').eql(himaPost.text);
+ res.body.should.have.property('created_post');
+ res.body.created_post.should.have.property('text').eql(post.text);
+ res.body.created_post.should.have.property('reply_id').eql(post.reply_id);
+ res.body.created_post.should.have.property('reply');
+ res.body.created_post.reply.should.have.property('text').eql(himaPost.text);
}));
it('repostできる', async(async () => {
@@ -303,9 +306,10 @@ describe('API', () => {
const res = await request('/posts/create', post, me);
res.should.have.status(200);
res.body.should.be.a('object');
- res.body.should.have.property('repost_id').eql(post.repost_id);
- res.body.should.have.property('repost');
- res.body.repost.should.have.property('text').eql(himaPost.text);
+ res.body.should.have.property('created_post');
+ res.body.created_post.should.have.property('repost_id').eql(post.repost_id);
+ res.body.created_post.should.have.property('repost');
+ res.body.created_post.repost.should.have.property('text').eql(himaPost.text);
}));
it('引用repostできる', async(async () => {
@@ -323,10 +327,11 @@ describe('API', () => {
const res = await request('/posts/create', post, me);
res.should.have.status(200);
res.body.should.be.a('object');
- res.body.should.have.property('text').eql(post.text);
- res.body.should.have.property('repost_id').eql(post.repost_id);
- res.body.should.have.property('repost');
- res.body.repost.should.have.property('text').eql(himaPost.text);
+ res.body.should.have.property('created_post');
+ res.body.created_post.should.have.property('text').eql(post.text);
+ res.body.created_post.should.have.property('repost_id').eql(post.repost_id);
+ res.body.created_post.should.have.property('repost');
+ res.body.created_post.repost.should.have.property('text').eql(himaPost.text);
}));
it('文字数ぎりぎりで怒られない', async(async () => {
@@ -395,7 +400,8 @@ describe('API', () => {
}, me);
res.should.have.status(200);
res.body.should.be.a('object');
- res.body.should.have.property('poll');
+ res.body.should.have.property('created_post');
+ res.body.created_post.should.have.property('poll');
}));
it('投票の選択肢が無くて怒られる', async(async () => {
--
cgit v1.2.3-freya
From c378e5fc946722d6e8a88bcf6a47109c31d70116 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Thu, 21 Dec 2017 02:20:02 +0900
Subject: #1021
---
src/api/endpoints/channels.ts | 16 ++++++-------
src/api/endpoints/channels/posts.ts | 16 ++++++-------
src/api/endpoints/drive/files.ts | 16 ++++++-------
src/api/endpoints/drive/folders.ts | 16 ++++++-------
src/api/endpoints/drive/stream.ts | 16 ++++++-------
src/api/endpoints/i/notifications.ts | 16 ++++++-------
src/api/endpoints/i/signin_history.ts | 16 ++++++-------
src/api/endpoints/messaging/messages.ts | 16 ++++++-------
src/api/endpoints/posts.ts | 16 ++++++-------
src/api/endpoints/posts/mentions.ts | 16 ++++++-------
src/api/endpoints/posts/reposts.ts | 16 ++++++-------
src/api/endpoints/posts/timeline.ts | 26 +++++++++++-----------
src/api/endpoints/users.ts | 16 ++++++-------
src/api/endpoints/users/posts.ts | 26 +++++++++++-----------
src/web/app/common/tags/messaging/room.tag | 2 +-
src/web/app/desktop/tags/home-widgets/mentions.tag | 2 +-
src/web/app/desktop/tags/home-widgets/timeline.tag | 4 ++--
src/web/app/desktop/tags/notifications.tag | 2 +-
src/web/app/desktop/tags/user-timeline.tag | 4 ++--
src/web/app/mobile/tags/drive.tag | 2 +-
src/web/app/mobile/tags/home-timeline.tag | 2 +-
src/web/app/mobile/tags/notifications.tag | 2 +-
src/web/app/mobile/tags/user-timeline.tag | 2 +-
src/web/docs/api/endpoints/posts/timeline.yaml | 4 ++--
24 files changed, 135 insertions(+), 135 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/channels.ts b/src/api/endpoints/channels.ts
index e10c943896..14817d9bd8 100644
--- a/src/api/endpoints/channels.ts
+++ b/src/api/endpoints/channels.ts
@@ -21,13 +21,13 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) return rej('invalid until_id param');
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- return rej('cannot set since_id and max_id');
+ // Check if both of since_id and until_id is specified
+ if (sinceId && untilId) {
+ return rej('cannot set since_id and until_id');
}
// Construct query
@@ -40,9 +40,9 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
}
diff --git a/src/api/endpoints/channels/posts.ts b/src/api/endpoints/channels/posts.ts
index 5c071a124f..9c2d607edb 100644
--- a/src/api/endpoints/channels/posts.ts
+++ b/src/api/endpoints/channels/posts.ts
@@ -22,13 +22,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) return rej('invalid until_id param');
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- return rej('cannot set since_id and max_id');
+ // Check if both of since_id and until_id is specified
+ if (sinceId && untilId) {
+ return rej('cannot set since_id and until_id');
}
// Get 'channel_id' parameter
@@ -58,9 +58,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
}
//#endregion Construct query
diff --git a/src/api/endpoints/drive/files.ts b/src/api/endpoints/drive/files.ts
index b2e094775c..3d5f81339a 100644
--- a/src/api/endpoints/drive/files.ts
+++ b/src/api/endpoints/drive/files.ts
@@ -22,13 +22,13 @@ module.exports = async (params, user, app) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) throw 'invalid since_id param';
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) throw 'invalid max_id param';
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) throw 'invalid until_id param';
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- throw 'cannot set since_id and max_id';
+ // Check if both of since_id and until_id is specified
+ if (sinceId && untilId) {
+ throw 'cannot set since_id and until_id';
}
// Get 'folder_id' parameter
@@ -52,9 +52,9 @@ module.exports = async (params, user, app) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
}
if (type) {
diff --git a/src/api/endpoints/drive/folders.ts b/src/api/endpoints/drive/folders.ts
index d49ef0af03..7944e2c6a6 100644
--- a/src/api/endpoints/drive/folders.ts
+++ b/src/api/endpoints/drive/folders.ts
@@ -22,13 +22,13 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) return rej('invalid until_id param');
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- return rej('cannot set since_id and max_id');
+ // Check if both of since_id and until_id is specified
+ if (sinceId && untilId) {
+ return rej('cannot set since_id and until_id');
}
// Get 'folder_id' parameter
@@ -48,9 +48,9 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
}
diff --git a/src/api/endpoints/drive/stream.ts b/src/api/endpoints/drive/stream.ts
index 7ee255e5d1..5b0eb0a0d8 100644
--- a/src/api/endpoints/drive/stream.ts
+++ b/src/api/endpoints/drive/stream.ts
@@ -21,13 +21,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) return rej('invalid until_id param');
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- return rej('cannot set since_id and max_id');
+ // Check if both of since_id and until_id is specified
+ if (sinceId && untilId) {
+ return rej('cannot set since_id and until_id');
}
// Get 'type' parameter
@@ -46,9 +46,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
}
if (type) {
diff --git a/src/api/endpoints/i/notifications.ts b/src/api/endpoints/i/notifications.ts
index 607e0768a4..48254e5e67 100644
--- a/src/api/endpoints/i/notifications.ts
+++ b/src/api/endpoints/i/notifications.ts
@@ -36,13 +36,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) return rej('invalid until_id param');
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- return rej('cannot set since_id and max_id');
+ // Check if both of since_id and until_id is specified
+ if (sinceId && untilId) {
+ return rej('cannot set since_id and until_id');
}
const query = {
@@ -73,9 +73,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
}
diff --git a/src/api/endpoints/i/signin_history.ts b/src/api/endpoints/i/signin_history.ts
index 1a6e50c7c8..e38bfa4d98 100644
--- a/src/api/endpoints/i/signin_history.ts
+++ b/src/api/endpoints/i/signin_history.ts
@@ -21,13 +21,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) return rej('invalid until_id param');
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- return rej('cannot set since_id and max_id');
+ // Check if both of since_id and until_id is specified
+ if (sinceId && untilId) {
+ return rej('cannot set since_id and until_id');
}
const query = {
@@ -43,9 +43,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
}
diff --git a/src/api/endpoints/messaging/messages.ts b/src/api/endpoints/messaging/messages.ts
index 7b270924eb..3d3c6950a1 100644
--- a/src/api/endpoints/messaging/messages.ts
+++ b/src/api/endpoints/messaging/messages.ts
@@ -44,13 +44,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) return rej('invalid until_id param');
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- return rej('cannot set since_id and max_id');
+ // Check if both of since_id and until_id is specified
+ if (sinceId && untilId) {
+ return rej('cannot set since_id and until_id');
}
const query = {
@@ -72,9 +72,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
}
diff --git a/src/api/endpoints/posts.ts b/src/api/endpoints/posts.ts
index f6efcc108d..db166cd67a 100644
--- a/src/api/endpoints/posts.ts
+++ b/src/api/endpoints/posts.ts
@@ -36,13 +36,13 @@ module.exports = (params) => new Promise(async (res, rej) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) return rej('invalid until_id param');
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- return rej('cannot set since_id and max_id');
+ // Check if both of since_id and until_id is specified
+ if (sinceId && untilId) {
+ return rej('cannot set since_id and until_id');
}
// Construct query
@@ -55,9 +55,9 @@ module.exports = (params) => new Promise(async (res, rej) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
}
diff --git a/src/api/endpoints/posts/mentions.ts b/src/api/endpoints/posts/mentions.ts
index 0ebe8be503..3bb4ec3fa0 100644
--- a/src/api/endpoints/posts/mentions.ts
+++ b/src/api/endpoints/posts/mentions.ts
@@ -27,13 +27,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) return rej('invalid until_id param');
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- return rej('cannot set since_id and max_id');
+ // Check if both of since_id and until_id is specified
+ if (sinceId && untilId) {
+ return rej('cannot set since_id and until_id');
}
// Construct query
@@ -58,9 +58,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
}
diff --git a/src/api/endpoints/posts/reposts.ts b/src/api/endpoints/posts/reposts.ts
index b701ff7574..bcc6163a11 100644
--- a/src/api/endpoints/posts/reposts.ts
+++ b/src/api/endpoints/posts/reposts.ts
@@ -25,13 +25,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) return rej('invalid until_id param');
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- return rej('cannot set since_id and max_id');
+ // Check if both of since_id and until_id is specified
+ if (sinceId && untilId) {
+ return rej('cannot set since_id and until_id');
}
// Lookup post
@@ -55,9 +55,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
}
diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts
index 0d08b95463..91cba0a047 100644
--- a/src/api/endpoints/posts/timeline.ts
+++ b/src/api/endpoints/posts/timeline.ts
@@ -25,21 +25,21 @@ module.exports = async (params, user, app) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) throw 'invalid since_id param';
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) throw 'invalid max_id param';
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) throw 'invalid until_id param';
// Get 'since_date' parameter
const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$;
if (sinceDateErr) throw 'invalid since_date param';
- // Get 'max_date' parameter
- const [maxDate, maxDateErr] = $(params.max_date).optional.number().$;
- if (maxDateErr) throw 'invalid max_date param';
+ // Get 'until_date' parameter
+ const [untilDate, untilDateErr] = $(params.until_date).optional.number().$;
+ if (untilDateErr) throw 'invalid until_date param';
- // Check if only one of since_id, max_id, since_date, max_date specified
- if ([sinceId, maxId, sinceDate, maxDate].filter(x => x != null).length > 1) {
- throw 'only one of since_id, max_id, since_date, max_date can be specified';
+ // Check if only one of since_id, until_id, since_date, until_date specified
+ if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
+ throw 'only one of since_id, until_id, since_date, until_date can be specified';
}
const { followingIds, watchingChannelIds } = await rap({
@@ -85,18 +85,18 @@ module.exports = async (params, user, app) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
} else if (sinceDate) {
sort._id = 1;
query.created_at = {
$gt: new Date(sinceDate)
};
- } else if (maxDate) {
+ } else if (untilDate) {
query.created_at = {
- $lt: new Date(maxDate)
+ $lt: new Date(untilDate)
};
}
//#endregion
diff --git a/src/api/endpoints/users.ts b/src/api/endpoints/users.ts
index 134f262fb1..f3c9b66a5e 100644
--- a/src/api/endpoints/users.ts
+++ b/src/api/endpoints/users.ts
@@ -21,13 +21,13 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) return rej('invalid until_id param');
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- return rej('cannot set since_id and max_id');
+ // Check if both of since_id and until_id is specified
+ if (sinceId && untilId) {
+ return rej('cannot set since_id and until_id');
}
// Construct query
@@ -40,9 +40,9 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
}
diff --git a/src/api/endpoints/users/posts.ts b/src/api/endpoints/users/posts.ts
index fe821cf17a..0d8384a43d 100644
--- a/src/api/endpoints/users/posts.ts
+++ b/src/api/endpoints/users/posts.ts
@@ -42,21 +42,21 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) return rej('invalid until_id param');
// Get 'since_date' parameter
const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$;
if (sinceDateErr) throw 'invalid since_date param';
- // Get 'max_date' parameter
- const [maxDate, maxDateErr] = $(params.max_date).optional.number().$;
- if (maxDateErr) throw 'invalid max_date param';
+ // Get 'until_date' parameter
+ const [untilDate, untilDateErr] = $(params.until_date).optional.number().$;
+ if (untilDateErr) throw 'invalid until_date param';
- // Check if only one of since_id, max_id, since_date, max_date specified
- if ([sinceId, maxId, sinceDate, maxDate].filter(x => x != null).length > 1) {
- throw 'only one of since_id, max_id, since_date, max_date can be specified';
+ // Check if only one of since_id, until_id, since_date, until_date specified
+ if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
+ throw 'only one of since_id, until_id, since_date, until_date can be specified';
}
const q = userId !== undefined
@@ -88,18 +88,18 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
} else if (sinceDate) {
sort._id = 1;
query.created_at = {
$gt: new Date(sinceDate)
};
- } else if (maxDate) {
+ } else if (untilDate) {
query.created_at = {
- $lt: new Date(maxDate)
+ $lt: new Date(untilDate)
};
}
diff --git a/src/web/app/common/tags/messaging/room.tag b/src/web/app/common/tags/messaging/room.tag
index a149e1de22..7b4d1be569 100644
--- a/src/web/app/common/tags/messaging/room.tag
+++ b/src/web/app/common/tags/messaging/room.tag
@@ -254,7 +254,7 @@
this.api('messaging/messages', {
user_id: this.user.id,
limit: max + 1,
- max_id: this.moreMessagesIsInStock ? this.messages[0].id : undefined
+ until_id: this.moreMessagesIsInStock ? this.messages[0].id : undefined
}).then(messages => {
if (messages.length == max + 1) {
this.moreMessagesIsInStock = true;
diff --git a/src/web/app/desktop/tags/home-widgets/mentions.tag b/src/web/app/desktop/tags/home-widgets/mentions.tag
index a48c7239a1..2687283079 100644
--- a/src/web/app/desktop/tags/home-widgets/mentions.tag
+++ b/src/web/app/desktop/tags/home-widgets/mentions.tag
@@ -101,7 +101,7 @@
});
this.api('posts/mentions', {
following: this.mode == 'following',
- max_id: this.refs.timeline.tail().id
+ until_id: this.refs.timeline.tail().id
}).then(posts => {
this.update({
moreLoading: false
diff --git a/src/web/app/desktop/tags/home-widgets/timeline.tag b/src/web/app/desktop/tags/home-widgets/timeline.tag
index 4c58aa4aa8..9571b09f34 100644
--- a/src/web/app/desktop/tags/home-widgets/timeline.tag
+++ b/src/web/app/desktop/tags/home-widgets/timeline.tag
@@ -86,7 +86,7 @@
});
this.api('posts/timeline', {
- max_date: this.date ? this.date.getTime() : undefined
+ until_date: this.date ? this.date.getTime() : undefined
}).then(posts => {
this.update({
isLoading: false,
@@ -103,7 +103,7 @@
moreLoading: true
});
this.api('posts/timeline', {
- max_id: this.refs.timeline.tail().id
+ until_id: this.refs.timeline.tail().id
}).then(posts => {
this.update({
moreLoading: false
diff --git a/src/web/app/desktop/tags/notifications.tag b/src/web/app/desktop/tags/notifications.tag
index 3218c00f6a..39862487e9 100644
--- a/src/web/app/desktop/tags/notifications.tag
+++ b/src/web/app/desktop/tags/notifications.tag
@@ -283,7 +283,7 @@
this.api('i/notifications', {
limit: max + 1,
- max_id: this.notifications[this.notifications.length - 1].id
+ until_id: this.notifications[this.notifications.length - 1].id
}).then(notifications => {
if (notifications.length == max + 1) {
this.moreNotifications = true;
diff --git a/src/web/app/desktop/tags/user-timeline.tag b/src/web/app/desktop/tags/user-timeline.tag
index 2b05f6b5cf..134aeee28c 100644
--- a/src/web/app/desktop/tags/user-timeline.tag
+++ b/src/web/app/desktop/tags/user-timeline.tag
@@ -96,7 +96,7 @@
this.fetch = cb => {
this.api('users/posts', {
user_id: this.user.id,
- max_date: this.date ? this.date.getTime() : undefined,
+ until_date: this.date ? this.date.getTime() : undefined,
with_replies: this.mode == 'with-replies'
}).then(posts => {
this.update({
@@ -116,7 +116,7 @@
this.api('users/posts', {
user_id: this.user.id,
with_replies: this.mode == 'with-replies',
- max_id: this.refs.timeline.tail().id
+ until_id: this.refs.timeline.tail().id
}).then(posts => {
this.update({
moreLoading: false
diff --git a/src/web/app/mobile/tags/drive.tag b/src/web/app/mobile/tags/drive.tag
index 41dbfddae9..2a3ff23bfa 100644
--- a/src/web/app/mobile/tags/drive.tag
+++ b/src/web/app/mobile/tags/drive.tag
@@ -430,7 +430,7 @@
this.api('drive/files', {
folder_id: this.folder ? this.folder.id : null,
limit: max + 1,
- max_id: this.files[this.files.length - 1].id
+ until_id: this.files[this.files.length - 1].id
}).then(files => {
if (files.length == max + 1) {
this.moreFiles = true;
diff --git a/src/web/app/mobile/tags/home-timeline.tag b/src/web/app/mobile/tags/home-timeline.tag
index e96823fa10..397d2b3980 100644
--- a/src/web/app/mobile/tags/home-timeline.tag
+++ b/src/web/app/mobile/tags/home-timeline.tag
@@ -47,7 +47,7 @@
this.more = () => {
return this.api('posts/timeline', {
- max_id: this.refs.timeline.tail().id
+ until_id: this.refs.timeline.tail().id
});
};
diff --git a/src/web/app/mobile/tags/notifications.tag b/src/web/app/mobile/tags/notifications.tag
index c3500d1b84..742cc45145 100644
--- a/src/web/app/mobile/tags/notifications.tag
+++ b/src/web/app/mobile/tags/notifications.tag
@@ -146,7 +146,7 @@
this.api('i/notifications', {
limit: max + 1,
- max_id: this.notifications[this.notifications.length - 1].id
+ until_id: this.notifications[this.notifications.length - 1].id
}).then(notifications => {
if (notifications.length == max + 1) {
this.moreNotifications = true;
diff --git a/src/web/app/mobile/tags/user-timeline.tag b/src/web/app/mobile/tags/user-timeline.tag
index 4dbe719f5a..86ead5971f 100644
--- a/src/web/app/mobile/tags/user-timeline.tag
+++ b/src/web/app/mobile/tags/user-timeline.tag
@@ -26,7 +26,7 @@
return this.api('users/posts', {
user_id: this.user.id,
with_media: this.withMedia,
- max_id: this.refs.timeline.tail().id
+ until_id: this.refs.timeline.tail().id
});
};
diff --git a/src/web/docs/api/endpoints/posts/timeline.yaml b/src/web/docs/api/endpoints/posts/timeline.yaml
index e1d78c082e..01976b0611 100644
--- a/src/web/docs/api/endpoints/posts/timeline.yaml
+++ b/src/web/docs/api/endpoints/posts/timeline.yaml
@@ -15,7 +15,7 @@ params:
optional: true
desc:
ja: "指定すると、この投稿を基点としてより新しい投稿を取得します"
- - name: "max_id"
+ - name: "until_id"
type: "id(Post)"
optional: true
desc:
@@ -25,7 +25,7 @@ params:
optional: true
desc:
ja: "指定した時間を基点としてより新しい投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。"
- - name: "max_date"
+ - name: "until_date"
type: "number"
optional: true
desc:
--
cgit v1.2.3-freya
From eaf0d5e637e0fd5be62b7ccf940ba1bcebeba786 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Thu, 21 Dec 2017 04:01:44 +0900
Subject: #1017 #155
---
src/api/endpoints/posts/search.ts | 96 ++++++++++++++++++++----
src/web/app/common/scripts/parse-search-query.ts | 41 ++++++++++
src/web/app/desktop/router.ts | 4 +-
src/web/app/desktop/tags/search-posts.tag | 6 +-
src/web/app/desktop/tags/ui.tag | 2 +-
src/web/app/mobile/router.ts | 4 +-
src/web/app/mobile/tags/search-posts.tag | 6 +-
src/web/app/mobile/tags/ui.tag | 2 +-
src/web/docs/search.ja.pug | 38 ++++++++++
9 files changed, 172 insertions(+), 27 deletions(-)
create mode 100644 src/web/app/common/scripts/parse-search-query.ts
create mode 100644 src/web/docs/search.ja.pug
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index b434f64342..dba7a53b5f 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -5,6 +5,7 @@ import * as mongo from 'mongodb';
import $ from 'cafy';
const escapeRegexp = require('escape-regexp');
import Post from '../../models/post';
+import User from '../../models/user';
import serialize from '../../serializers/post';
import config from '../../../conf';
@@ -16,33 +17,98 @@ import config from '../../../conf';
* @return {Promise}
*/
module.exports = (params, me) => new Promise(async (res, rej) => {
- // Get 'query' parameter
- const [query, queryError] = $(params.query).string().pipe(x => x != '').$;
- if (queryError) return rej('invalid query param');
+ // Get 'text' parameter
+ const [text, textError] = $(params.text).optional.string().$;
+ if (textError) return rej('invalid text param');
+
+ // Get 'user_id' parameter
+ const [userId, userIdErr] = $(params.user_id).optional.id().$;
+ if (userIdErr) return rej('invalid user_id param');
+
+ // Get 'username' parameter
+ const [username, usernameErr] = $(params.username).optional.string().$;
+ if (usernameErr) return rej('invalid username param');
+
+ // Get 'include_replies' parameter
+ const [includeReplies = true, includeRepliesErr] = $(params.include_replies).optional.boolean().$;
+ if (includeRepliesErr) return rej('invalid include_replies param');
+
+ // Get 'with_media' parameter
+ const [withMedia = false, withMediaErr] = $(params.with_media).optional.boolean().$;
+ if (withMediaErr) return rej('invalid with_media param');
+
+ // Get 'since_date' parameter
+ const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$;
+ if (sinceDateErr) throw 'invalid since_date param';
+
+ // Get 'until_date' parameter
+ const [untilDate, untilDateErr] = $(params.until_date).optional.number().$;
+ if (untilDateErr) throw 'invalid until_date param';
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
if (offsetErr) return rej('invalid offset param');
- // Get 'max' parameter
- const [max = 10, maxErr] = $(params.max).optional.number().range(1, 30).$;
- if (maxErr) return rej('invalid max param');
+ // Get 'limit' parameter
+ const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 30).$;
+ if (limitErr) return rej('invalid limit param');
+
+ let user = userId;
+
+ if (user == null && username != null) {
+ const _user = await User.findOne({
+ username_lower: username.toLowerCase()
+ });
+ if (_user) {
+ user = _user._id;
+ }
+ }
- // If Elasticsearch is available, search by $
+ // If Elasticsearch is available, search by it
// If not, search by MongoDB
(config.elasticsearch.enable ? byElasticsearch : byNative)
- (res, rej, me, query, offset, max);
+ (res, rej, me, text, user, includeReplies, withMedia, sinceDate, untilDate, offset, limit);
});
// Search by MongoDB
-async function byNative(res, rej, me, query, offset, max) {
- const escapedQuery = escapeRegexp(query);
+async function byNative(res, rej, me, text, userId, includeReplies, withMedia, sinceDate, untilDate, offset, max) {
+ const q: any = {};
+
+ if (text) {
+ q.$and = text.split(' ').map(x => ({
+ text: new RegExp(escapeRegexp(x))
+ }));
+ }
+
+ if (userId) {
+ q.user_id = userId;
+ }
+
+ if (!includeReplies) {
+ q.reply_id = null;
+ }
+
+ if (withMedia) {
+ q.media_ids = {
+ $exists: true,
+ $ne: null
+ };
+ }
+
+ if (sinceDate) {
+ q.created_at = {
+ $gt: new Date(sinceDate)
+ };
+ }
+
+ if (untilDate) {
+ if (q.created_at == undefined) q.created_at = {};
+ q.created_at.$lt = new Date(untilDate);
+ }
// Search posts
const posts = await Post
- .find({
- text: new RegExp(escapedQuery)
- }, {
+ .find(q, {
sort: {
_id: -1
},
@@ -56,7 +122,7 @@ async function byNative(res, rej, me, query, offset, max) {
}
// Search by Elasticsearch
-async function byElasticsearch(res, rej, me, query, offset, max) {
+async function byElasticsearch(res, rej, me, text, userId, includeReplies, withMedia, sinceDate, untilDate, offset, max) {
const es = require('../../db/elasticsearch');
es.search({
@@ -68,7 +134,7 @@ async function byElasticsearch(res, rej, me, query, offset, max) {
query: {
simple_query_string: {
fields: ['text'],
- query: query,
+ query: text,
default_operator: 'and'
}
},
diff --git a/src/web/app/common/scripts/parse-search-query.ts b/src/web/app/common/scripts/parse-search-query.ts
new file mode 100644
index 0000000000..adcbfbb8fe
--- /dev/null
+++ b/src/web/app/common/scripts/parse-search-query.ts
@@ -0,0 +1,41 @@
+export default function(qs: string) {
+ const q = {
+ text: ''
+ };
+
+ qs.split(' ').forEach(x => {
+ if (/^([a-z_]+?):(.+?)$/.test(x)) {
+ const [key, value] = x.split(':');
+ switch (key) {
+ case 'user':
+ q['username'] = value;
+ break;
+ case 'reply':
+ q['include_replies'] = value == 'true';
+ break;
+ case 'media':
+ q['with_media'] = value == 'true';
+ break;
+ case 'until':
+ case 'since':
+ // YYYY-MM-DD
+ if (/^[0-9]+\-[0-9]+\-[0-9]+$/) {
+ const [yyyy, mm, dd] = value.split('-');
+ q[`${key}_date`] = (new Date(parseInt(yyyy, 10), parseInt(mm, 10) - 1, parseInt(dd, 10))).getTime();
+ }
+ break;
+ default:
+ q[key] = value;
+ break;
+ }
+ } else {
+ q.text += x + ' ';
+ }
+ });
+
+ if (q.text) {
+ q.text = q.text.trim();
+ }
+
+ return q;
+}
diff --git a/src/web/app/desktop/router.ts b/src/web/app/desktop/router.ts
index 27b63ab2ef..ce68c4f2d1 100644
--- a/src/web/app/desktop/router.ts
+++ b/src/web/app/desktop/router.ts
@@ -16,7 +16,7 @@ export default (mios: MiOS) => {
route('/i/messaging/:user', messaging);
route('/i/mentions', mentions);
route('/post::post', post);
- route('/search::query', search);
+ route('/search', search);
route('/:user', user.bind(null, 'home'));
route('/:user/graphs', user.bind(null, 'graphs'));
route('/:user/:post', post);
@@ -47,7 +47,7 @@ export default (mios: MiOS) => {
function search(ctx) {
const el = document.createElement('mk-search-page');
- el.setAttribute('query', ctx.params.query);
+ el.setAttribute('query', ctx.querystring.substr(2));
mount(el);
}
diff --git a/src/web/app/desktop/tags/search-posts.tag b/src/web/app/desktop/tags/search-posts.tag
index 52f765d1a1..c6b24837d2 100644
--- a/src/web/app/desktop/tags/search-posts.tag
+++ b/src/web/app/desktop/tags/search-posts.tag
@@ -33,6 +33,8 @@
diff --git a/src/web/app/mobile/router.ts b/src/web/app/mobile/router.ts
index d0c6add0b8..afb9aa6201 100644
--- a/src/web/app/mobile/router.ts
+++ b/src/web/app/mobile/router.ts
@@ -23,7 +23,7 @@ export default (mios: MiOS) => {
route('/i/settings/authorized-apps', settingsAuthorizedApps);
route('/post/new', newPost);
route('/post::post', post);
- route('/search::query', search);
+ route('/search', search);
route('/:user', user.bind(null, 'overview'));
route('/:user/graphs', user.bind(null, 'graphs'));
route('/:user/followers', userFollowers);
@@ -83,7 +83,7 @@ export default (mios: MiOS) => {
function search(ctx) {
const el = document.createElement('mk-search-page');
- el.setAttribute('query', ctx.params.query);
+ el.setAttribute('query', ctx.querystring.substr(2));
mount(el);
}
diff --git a/src/web/app/mobile/tags/search-posts.tag b/src/web/app/mobile/tags/search-posts.tag
index 967764bc2c..023a35bf62 100644
--- a/src/web/app/mobile/tags/search-posts.tag
+++ b/src/web/app/mobile/tags/search-posts.tag
@@ -15,6 +15,8 @@
width calc(100% - 32px)
diff --git a/src/web/docs/search.ja.pug b/src/web/docs/search.ja.pug
new file mode 100644
index 0000000000..f7ec9519f5
--- /dev/null
+++ b/src/web/docs/search.ja.pug
@@ -0,0 +1,38 @@
+h1 検索
+
+p 投稿を検索することができます。
+p
+ | キーワードを半角スペースで区切ると、and検索になります。
+ | 例えば、「git コミット」と検索すると、「gitで編集したファイルの特定の行だけコミットする方法がわからない」などがマッチします。
+
+section
+ h2 オプション
+ p
+ | オプションを使用して、より高度な検索をすることもできます。
+ | オプションを指定するには、「オプション名:値」という形式でクエリに含めます。
+ p 利用可能なオプション一覧です:
+
+ table
+ thead
+ tr
+ th 名前
+ th 説明
+ tbody
+ tr
+ td user
+ td ユーザー名。投稿者を限定します。
+ tr
+ td reply
+ td 返信を含めるか否か。(trueかfalse)
+ tr
+ td media
+ td メディアが添付されているか。(trueかfalse)
+ tr
+ td until
+ td 上限の日時。(YYYY-MM-DD)
+ tr
+ td since
+ td 下限の日時。(YYYY-MM-DD)
+
+ p 例えば、「@syuiloの2017年11月1日から2017年12月31日までの『Misskey』というテキストを含む返信ではない投稿」を検索したい場合、クエリは以下のようになります:
+ code user:syuilo since:2017-11-01 until:2017-12-31 reply:false Misskey
--
cgit v1.2.3-freya
From 59120063fe792ba0bc230749a36b1e4acf86443f Mon Sep 17 00:00:00 2001
From: こぴなたみぽ
Date: Thu, 21 Dec 2017 06:31:56 +0900
Subject: #1023
---
src/api/endpoints/posts/search.ts | 21 ++++++++++++++++++---
src/web/app/common/scripts/parse-search-query.ts | 3 +++
src/web/docs/search.ja.pug | 3 +++
3 files changed, 24 insertions(+), 3 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index dba7a53b5f..88cdd32dac 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -6,6 +6,7 @@ import $ from 'cafy';
const escapeRegexp = require('escape-regexp');
import Post from '../../models/post';
import User from '../../models/user';
+import getFriends from '../../common/get-friends';
import serialize from '../../serializers/post';
import config from '../../../conf';
@@ -29,6 +30,10 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
const [username, usernameErr] = $(params.username).optional.string().$;
if (usernameErr) return rej('invalid username param');
+ // Get 'following' parameter
+ const [following = null, followingErr] = $(params.following).optional.nullable.boolean().$;
+ if (followingErr) return rej('invalid following param');
+
// Get 'include_replies' parameter
const [includeReplies = true, includeRepliesErr] = $(params.include_replies).optional.boolean().$;
if (includeRepliesErr) return rej('invalid include_replies param');
@@ -67,11 +72,11 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// If Elasticsearch is available, search by it
// If not, search by MongoDB
(config.elasticsearch.enable ? byElasticsearch : byNative)
- (res, rej, me, text, user, includeReplies, withMedia, sinceDate, untilDate, offset, limit);
+ (res, rej, me, text, user, following, includeReplies, withMedia, sinceDate, untilDate, offset, limit);
});
// Search by MongoDB
-async function byNative(res, rej, me, text, userId, includeReplies, withMedia, sinceDate, untilDate, offset, max) {
+async function byNative(res, rej, me, text, userId, following, includeReplies, withMedia, sinceDate, untilDate, offset, max) {
const q: any = {};
if (text) {
@@ -84,6 +89,16 @@ async function byNative(res, rej, me, text, userId, includeReplies, withMedia, s
q.user_id = userId;
}
+ if (following != null) {
+ const ids = await getFriends(me._id, false);
+ q.user_id = {};
+ if (following) {
+ q.user_id.$in = ids;
+ } else {
+ q.user_id.$nin = ids;
+ }
+ }
+
if (!includeReplies) {
q.reply_id = null;
}
@@ -122,7 +137,7 @@ async function byNative(res, rej, me, text, userId, includeReplies, withMedia, s
}
// Search by Elasticsearch
-async function byElasticsearch(res, rej, me, text, userId, includeReplies, withMedia, sinceDate, untilDate, offset, max) {
+async function byElasticsearch(res, rej, me, text, userId, following, includeReplies, withMedia, sinceDate, untilDate, offset, max) {
const es = require('../../db/elasticsearch');
es.search({
diff --git a/src/web/app/common/scripts/parse-search-query.ts b/src/web/app/common/scripts/parse-search-query.ts
index adcbfbb8fe..62b2cf51b1 100644
--- a/src/web/app/common/scripts/parse-search-query.ts
+++ b/src/web/app/common/scripts/parse-search-query.ts
@@ -10,6 +10,9 @@ export default function(qs: string) {
case 'user':
q['username'] = value;
break;
+ case 'follow':
+ q['following'] = value == 'null' ? null : value == 'true';
+ break;
case 'reply':
q['include_replies'] = value == 'true';
break;
diff --git a/src/web/docs/search.ja.pug b/src/web/docs/search.ja.pug
index f7ec9519f5..7d4d23fb6a 100644
--- a/src/web/docs/search.ja.pug
+++ b/src/web/docs/search.ja.pug
@@ -21,6 +21,9 @@ section
tr
td user
td ユーザー名。投稿者を限定します。
+ tr
+ td follow
+ td フォローしているユーザーのみに限定。(trueかfalse)
tr
td reply
td 返信を含めるか否か。(trueかfalse)
--
cgit v1.2.3-freya
From 40f5e67ff0f803fab117c405a0614df915381433 Mon Sep 17 00:00:00 2001
From: こぴなたみぽ
Date: Thu, 21 Dec 2017 07:35:16 +0900
Subject: :v:
---
src/api/endpoints/posts/search.ts | 130 +++++++++++++++++------
src/web/app/common/scripts/parse-search-query.ts | 7 +-
src/web/docs/search.ja.pug | 29 ++++-
3 files changed, 131 insertions(+), 35 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index 88cdd32dac..21e9134d38 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -34,13 +34,17 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
const [following = null, followingErr] = $(params.following).optional.nullable.boolean().$;
if (followingErr) return rej('invalid following param');
- // Get 'include_replies' parameter
- const [includeReplies = true, includeRepliesErr] = $(params.include_replies).optional.boolean().$;
- if (includeRepliesErr) return rej('invalid include_replies param');
+ // Get 'reply' parameter
+ const [reply = null, replyErr] = $(params.reply).optional.nullable.boolean().$;
+ if (replyErr) return rej('invalid reply param');
- // Get 'with_media' parameter
- const [withMedia = false, withMediaErr] = $(params.with_media).optional.boolean().$;
- if (withMediaErr) return rej('invalid with_media param');
+ // Get 'repost' parameter
+ const [repost = null, repostErr] = $(params.repost).optional.nullable.boolean().$;
+ if (repostErr) return rej('invalid repost param');
+
+ // Get 'media' parameter
+ const [media = null, mediaErr] = $(params.media).optional.nullable.boolean().$;
+ if (mediaErr) return rej('invalid media param');
// Get 'since_date' parameter
const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$;
@@ -72,53 +76,119 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// If Elasticsearch is available, search by it
// If not, search by MongoDB
(config.elasticsearch.enable ? byElasticsearch : byNative)
- (res, rej, me, text, user, following, includeReplies, withMedia, sinceDate, untilDate, offset, limit);
+ (res, rej, me, text, user, following, reply, repost, media, sinceDate, untilDate, offset, limit);
});
// Search by MongoDB
-async function byNative(res, rej, me, text, userId, following, includeReplies, withMedia, sinceDate, untilDate, offset, max) {
- const q: any = {};
+async function byNative(res, rej, me, text, userId, following, reply, repost, media, sinceDate, untilDate, offset, max) {
+ const q: any = {
+ $and: []
+ };
+
+ const push = q.$and.push;
if (text) {
- q.$and = text.split(' ').map(x => ({
- text: new RegExp(escapeRegexp(x))
- }));
+ push({
+ $and: text.split(' ').map(x => ({
+ text: new RegExp(escapeRegexp(x))
+ }))
+ });
}
if (userId) {
- q.user_id = userId;
+ push({
+ user_id: userId
+ });
}
if (following != null) {
const ids = await getFriends(me._id, false);
- q.user_id = {};
- if (following) {
- q.user_id.$in = ids;
+ push({
+ user_id: following ? {
+ $in: ids
+ } : {
+ $nin: ids
+ }
+ });
+ }
+
+ if (reply != null) {
+ if (reply) {
+ push({
+ reply_id: {
+ $exists: true,
+ $ne: null
+ }
+ });
} else {
- q.user_id.$nin = ids;
+ push({
+ $or: [{
+ reply_id: {
+ $exists: false
+ }
+ }, {
+ reply_id: null
+ }]
+ });
}
}
- if (!includeReplies) {
- q.reply_id = null;
+ if (repost != null) {
+ if (repost) {
+ push({
+ repost_id: {
+ $exists: true,
+ $ne: null
+ }
+ });
+ } else {
+ push({
+ $or: [{
+ repost_id: {
+ $exists: false
+ }
+ }, {
+ repost_id: null
+ }]
+ });
+ }
}
- if (withMedia) {
- q.media_ids = {
- $exists: true,
- $ne: null
- };
+ if (media != null) {
+ if (media) {
+ push({
+ media_ids: {
+ $exists: true,
+ $ne: null
+ }
+ });
+ } else {
+ push({
+ $or: [{
+ media_ids: {
+ $exists: false
+ }
+ }, {
+ media_ids: null
+ }]
+ });
+ }
}
if (sinceDate) {
- q.created_at = {
- $gt: new Date(sinceDate)
- };
+ push({
+ created_at: {
+ $gt: new Date(sinceDate)
+ }
+ });
}
if (untilDate) {
- if (q.created_at == undefined) q.created_at = {};
- q.created_at.$lt = new Date(untilDate);
+ push({
+ created_at: {
+ $lt: new Date(untilDate)
+ }
+ });
}
// Search posts
@@ -137,7 +207,7 @@ async function byNative(res, rej, me, text, userId, following, includeReplies, w
}
// Search by Elasticsearch
-async function byElasticsearch(res, rej, me, text, userId, following, includeReplies, withMedia, sinceDate, untilDate, offset, max) {
+async function byElasticsearch(res, rej, me, text, userId, following, reply, repost, media, sinceDate, untilDate, offset, max) {
const es = require('../../db/elasticsearch');
es.search({
diff --git a/src/web/app/common/scripts/parse-search-query.ts b/src/web/app/common/scripts/parse-search-query.ts
index 62b2cf51b1..f65e4683a6 100644
--- a/src/web/app/common/scripts/parse-search-query.ts
+++ b/src/web/app/common/scripts/parse-search-query.ts
@@ -14,10 +14,13 @@ export default function(qs: string) {
q['following'] = value == 'null' ? null : value == 'true';
break;
case 'reply':
- q['include_replies'] = value == 'true';
+ q['reply'] = value == 'null' ? null : value == 'true';
+ break;
+ case 'repost':
+ q['repost'] = value == 'null' ? null : value == 'true';
break;
case 'media':
- q['with_media'] = value == 'true';
+ q['media'] = value == 'null' ? null : value == 'true';
break;
case 'until':
case 'since':
diff --git a/src/web/docs/search.ja.pug b/src/web/docs/search.ja.pug
index 7d4d23fb6a..d46e5f4a04 100644
--- a/src/web/docs/search.ja.pug
+++ b/src/web/docs/search.ja.pug
@@ -23,13 +23,36 @@ section
td ユーザー名。投稿者を限定します。
tr
td follow
- td フォローしているユーザーのみに限定。(trueかfalse)
+ td
+ | true ... フォローしているユーザーに限定。
+ br
+ | false ... フォローしていないユーザーに限定。
+ br
+ | null ... 特に限定しない(デフォルト)
tr
td reply
- td 返信を含めるか否か。(trueかfalse)
+ td
+ | true ... 返信に限定。
+ br
+ | false ... 返信でない投稿に限定。
+ br
+ | null ... 特に限定しない(デフォルト)
+ tr
+ td repost
+ td
+ | true ... Repostに限定。
+ br
+ | false ... Repostでない投稿に限定。
+ br
+ | null ... 特に限定しない(デフォルト)
tr
td media
- td メディアが添付されているか。(trueかfalse)
+ td
+ | true ... メディアが添付されている投稿に限定。
+ br
+ | false ... メディアが添付されていない投稿に限定。
+ br
+ | null ... 特に限定しない(デフォルト)
tr
td until
td 上限の日時。(YYYY-MM-DD)
--
cgit v1.2.3-freya
From b2223c19e18ee5884ea13ec0d33f3ddb1ac9ea27 Mon Sep 17 00:00:00 2001
From: こぴなたみぽ
Date: Thu, 21 Dec 2017 07:45:45 +0900
Subject: Fix bug
---
src/api/endpoints/posts/search.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index 21e9134d38..a3c44d09ce 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -85,7 +85,7 @@ async function byNative(res, rej, me, text, userId, following, reply, repost, me
$and: []
};
- const push = q.$and.push;
+ const push = x => q.$and.push(x);
if (text) {
push({
--
cgit v1.2.3-freya
From aff76a57c0d123b992d7284faba6c5a146985246 Mon Sep 17 00:00:00 2001
From: こぴなたみぽ
Date: Thu, 21 Dec 2017 07:57:31 +0900
Subject: :v:
---
src/api/endpoints/posts/search.ts | 31 +++++++++++++++++++++---
src/web/app/common/scripts/parse-search-query.ts | 3 +++
src/web/docs/search.ja.pug | 8 ++++++
3 files changed, 39 insertions(+), 3 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index a3c44d09ce..777cd7909a 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -46,6 +46,10 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
const [media = null, mediaErr] = $(params.media).optional.nullable.boolean().$;
if (mediaErr) return rej('invalid media param');
+ // Get 'poll' parameter
+ const [poll = null, pollErr] = $(params.poll).optional.nullable.boolean().$;
+ if (pollErr) return rej('invalid poll param');
+
// Get 'since_date' parameter
const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$;
if (sinceDateErr) throw 'invalid since_date param';
@@ -76,11 +80,11 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// If Elasticsearch is available, search by it
// If not, search by MongoDB
(config.elasticsearch.enable ? byElasticsearch : byNative)
- (res, rej, me, text, user, following, reply, repost, media, sinceDate, untilDate, offset, limit);
+ (res, rej, me, text, user, following, reply, repost, media, poll, sinceDate, untilDate, offset, limit);
});
// Search by MongoDB
-async function byNative(res, rej, me, text, userId, following, reply, repost, media, sinceDate, untilDate, offset, max) {
+async function byNative(res, rej, me, text, userId, following, reply, repost, media, poll, sinceDate, untilDate, offset, max) {
const q: any = {
$and: []
};
@@ -175,6 +179,27 @@ async function byNative(res, rej, me, text, userId, following, reply, repost, me
}
}
+ if (poll != null) {
+ if (poll) {
+ push({
+ poll: {
+ $exists: true,
+ $ne: null
+ }
+ });
+ } else {
+ push({
+ $or: [{
+ poll: {
+ $exists: false
+ }
+ }, {
+ poll: null
+ }]
+ });
+ }
+ }
+
if (sinceDate) {
push({
created_at: {
@@ -207,7 +232,7 @@ async function byNative(res, rej, me, text, userId, following, reply, repost, me
}
// Search by Elasticsearch
-async function byElasticsearch(res, rej, me, text, userId, following, reply, repost, media, sinceDate, untilDate, offset, max) {
+async function byElasticsearch(res, rej, me, text, userId, following, reply, repost, media, poll, sinceDate, untilDate, offset, max) {
const es = require('../../db/elasticsearch');
es.search({
diff --git a/src/web/app/common/scripts/parse-search-query.ts b/src/web/app/common/scripts/parse-search-query.ts
index f65e4683a6..c021ee6417 100644
--- a/src/web/app/common/scripts/parse-search-query.ts
+++ b/src/web/app/common/scripts/parse-search-query.ts
@@ -22,6 +22,9 @@ export default function(qs: string) {
case 'media':
q['media'] = value == 'null' ? null : value == 'true';
break;
+ case 'poll':
+ q['poll'] = value == 'null' ? null : value == 'true';
+ break;
case 'until':
case 'since':
// YYYY-MM-DD
diff --git a/src/web/docs/search.ja.pug b/src/web/docs/search.ja.pug
index d46e5f4a04..41e443d746 100644
--- a/src/web/docs/search.ja.pug
+++ b/src/web/docs/search.ja.pug
@@ -53,6 +53,14 @@ section
| false ... メディアが添付されていない投稿に限定。
br
| null ... 特に限定しない(デフォルト)
+ tr
+ td poll
+ td
+ | true ... 投票が添付されている投稿に限定。
+ br
+ | false ... 投票が添付されていない投稿に限定。
+ br
+ | null ... 特に限定しない(デフォルト)
tr
td until
td 上限の日時。(YYYY-MM-DD)
--
cgit v1.2.3-freya
From 0dc97370a34d88c9274f5a89f1714d7ce99f7a25 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Thu, 21 Dec 2017 15:28:50 +0900
Subject: Fix bug
---
src/api/endpoints/posts/search.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index 777cd7909a..bd3bbfc12e 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -105,7 +105,7 @@ async function byNative(res, rej, me, text, userId, following, reply, repost, me
});
}
- if (following != null) {
+ if (following != null && me != null) {
const ids = await getFriends(me._id, false);
push({
user_id: following ? {
--
cgit v1.2.3-freya
From fd28d1bcc325ad22afc8584fc9fe6e9091d0524a Mon Sep 17 00:00:00 2001
From: syuilo
Date: Thu, 21 Dec 2017 15:30:15 +0900
Subject: #1026
---
src/api/endpoints/posts/search.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index bd3bbfc12e..16d54f729f 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -111,7 +111,7 @@ async function byNative(res, rej, me, text, userId, following, reply, repost, me
user_id: following ? {
$in: ids
} : {
- $nin: ids
+ $nin: ids.concat(me._id)
}
});
}
--
cgit v1.2.3-freya
From 41623f85901437631707c308e0550b9be8e7b782 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Thu, 21 Dec 2017 15:37:26 +0900
Subject: Fix bug
---
src/api/endpoints/posts/search.ts | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index 16d54f729f..ac25652a0b 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -85,7 +85,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Search by MongoDB
async function byNative(res, rej, me, text, userId, following, reply, repost, media, poll, sinceDate, untilDate, offset, max) {
- const q: any = {
+ let q: any = {
$and: []
};
@@ -216,6 +216,10 @@ async function byNative(res, rej, me, text, userId, following, reply, repost, me
});
}
+ if (q.$and.length == 0) {
+ q = {};
+ }
+
// Search posts
const posts = await Post
.find(q, {
--
cgit v1.2.3-freya
From 8fd78aebbf01755ffdecb9aa17dff1f842b194ff Mon Sep 17 00:00:00 2001
From: こぴなたみぽ
Date: Fri, 22 Dec 2017 04:50:50 +0900
Subject: wip
---
src/api/endpoints/posts/timeline.ts | 12 +++++++++++-
src/api/models/mute.ts | 3 +++
2 files changed, 14 insertions(+), 1 deletion(-)
create mode 100644 src/api/models/mute.ts
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts
index 91cba0a047..6cc7825e64 100644
--- a/src/api/endpoints/posts/timeline.ts
+++ b/src/api/endpoints/posts/timeline.ts
@@ -77,7 +77,17 @@ module.exports = async (params, user, app) => {
channel_id: {
$in: watchingChannelIds
}
- }]
+ }],
+ // mute
+ user_id: {
+ $nin: mutes
+ },
+ '_reply.user_id': {
+ $nin: mutes
+ },
+ '_repost.user_id': {
+ $nin: mutes
+ },
} as any;
if (sinceId) {
diff --git a/src/api/models/mute.ts b/src/api/models/mute.ts
new file mode 100644
index 0000000000..16018b82f7
--- /dev/null
+++ b/src/api/models/mute.ts
@@ -0,0 +1,3 @@
+import db from '../../db/mongodb';
+
+export default db.get('mute') as any; // fuck type definition
--
cgit v1.2.3-freya
From 11e05a3a3298ea072f24ece0ad7a5c8c00bb1b23 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 22 Dec 2017 05:41:21 +0900
Subject: wip
---
src/api/endpoints/posts/create.ts | 6 ++-
tools/migration/node.2017-12-22.hiseikika.js | 67 ++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
create mode 100644 tools/migration/node.2017-12-22.hiseikika.js
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index 7270efaf71..9d791538fe 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -215,7 +215,11 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
poll: poll,
text: text,
user_id: user._id,
- app_id: app ? app._id : null
+ app_id: app ? app._id : null,
+
+ // 以下非正規化データ
+ _reply: reply ? { user_id: reply.user_id } : undefined,
+ _repost: repost ? { user_id: repost.user_id } : undefined,
});
// Serialize
diff --git a/tools/migration/node.2017-12-22.hiseikika.js b/tools/migration/node.2017-12-22.hiseikika.js
new file mode 100644
index 0000000000..ff8294c8d1
--- /dev/null
+++ b/tools/migration/node.2017-12-22.hiseikika.js
@@ -0,0 +1,67 @@
+// for Node.js interpret
+
+const { default: Post } = require('../../built/api/models/post')
+const { default: zip } = require('@prezzemolo/zip')
+
+const migrate = async (post) => {
+ const x = {};
+ if (post.reply_id != null) {
+ const reply = await Post.findOne({
+ _id: post.reply_id
+ });
+ x['_reply.user_id'] = reply.user_id;
+ }
+ if (post.repost_id != null) {
+ const repost = await Post.findOne({
+ _id: post.repost_id
+ });
+ x['_repost.user_id'] = repost.user_id;
+ }
+ if (post.reply_id != null || post.repost_id != null) {
+ const result = await Post.update(post._id, {
+ $set: x,
+ });
+ return result.ok === 1;
+ } else {
+ return true;
+ }
+}
+
+async function main() {
+ const query = {
+ $or: [{
+ reply_id: {
+ $exists: true,
+ $ne: null
+ }
+ }, {
+ repost_id: {
+ $exists: true,
+ $ne: null
+ }
+ }]
+ }
+
+ const count = await Post.count(query);
+
+ const dop = Number.parseInt(process.argv[2]) || 5
+ const idop = ((count - (count % dop)) / dop) + 1
+
+ return zip(
+ 1,
+ async (time) => {
+ console.log(`${time} / ${idop}`)
+ const doc = await Post.find(query, {
+ limit: dop, skip: time * dop
+ })
+ return Promise.all(doc.map(migrate))
+ },
+ idop
+ ).then(a => {
+ const rv = []
+ a.forEach(e => rv.push(...e))
+ return rv
+ })
+}
+
+main().then(console.dir).catch(console.error)
--
cgit v1.2.3-freya
From a134aa5a81ea2c443153b3723abf662a8069e36a Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 22 Dec 2017 06:03:54 +0900
Subject: wip
---
src/api/endpoints.ts | 17 +++++++++
src/api/endpoints/mute/create.ts | 61 +++++++++++++++++++++++++++++++
src/api/endpoints/mute/delete.ts | 63 ++++++++++++++++++++++++++++++++
src/api/endpoints/mute/list.ts | 73 +++++++++++++++++++++++++++++++++++++
src/api/endpoints/posts/timeline.ts | 19 +++++++---
5 files changed, 228 insertions(+), 5 deletions(-)
create mode 100644 src/api/endpoints/mute/create.ts
create mode 100644 src/api/endpoints/mute/delete.ts
create mode 100644 src/api/endpoints/mute/list.ts
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts
index 1138df193b..e846381578 100644
--- a/src/api/endpoints.ts
+++ b/src/api/endpoints.ts
@@ -222,6 +222,23 @@ const endpoints: Endpoint[] = [
withCredential: true,
kind: 'notification-read'
},
+
+ {
+ name: 'mute/create',
+ withCredential: true,
+ kind: 'account/write'
+ },
+ {
+ name: 'mute/delete',
+ withCredential: true,
+ kind: 'account/write'
+ },
+ {
+ name: 'mute/list',
+ withCredential: true,
+ kind: 'account/read'
+ },
+
{
name: 'notifications/get_unread_count',
withCredential: true,
diff --git a/src/api/endpoints/mute/create.ts b/src/api/endpoints/mute/create.ts
new file mode 100644
index 0000000000..f44854ab52
--- /dev/null
+++ b/src/api/endpoints/mute/create.ts
@@ -0,0 +1,61 @@
+/**
+ * Module dependencies
+ */
+import $ from 'cafy';
+import User from '../../models/user';
+import Mute from '../../models/mute';
+
+/**
+ * Mute a user
+ *
+ * @param {any} params
+ * @param {any} user
+ * @return {Promise}
+ */
+module.exports = (params, user) => new Promise(async (res, rej) => {
+ const muter = user;
+
+ // Get 'user_id' parameter
+ const [userId, userIdErr] = $(params.user_id).id().$;
+ if (userIdErr) return rej('invalid user_id param');
+
+ // 自分自身
+ if (user._id.equals(userId)) {
+ return rej('mutee is yourself');
+ }
+
+ // Get mutee
+ const mutee = await User.findOne({
+ _id: userId
+ }, {
+ fields: {
+ data: false,
+ profile: false
+ }
+ });
+
+ if (mutee === null) {
+ return rej('user not found');
+ }
+
+ // Check if already muting
+ const exist = await Mute.findOne({
+ muter_id: muter._id,
+ mutee_id: mutee._id,
+ deleted_at: { $exists: false }
+ });
+
+ if (exist !== null) {
+ return rej('already muting');
+ }
+
+ // Create mute
+ await Mute.insert({
+ created_at: new Date(),
+ muter_id: muter._id,
+ mutee_id: mutee._id,
+ });
+
+ // Send response
+ res();
+});
diff --git a/src/api/endpoints/mute/delete.ts b/src/api/endpoints/mute/delete.ts
new file mode 100644
index 0000000000..d6bff3353a
--- /dev/null
+++ b/src/api/endpoints/mute/delete.ts
@@ -0,0 +1,63 @@
+/**
+ * Module dependencies
+ */
+import $ from 'cafy';
+import User from '../../models/user';
+import Mute from '../../models/mute';
+
+/**
+ * Unmute a user
+ *
+ * @param {any} params
+ * @param {any} user
+ * @return {Promise}
+ */
+module.exports = (params, user) => new Promise(async (res, rej) => {
+ const muter = user;
+
+ // Get 'user_id' parameter
+ const [userId, userIdErr] = $(params.user_id).id().$;
+ if (userIdErr) return rej('invalid user_id param');
+
+ // Check if the mutee is yourself
+ if (user._id.equals(userId)) {
+ return rej('mutee is yourself');
+ }
+
+ // Get mutee
+ const mutee = await User.findOne({
+ _id: userId
+ }, {
+ fields: {
+ data: false,
+ profile: false
+ }
+ });
+
+ if (mutee === null) {
+ return rej('user not found');
+ }
+
+ // Check not muting
+ const exist = await Mute.findOne({
+ muter_id: muter._id,
+ mutee_id: mutee._id,
+ deleted_at: { $exists: false }
+ });
+
+ if (exist === null) {
+ return rej('already not muting');
+ }
+
+ // Delete mute
+ await Mute.update({
+ _id: exist._id
+ }, {
+ $set: {
+ deleted_at: new Date()
+ }
+ });
+
+ // Send response
+ res();
+});
diff --git a/src/api/endpoints/mute/list.ts b/src/api/endpoints/mute/list.ts
new file mode 100644
index 0000000000..740e19f0bb
--- /dev/null
+++ b/src/api/endpoints/mute/list.ts
@@ -0,0 +1,73 @@
+/**
+ * Module dependencies
+ */
+import $ from 'cafy';
+import Mute from '../../models/mute';
+import serialize from '../../serializers/user';
+import getFriends from '../../common/get-friends';
+
+/**
+ * Get muted users of a user
+ *
+ * @param {any} params
+ * @param {any} me
+ * @return {Promise}
+ */
+module.exports = (params, me) => new Promise(async (res, rej) => {
+ // Get 'iknow' parameter
+ const [iknow = false, iknowErr] = $(params.iknow).optional.boolean().$;
+ if (iknowErr) return rej('invalid iknow param');
+
+ // Get 'limit' parameter
+ const [limit = 30, limitErr] = $(params.limit).optional.number().range(1, 100).$;
+ if (limitErr) return rej('invalid limit param');
+
+ // Get 'cursor' parameter
+ const [cursor = null, cursorErr] = $(params.cursor).optional.id().$;
+ if (cursorErr) return rej('invalid cursor param');
+
+ // Construct query
+ const query = {
+ muter_id: me._id,
+ deleted_at: { $exists: false }
+ } as any;
+
+ if (iknow) {
+ // Get my friends
+ const myFriends = await getFriends(me._id);
+
+ query.mutee_id = {
+ $in: myFriends
+ };
+ }
+
+ // カーソルが指定されている場合
+ if (cursor) {
+ query._id = {
+ $lt: cursor
+ };
+ }
+
+ // Get mutes
+ const mutes = await Mute
+ .find(query, {
+ limit: limit + 1,
+ sort: { _id: -1 }
+ });
+
+ // 「次のページ」があるかどうか
+ const inStock = mutes.length === limit + 1;
+ if (inStock) {
+ mutes.pop();
+ }
+
+ // Serialize
+ const users = await Promise.all(mutes.map(async m =>
+ await serialize(m.mutee_id, me, { detail: true })));
+
+ // Response
+ res({
+ users: users,
+ next: inStock ? mutes[mutes.length - 1]._id : null,
+ });
+});
diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts
index 6cc7825e64..da7ffd0c14 100644
--- a/src/api/endpoints/posts/timeline.ts
+++ b/src/api/endpoints/posts/timeline.ts
@@ -4,6 +4,7 @@
import $ from 'cafy';
import rap from '@prezzemolo/rap';
import Post from '../../models/post';
+import Mute from '../../models/mute';
import ChannelWatching from '../../models/channel-watching';
import getFriends from '../../common/get-friends';
import serialize from '../../serializers/post';
@@ -42,15 +43,23 @@ module.exports = async (params, user, app) => {
throw 'only one of since_id, until_id, since_date, until_date can be specified';
}
- const { followingIds, watchingChannelIds } = await rap({
+ const { followingIds, watchingChannelIds, mutedUserIds } = await rap({
// ID list of the user itself and other users who the user follows
followingIds: getFriends(user._id),
+
// Watchしているチャンネルを取得
watchingChannelIds: ChannelWatching.find({
user_id: user._id,
// 削除されたドキュメントは除く
deleted_at: { $exists: false }
- }).then(watches => watches.map(w => w.channel_id))
+ }).then(watches => watches.map(w => w.channel_id)),
+
+ // ミュートしているユーザーを取得
+ mutedUserIds: Mute.find({
+ muter_id: user._id,
+ // 削除されたドキュメントは除く
+ deleted_at: { $exists: false }
+ }).then(ms => ms.map(m => m.mutee_id))
});
//#region Construct query
@@ -80,13 +89,13 @@ module.exports = async (params, user, app) => {
}],
// mute
user_id: {
- $nin: mutes
+ $nin: mutedUserIds
},
'_reply.user_id': {
- $nin: mutes
+ $nin: mutedUserIds
},
'_repost.user_id': {
- $nin: mutes
+ $nin: mutedUserIds
},
} as any;
--
cgit v1.2.3-freya
From 26b40d8886ccf87eed5cce2868b14994c29752b9 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 22 Dec 2017 06:38:48 +0900
Subject: wip
---
src/api/endpoints/posts/search.ts | 89 +++++++++++++++++++++++++++++++++++++--
src/web/docs/search.ja.pug | 16 +++++++
2 files changed, 102 insertions(+), 3 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index ac25652a0b..f722231d4c 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -6,6 +6,7 @@ import $ from 'cafy';
const escapeRegexp = require('escape-regexp');
import Post from '../../models/post';
import User from '../../models/user';
+import Mute from '../../models/mute';
import getFriends from '../../common/get-friends';
import serialize from '../../serializers/post';
import config from '../../../conf';
@@ -34,6 +35,10 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
const [following = null, followingErr] = $(params.following).optional.nullable.boolean().$;
if (followingErr) return rej('invalid following param');
+ // Get 'mute' parameter
+ const [mute = 'mute_all', muteErr] = $(params.mute).optional.string().$;
+ if (muteErr) return rej('invalid mute param');
+
// Get 'reply' parameter
const [reply = null, replyErr] = $(params.reply).optional.nullable.boolean().$;
if (replyErr) return rej('invalid reply param');
@@ -80,11 +85,11 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// If Elasticsearch is available, search by it
// If not, search by MongoDB
(config.elasticsearch.enable ? byElasticsearch : byNative)
- (res, rej, me, text, user, following, reply, repost, media, poll, sinceDate, untilDate, offset, limit);
+ (res, rej, me, text, user, following, mute, reply, repost, media, poll, sinceDate, untilDate, offset, limit);
});
// Search by MongoDB
-async function byNative(res, rej, me, text, userId, following, reply, repost, media, poll, sinceDate, untilDate, offset, max) {
+async function byNative(res, rej, me, text, userId, following, mute, reply, repost, media, poll, sinceDate, untilDate, offset, max) {
let q: any = {
$and: []
};
@@ -116,6 +121,84 @@ async function byNative(res, rej, me, text, userId, following, reply, repost, me
});
}
+ if (me != null) {
+ const mutes = await Mute.find({
+ muter_id: me._id,
+ deleted_at: { $exists: false }
+ });
+ const mutedUserIds = mutes.map(m => m.mutee_id);
+
+ switch (mute) {
+ case 'mute_all':
+ push({
+ user_id: {
+ $nin: mutedUserIds
+ },
+ '_reply.user_id': {
+ $nin: mutedUserIds
+ },
+ '_repost.user_id': {
+ $nin: mutedUserIds
+ }
+ });
+ break;
+ case 'mute_related':
+ push({
+ '_reply.user_id': {
+ $nin: mutedUserIds
+ },
+ '_repost.user_id': {
+ $nin: mutedUserIds
+ }
+ });
+ break;
+ case 'mute_direct':
+ push({
+ user_id: {
+ $nin: mutedUserIds
+ }
+ });
+ break;
+ case 'direct_only':
+ push({
+ user_id: {
+ $in: mutedUserIds
+ }
+ });
+ break;
+ case 'related_only':
+ push({
+ $or: [{
+ '_reply.user_id': {
+ $in: mutedUserIds
+ }
+ }, {
+ '_repost.user_id': {
+ $in: mutedUserIds
+ }
+ }]
+ });
+ break;
+ case 'all_only':
+ push({
+ $or: [{
+ user_id: {
+ $in: mutedUserIds
+ }
+ }, {
+ '_reply.user_id': {
+ $in: mutedUserIds
+ }
+ }, {
+ '_repost.user_id': {
+ $in: mutedUserIds
+ }
+ }]
+ });
+ break;
+ }
+ }
+
if (reply != null) {
if (reply) {
push({
@@ -236,7 +319,7 @@ async function byNative(res, rej, me, text, userId, following, reply, repost, me
}
// Search by Elasticsearch
-async function byElasticsearch(res, rej, me, text, userId, following, reply, repost, media, poll, sinceDate, untilDate, offset, max) {
+async function byElasticsearch(res, rej, me, text, userId, following, mute, reply, repost, media, poll, sinceDate, untilDate, offset, max) {
const es = require('../../db/elasticsearch');
es.search({
diff --git a/src/web/docs/search.ja.pug b/src/web/docs/search.ja.pug
index 41e443d746..552f95c60f 100644
--- a/src/web/docs/search.ja.pug
+++ b/src/web/docs/search.ja.pug
@@ -29,6 +29,22 @@ section
| false ... フォローしていないユーザーに限定。
br
| null ... 特に限定しない(デフォルト)
+ tr
+ td mute
+ td
+ | mute_all ... ミュートしているユーザーの投稿とその投稿に対する返信やRepostを除外する(デフォルト)
+ br
+ | mute_related ... ミュートしているユーザーの投稿に対する返信やRepostだけ除外する
+ br
+ | mute_direct ... ミュートしているユーザーの投稿だけ除外する
+ br
+ | disabled ... ミュートしているユーザーの投稿とその投稿に対する返信やRepostも含める
+ br
+ | direct_only ... ミュートしているユーザーの投稿だけに限定
+ br
+ | related_only ... ミュートしているユーザーの投稿に対する返信やRepostだけに限定
+ br
+ | all_only ... ミュートしているユーザーの投稿とその投稿に対する返信やRepostに限定
tr
td reply
td
--
cgit v1.2.3-freya
From 6575a6de5bbcab9a88448e4366feb77f1845a580 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 22 Dec 2017 07:26:23 +0900
Subject: wip
---
src/api/endpoints/i/notifications.ts | 23 ++++++++++++++++++-----
src/api/stream/home.ts | 33 +++++++++++++++++++++++++++++++--
2 files changed, 49 insertions(+), 7 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/i/notifications.ts b/src/api/endpoints/i/notifications.ts
index 48254e5e67..fb9be7f61b 100644
--- a/src/api/endpoints/i/notifications.ts
+++ b/src/api/endpoints/i/notifications.ts
@@ -3,6 +3,7 @@
*/
import $ from 'cafy';
import Notification from '../../models/notification';
+import Mute from '../../models/mute';
import serialize from '../../serializers/notification';
import getFriends from '../../common/get-friends';
import read from '../../common/read-notification';
@@ -45,8 +46,18 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
return rej('cannot set since_id and until_id');
}
+ const mute = await Mute.find({
+ muter_id: user._id,
+ deleted_at: { $exists: false }
+ });
+
const query = {
- notifiee_id: user._id
+ notifiee_id: user._id,
+ $and: [{
+ notifier_id: {
+ $nin: mute.map(m => m.mutee_id)
+ }
+ }]
} as any;
const sort = {
@@ -54,12 +65,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
};
if (following) {
- // ID list of the user $self and other users who the user follows
+ // ID list of the user itself and other users who the user follows
const followingIds = await getFriends(user._id);
- query.notifier_id = {
- $in: followingIds
- };
+ query.$and.push({
+ notifier_id: {
+ $in: followingIds
+ }
+ });
}
if (type) {
diff --git a/src/api/stream/home.ts b/src/api/stream/home.ts
index 7c8f3bfec8..7dcdb5ed73 100644
--- a/src/api/stream/home.ts
+++ b/src/api/stream/home.ts
@@ -3,19 +3,48 @@ import * as redis from 'redis';
import * as debug from 'debug';
import User from '../models/user';
+import Mute from '../models/mute';
import serializePost from '../serializers/post';
import readNotification from '../common/read-notification';
const log = debug('misskey');
-export default function homeStream(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient, user: any): void {
+export default async function(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient, user: any) {
// Subscribe Home stream channel
subscriber.subscribe(`misskey:user-stream:${user._id}`);
+ const mute = await Mute.find({
+ muter_id: user._id,
+ deleted_at: { $exists: false }
+ });
+ const mutedUserIds = mute.map(m => m.mutee_id.toString());
+
subscriber.on('message', async (channel, data) => {
switch (channel.split(':')[1]) {
case 'user-stream':
- connection.send(data);
+ try {
+ const x = JSON.parse(data);
+
+ if (x.type == 'post') {
+ if (mutedUserIds.indexOf(x.body.user_id) != -1) {
+ return;
+ }
+ if (x.body.reply != null && mutedUserIds.indexOf(x.body.reply.user_id) != -1) {
+ return;
+ }
+ if (x.body.repost != null && mutedUserIds.indexOf(x.body.repost.user_id) != -1) {
+ return;
+ }
+ } else if (x.type == 'notification') {
+ if (mutedUserIds.indexOf(x.body.user_id) != -1) {
+ return;
+ }
+ }
+
+ connection.send(data);
+ } catch (e) {
+ connection.send(data);
+ }
break;
case 'post-stream':
const postId = channel.split(':')[2];
--
cgit v1.2.3-freya
From 8b515b4dae8c272257ee8892713fe954f0ff9c4a Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 22 Dec 2017 07:38:57 +0900
Subject: wip
---
src/api/common/notify.ts | 12 ++++++++++++
src/api/endpoints/notifications/get_unread_count.ts | 10 ++++++++++
2 files changed, 22 insertions(+)
(limited to 'src/api/endpoints')
diff --git a/src/api/common/notify.ts b/src/api/common/notify.ts
index 4b3e6a5d54..f06622f912 100644
--- a/src/api/common/notify.ts
+++ b/src/api/common/notify.ts
@@ -1,5 +1,6 @@
import * as mongo from 'mongodb';
import Notification from '../models/notification';
+import Mute from '../models/mute';
import event from '../event';
import serialize from '../serializers/notification';
@@ -32,6 +33,17 @@ export default (
setTimeout(async () => {
const fresh = await Notification.findOne({ _id: notification._id }, { is_read: true });
if (!fresh.is_read) {
+ //#region ただしミュートしているユーザーからの通知なら無視
+ const mute = await Mute.find({
+ muter_id: notifiee,
+ deleted_at: { $exists: false }
+ });
+ const mutedUserIds = mute.map(m => m.mutee_id.toString());
+ if (mutedUserIds.indexOf(notifier.toHexString()) != -1) {
+ return;
+ }
+ //#endregion
+
event(notifiee, 'unread_notification', await serialize(notification));
}
}, 3000);
diff --git a/src/api/endpoints/notifications/get_unread_count.ts b/src/api/endpoints/notifications/get_unread_count.ts
index 9514e78713..845d6b29ce 100644
--- a/src/api/endpoints/notifications/get_unread_count.ts
+++ b/src/api/endpoints/notifications/get_unread_count.ts
@@ -2,6 +2,7 @@
* Module dependencies
*/
import Notification from '../../models/notification';
+import Mute from '../../models/mute';
/**
* Get count of unread notifications
@@ -11,9 +12,18 @@ import Notification from '../../models/notification';
* @return {Promise}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
+ const mute = await Mute.find({
+ muter_id: user._id,
+ deleted_at: { $exists: false }
+ });
+ const mutedUserIds = mute.map(m => m.mutee_id);
+
const count = await Notification
.count({
notifiee_id: user._id,
+ notifier_id: {
+ $nin: mutedUserIds
+ },
is_read: false
});
--
cgit v1.2.3-freya
From f93bc3a8ec7eae63330193bc87c5b1437bf874ed Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 22 Dec 2017 07:43:56 +0900
Subject: wip
---
src/api/common/notify.ts | 2 +-
src/api/endpoints/posts/create.ts | 14 +++++++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/common/notify.ts b/src/api/common/notify.ts
index f06622f912..2b79416a30 100644
--- a/src/api/common/notify.ts
+++ b/src/api/common/notify.ts
@@ -39,7 +39,7 @@ export default (
deleted_at: { $exists: false }
});
const mutedUserIds = mute.map(m => m.mutee_id.toString());
- if (mutedUserIds.indexOf(notifier.toHexString()) != -1) {
+ if (mutedUserIds.indexOf(notifier.toString()) != -1) {
return;
}
//#endregion
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index 9d791538fe..a1d05c67c6 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -8,6 +8,7 @@ import { default as Post, IPost, isValidText } from '../../models/post';
import { default as User, IUser } from '../../models/user';
import { default as Channel, IChannel } from '../../models/channel';
import Following from '../../models/following';
+import Mute from '../../models/mute';
import DriveFile from '../../models/drive-file';
import Watching from '../../models/post-watching';
import ChannelWatching from '../../models/channel-watching';
@@ -240,7 +241,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
const mentions = [];
- function addMention(mentionee, reason) {
+ async function addMention(mentionee, reason) {
// Reject if already added
if (mentions.some(x => x.equals(mentionee))) return;
@@ -249,8 +250,15 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// Publish event
if (!user._id.equals(mentionee)) {
- event(mentionee, reason, postObj);
- pushSw(mentionee, reason, postObj);
+ const mentioneeMutes = await Mute.find({
+ muter_id: mentionee,
+ deleted_at: { $exists: false }
+ });
+ const mentioneesMutedUserIds = mentioneeMutes.map(m => m.mutee_id.toString());
+ if (mentioneesMutedUserIds.indexOf(user._id.toString()) == -1) {
+ event(mentionee, reason, postObj);
+ pushSw(mentionee, reason, postObj);
+ }
}
}
--
cgit v1.2.3-freya
From e21ab77dd5fc007cc92fffd4362890fbde89db56 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 22 Dec 2017 14:21:40 +0900
Subject: wip
---
src/api/endpoints/messaging/history.ts | 11 ++++++++++-
src/api/endpoints/messaging/messages/create.ts | 12 ++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/messaging/history.ts b/src/api/endpoints/messaging/history.ts
index 5f7c9276dd..f14740dff5 100644
--- a/src/api/endpoints/messaging/history.ts
+++ b/src/api/endpoints/messaging/history.ts
@@ -3,6 +3,7 @@
*/
import $ from 'cafy';
import History from '../../models/messaging-history';
+import Mute from '../../models/mute';
import serialize from '../../serializers/messaging-message';
/**
@@ -17,10 +18,18 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param');
+ const mute = await Mute.find({
+ muter_id: user._id,
+ deleted_at: { $exists: false }
+ });
+
// Get history
const history = await History
.find({
- user_id: user._id
+ user_id: user._id,
+ partner: {
+ $nin: mute.map(m => m.mutee_id)
+ }
}, {
limit: limit,
sort: {
diff --git a/src/api/endpoints/messaging/messages/create.ts b/src/api/endpoints/messaging/messages/create.ts
index 3c7689f967..f69f2e0fb2 100644
--- a/src/api/endpoints/messaging/messages/create.ts
+++ b/src/api/endpoints/messaging/messages/create.ts
@@ -6,6 +6,7 @@ import Message from '../../../models/messaging-message';
import { isValidText } from '../../../models/messaging-message';
import History from '../../../models/messaging-history';
import User from '../../../models/user';
+import Mute from '../../../models/mute';
import DriveFile from '../../../models/drive-file';
import serialize from '../../../serializers/messaging-message';
import publishUserStream from '../../../event';
@@ -97,6 +98,17 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
setTimeout(async () => {
const freshMessage = await Message.findOne({ _id: message._id }, { is_read: true });
if (!freshMessage.is_read) {
+ //#region ただしミュートしているユーザーからの通知なら無視
+ const mute = await Mute.find({
+ muter_id: recipient._id,
+ deleted_at: { $exists: false }
+ });
+ const mutedUserIds = mute.map(m => m.mutee_id.toString());
+ if (mutedUserIds.indexOf(user._id.toString()) != -1) {
+ return;
+ }
+ //#endregion
+
publishUserStream(message.recipient_id, 'unread_messaging_message', messageObj);
pushSw(message.recipient_id, 'unread_messaging_message', messageObj);
}
--
cgit v1.2.3-freya
From ef5a963b32afd5842894a2a61fa4c2d078853224 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 22 Dec 2017 14:35:47 +0900
Subject: wip
---
src/api/endpoints/messaging/unread.ts | 10 ++++++++++
1 file changed, 10 insertions(+)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/messaging/unread.ts b/src/api/endpoints/messaging/unread.ts
index 40bc83fe1c..c4326e1d22 100644
--- a/src/api/endpoints/messaging/unread.ts
+++ b/src/api/endpoints/messaging/unread.ts
@@ -2,6 +2,7 @@
* Module dependencies
*/
import Message from '../../models/messaging-message';
+import Mute from '../../models/mute';
/**
* Get count of unread messages
@@ -11,8 +12,17 @@ import Message from '../../models/messaging-message';
* @return {Promise}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
+ const mute = await Mute.find({
+ muter_id: user._id,
+ deleted_at: { $exists: false }
+ });
+ const mutedUserIds = mute.map(m => m.mutee_id);
+
const count = await Message
.count({
+ user_id: {
+ $nin: mutedUserIds
+ },
recipient_id: user._id,
is_read: false
});
--
cgit v1.2.3-freya
From 09af75a92d94cc59e41e0401da9af59a1a90e29f Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 22 Dec 2017 16:22:33 +0900
Subject: Update create.ts
---
src/api/endpoints/messaging/messages/create.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/messaging/messages/create.ts b/src/api/endpoints/messaging/messages/create.ts
index f69f2e0fb2..4e9d10197c 100644
--- a/src/api/endpoints/messaging/messages/create.ts
+++ b/src/api/endpoints/messaging/messages/create.ts
@@ -98,7 +98,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
setTimeout(async () => {
const freshMessage = await Message.findOne({ _id: message._id }, { is_read: true });
if (!freshMessage.is_read) {
- //#region ただしミュートしているユーザーからの通知なら無視
+ //#region ただしミュートされているなら発行しない
const mute = await Mute.find({
muter_id: recipient._id,
deleted_at: { $exists: false }
--
cgit v1.2.3-freya
From 8376b10b3b93d3c6cc50d69a6f0ae3ceb8c96c74 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Sat, 23 Dec 2017 04:21:15 +0900
Subject: #1035
---
src/api/endpoints/posts/search.ts | 4 +++-
src/web/docs/search.ja.pug | 6 ++++++
2 files changed, 9 insertions(+), 1 deletion(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index f722231d4c..4697e6ed0f 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -99,7 +99,9 @@ async function byNative(res, rej, me, text, userId, following, mute, reply, repo
if (text) {
push({
$and: text.split(' ').map(x => ({
- text: new RegExp(escapeRegexp(x))
+ text: x[0] == '-' ? {
+ $ne: new RegExp(escapeRegexp(x))
+ } : new RegExp(escapeRegexp(x))
}))
});
}
diff --git a/src/web/docs/search.ja.pug b/src/web/docs/search.ja.pug
index e94990205b..5baac9d400 100644
--- a/src/web/docs/search.ja.pug
+++ b/src/web/docs/search.ja.pug
@@ -5,6 +5,12 @@ p
| キーワードを半角スペースで区切ると、and検索になります。
| 例えば、「git コミット」と検索すると、「gitで編集したファイルの特定の行だけコミットする方法がわからない」などがマッチします。
+section
+ h2 キーワードの除外
+ p キーワードの前に「-」(ハイフン)をプリフィクスすると、そのキーワードを含まない投稿に限定します。
+ p 例えば、「gitというキーワードを含むが、コミットというキーワードは含まない投稿」を検索したい場合、クエリは以下のようになります:
+ code git -コミット
+
section
h2 オプション
p
--
cgit v1.2.3-freya
From 67c269ddf54d43b68c06b8fb2726f72d87600c11 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Sat, 23 Dec 2017 04:21:48 +0900
Subject: oops
---
src/api/endpoints/posts/search.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index 4697e6ed0f..33ef2a0a05 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -100,7 +100,7 @@ async function byNative(res, rej, me, text, userId, following, mute, reply, repo
push({
$and: text.split(' ').map(x => ({
text: x[0] == '-' ? {
- $ne: new RegExp(escapeRegexp(x))
+ $ne: new RegExp(escapeRegexp(x.substr(1)))
} : new RegExp(escapeRegexp(x))
}))
});
--
cgit v1.2.3-freya
From 020ce794af9493d3a037bc4cd942c6f0fac75330 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Sat, 23 Dec 2017 04:26:37 +0900
Subject: oops
---
src/api/endpoints/posts/search.ts | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index 33ef2a0a05..6cea5bdf53 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -99,8 +99,9 @@ async function byNative(res, rej, me, text, userId, following, mute, reply, repo
if (text) {
push({
$and: text.split(' ').map(x => ({
+ // キーワードが-で始まる場合そのキーワードを除外する
text: x[0] == '-' ? {
- $ne: new RegExp(escapeRegexp(x.substr(1)))
+ $not: new RegExp(escapeRegexp(x.substr(1)))
} : new RegExp(escapeRegexp(x))
}))
});
--
cgit v1.2.3-freya
From 7cf4aa9f110cebf1bf3017471b8e96d2522ad462 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Sat, 23 Dec 2017 04:38:56 +0900
Subject: #1034
---
src/api/endpoints/posts/search.ts | 24 ++++++++++++++++--------
src/web/docs/search.ja.pug | 5 +++++
2 files changed, 21 insertions(+), 8 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index 6cea5bdf53..26675989dd 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -97,14 +97,22 @@ async function byNative(res, rej, me, text, userId, following, mute, reply, repo
const push = x => q.$and.push(x);
if (text) {
- push({
- $and: text.split(' ').map(x => ({
- // キーワードが-で始まる場合そのキーワードを除外する
- text: x[0] == '-' ? {
- $not: new RegExp(escapeRegexp(x.substr(1)))
- } : new RegExp(escapeRegexp(x))
- }))
- });
+ // 完全一致検索
+ if (/"""(.+?)"""/.test(text)) {
+ const x = text.match(/"""(.+?)"""/)[1];
+ push({
+ text: x
+ });
+ } else {
+ push({
+ $and: text.split(' ').map(x => ({
+ // キーワードが-で始まる場合そのキーワードを除外する
+ text: x[0] == '-' ? {
+ $not: new RegExp(escapeRegexp(x.substr(1)))
+ } : new RegExp(escapeRegexp(x))
+ }))
+ });
+ }
}
if (userId) {
diff --git a/src/web/docs/search.ja.pug b/src/web/docs/search.ja.pug
index 09173a3503..9e64789488 100644
--- a/src/web/docs/search.ja.pug
+++ b/src/web/docs/search.ja.pug
@@ -11,6 +11,11 @@ section
p 例えば、「gitというキーワードを含むが、コミットというキーワードは含まない投稿」を検索したい場合、クエリは以下のようになります:
code git -コミット
+section
+ h2 完全一致
+ p テキストを「"""」で囲むと、そのテキストと完全に一致する投稿を検索します。
+ p 例えば、「"""にゃーん"""」と検索すると、「にゃーん」という投稿のみがヒットし、「にゃーん…」という投稿はヒットしません。
+
section
h2 オプション
p
--
cgit v1.2.3-freya
From f0818edd6e1d566a3d7e2b5495eeb389d728f564 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Sat, 23 Dec 2017 07:21:52 +0900
Subject: #1037 #1038
---
src/api/endpoints/posts/search.ts | 136 ++++++++---------------
src/web/app/common/scripts/parse-search-query.ts | 5 +-
src/web/docs/search.ja.pug | 19 +++-
3 files changed, 71 insertions(+), 89 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index 26675989dd..31c9a8d3c8 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -1,7 +1,6 @@
/**
* Module dependencies
*/
-import * as mongo from 'mongodb';
import $ from 'cafy';
const escapeRegexp = require('escape-regexp');
import Post from '../../models/post';
@@ -9,7 +8,6 @@ import User from '../../models/user';
import Mute from '../../models/mute';
import getFriends from '../../common/get-friends';
import serialize from '../../serializers/post';
-import config from '../../../conf';
/**
* Search a post
@@ -23,13 +21,21 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
const [text, textError] = $(params.text).optional.string().$;
if (textError) return rej('invalid text param');
- // Get 'user_id' parameter
- const [userId, userIdErr] = $(params.user_id).optional.id().$;
- if (userIdErr) return rej('invalid user_id param');
+ // Get 'include_user_ids' parameter
+ const [includeUserIds = [], includeUserIdsErr] = $(params.include_user_ids).optional.array('id').$;
+ if (includeUserIdsErr) return rej('invalid include_user_ids param');
- // Get 'username' parameter
- const [username, usernameErr] = $(params.username).optional.string().$;
- if (usernameErr) return rej('invalid username param');
+ // Get 'exclude_user_ids' parameter
+ const [excludeUserIds = [], excludeUserIdsErr] = $(params.exclude_user_ids).optional.array('id').$;
+ if (excludeUserIdsErr) return rej('invalid exclude_user_ids param');
+
+ // Get 'include_user_usernames' parameter
+ const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.include_user_usernames).optional.array('string').$;
+ if (includeUserUsernamesErr) return rej('invalid include_user_usernames param');
+
+ // Get 'exclude_user_usernames' parameter
+ const [excludeUserUsernames = [], excludeUserUsernamesErr] = $(params.exclude_user_usernames).optional.array('string').$;
+ if (excludeUserUsernamesErr) return rej('invalid exclude_user_usernames param');
// Get 'following' parameter
const [following = null, followingErr] = $(params.following).optional.nullable.boolean().$;
@@ -71,25 +77,36 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 30).$;
if (limitErr) return rej('invalid limit param');
- let user = userId;
+ let includeUsers = includeUserIds;
+ if (includeUserUsernames != null) {
+ const ids = (await Promise.all(includeUserUsernames.map(async (username) => {
+ const _user = await User.findOne({
+ username_lower: username.toLowerCase()
+ });
+ return _user ? _user._id : null;
+ }))).filter(id => id != null);
+ includeUsers = includeUsers.concat(ids);
+ }
- if (user == null && username != null) {
- const _user = await User.findOne({
- username_lower: username.toLowerCase()
- });
- if (_user) {
- user = _user._id;
- }
+ let excludeUsers = excludeUserIds;
+ if (excludeUserUsernames != null) {
+ const ids = (await Promise.all(excludeUserUsernames.map(async (username) => {
+ const _user = await User.findOne({
+ username_lower: username.toLowerCase()
+ });
+ return _user ? _user._id : null;
+ }))).filter(id => id != null);
+ excludeUsers = excludeUsers.concat(ids);
}
- // If Elasticsearch is available, search by it
- // If not, search by MongoDB
- (config.elasticsearch.enable ? byElasticsearch : byNative)
- (res, rej, me, text, user, following, mute, reply, repost, media, poll, sinceDate, untilDate, offset, limit);
+ search(res, rej, me, text, includeUsers, excludeUsers, following,
+ mute, reply, repost, media, poll, sinceDate, untilDate, offset, limit);
});
-// Search by MongoDB
-async function byNative(res, rej, me, text, userId, following, mute, reply, repost, media, poll, sinceDate, untilDate, offset, max) {
+async function search(
+ res, rej, me, text, includeUserIds, excludeUserIds, following,
+ mute, reply, repost, media, poll, sinceDate, untilDate, offset, max) {
+
let q: any = {
$and: []
};
@@ -115,9 +132,17 @@ async function byNative(res, rej, me, text, userId, following, mute, reply, repo
}
}
- if (userId) {
+ if (includeUserIds && includeUserIds.length != 0) {
push({
- user_id: userId
+ user_id: {
+ $in: includeUserIds
+ }
+ });
+ } else if (excludeUserIds && excludeUserIds.length != 0) {
+ push({
+ user_id: {
+ $nin: excludeUserIds
+ }
});
}
@@ -328,66 +353,3 @@ async function byNative(res, rej, me, text, userId, following, mute, reply, repo
res(await Promise.all(posts.map(async post =>
await serialize(post, me))));
}
-
-// Search by Elasticsearch
-async function byElasticsearch(res, rej, me, text, userId, following, mute, reply, repost, media, poll, sinceDate, untilDate, offset, max) {
- const es = require('../../db/elasticsearch');
-
- es.search({
- index: 'misskey',
- type: 'post',
- body: {
- size: max,
- from: offset,
- query: {
- simple_query_string: {
- fields: ['text'],
- query: text,
- default_operator: 'and'
- }
- },
- sort: [
- { _doc: 'desc' }
- ],
- highlight: {
- pre_tags: [''],
- post_tags: [''],
- encoder: 'html',
- fields: {
- text: {}
- }
- }
- }
- }, async (error, response) => {
- if (error) {
- console.error(error);
- return res(500);
- }
-
- if (response.hits.total === 0) {
- return res([]);
- }
-
- const hits = response.hits.hits.map(hit => new mongo.ObjectID(hit._id));
-
- // Fetch found posts
- const posts = await Post
- .find({
- _id: {
- $in: hits
- }
- }, {
- sort: {
- _id: -1
- }
- });
-
- posts.map(post => {
- post._highlight = response.hits.hits.filter(hit => post._id.equals(hit._id))[0].highlight.text[0];
- });
-
- // Serialize
- res(await Promise.all(posts.map(async post =>
- await serialize(post, me))));
- });
-}
diff --git a/src/web/app/common/scripts/parse-search-query.ts b/src/web/app/common/scripts/parse-search-query.ts
index c021ee6417..512791ecb0 100644
--- a/src/web/app/common/scripts/parse-search-query.ts
+++ b/src/web/app/common/scripts/parse-search-query.ts
@@ -8,7 +8,10 @@ export default function(qs: string) {
const [key, value] = x.split(':');
switch (key) {
case 'user':
- q['username'] = value;
+ q['include_user_usernames'] = value.split(',');
+ break;
+ case 'exclude_user':
+ q['exclude_user_usernames'] = value.split(',');
break;
case 'follow':
q['following'] = value == 'null' ? null : value == 'true';
diff --git a/src/web/docs/search.ja.pug b/src/web/docs/search.ja.pug
index 9e64789488..f33091ee6b 100644
--- a/src/web/docs/search.ja.pug
+++ b/src/web/docs/search.ja.pug
@@ -31,7 +31,24 @@ section
tbody
tr
td user
- td ユーザー名。投稿者を限定します。
+ td
+ | 指定されたユーザー名のユーザーの投稿に限定します。
+ | 「,」(カンマ)で区切って、複数ユーザーを指定することもできます。
+ br
+ | 例えば、
+ code user:himawari,sakurako
+ | と検索すると「@himawariまたは@sakurakoの投稿」だけに限定します。
+ | (つまりユーザーのホワイトリストです)
+ tr
+ td exclude_user
+ td
+ | 指定されたユーザー名のユーザーの投稿を除外します。
+ | 「,」(カンマ)で区切って、複数ユーザーを指定することもできます。
+ br
+ | 例えば、
+ code exclude_user:akari,chinatsu
+ | と検索すると「@akariまたは@chinatsu以外の投稿」に限定します。
+ | (つまりユーザーのブラックリストです)
tr
td follow
td
--
cgit v1.2.3-freya
From 718060dc855e09f270b8e19c089ed3c3743665e0 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 2 Feb 2018 08:21:30 +0900
Subject: wip
---
src/api/common/add-file-to-drive.ts | 4 ++--
src/api/common/notify.ts | 6 +++---
src/api/endpoints/app/create.ts | 4 ++--
src/api/endpoints/app/show.ts | 4 ++--
src/api/endpoints/auth/session/show.ts | 4 ++--
src/api/endpoints/auth/session/userkey.ts | 4 ++--
src/api/endpoints/channels.ts | 4 ++--
src/api/endpoints/channels/create.ts | 4 ++--
src/api/endpoints/channels/posts.ts | 4 ++--
src/api/endpoints/channels/show.ts | 4 ++--
src/api/endpoints/drive/files.ts | 4 ++--
src/api/endpoints/drive/files/create.ts | 4 ++--
src/api/endpoints/drive/files/find.ts | 4 ++--
src/api/endpoints/drive/files/show.ts | 4 ++--
src/api/endpoints/drive/files/update.ts | 4 ++--
src/api/endpoints/drive/files/upload_from_url.ts | 4 ++--
src/api/endpoints/drive/folders.ts | 4 ++--
src/api/endpoints/drive/folders/create.ts | 4 ++--
src/api/endpoints/drive/folders/find.ts | 4 ++--
src/api/endpoints/drive/folders/show.ts | 4 ++--
src/api/endpoints/drive/folders/update.ts | 4 ++--
src/api/endpoints/drive/stream.ts | 4 ++--
src/api/endpoints/i.ts | 4 ++--
src/api/endpoints/i/authorized_apps.ts | 4 ++--
src/api/endpoints/i/favorites.ts | 4 ++--
src/api/endpoints/i/notifications.ts | 4 ++--
src/api/endpoints/i/pin.ts | 4 ++--
src/api/endpoints/i/signin_history.ts | 4 ++--
src/api/endpoints/i/update.ts | 4 ++--
src/api/endpoints/messaging/history.ts | 4 ++--
src/api/endpoints/messaging/messages.ts | 4 ++--
src/api/endpoints/messaging/messages/create.ts | 4 ++--
src/api/endpoints/mute/list.ts | 4 ++--
src/api/endpoints/my/apps.ts | 4 ++--
src/api/endpoints/posts.ts | 4 ++--
src/api/endpoints/posts/context.ts | 4 ++--
src/api/endpoints/posts/create.ts | 4 ++--
src/api/endpoints/posts/mentions.ts | 4 ++--
src/api/endpoints/posts/polls/recommendation.ts | 4 ++--
src/api/endpoints/posts/reactions.ts | 4 ++--
src/api/endpoints/posts/replies.ts | 4 ++--
src/api/endpoints/posts/reposts.ts | 4 ++--
src/api/endpoints/posts/search.ts | 4 ++--
src/api/endpoints/posts/show.ts | 4 ++--
src/api/endpoints/posts/timeline.ts | 4 ++--
src/api/endpoints/posts/trend.ts | 4 ++--
src/api/endpoints/users.ts | 4 ++--
src/api/endpoints/users/followers.ts | 4 ++--
src/api/endpoints/users/following.ts | 4 ++--
src/api/endpoints/users/get_frequently_replied_users.ts | 4 ++--
src/api/endpoints/users/posts.ts | 4 ++--
src/api/endpoints/users/recommendation.ts | 4 ++--
src/api/endpoints/users/search.ts | 4 ++--
src/api/endpoints/users/search_by_username.ts | 4 ++--
src/api/endpoints/users/show.ts | 4 ++--
src/api/models/drive-file.ts | 10 ++++++++--
src/api/models/drive-folder.ts | 2 ++
src/api/models/messaging-message.ts | 5 +++++
src/api/private/signin.ts | 4 ++--
src/api/private/signup.ts | 4 ++--
src/api/service/twitter.ts | 4 ++--
61 files changed, 132 insertions(+), 119 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts
index 23cbc44e61..1ee455c092 100644
--- a/src/api/common/add-file-to-drive.ts
+++ b/src/api/common/add-file-to-drive.ts
@@ -12,7 +12,7 @@ import prominence = require('prominence');
import DriveFile, { getGridFSBucket } from '../models/drive-file';
import DriveFolder from '../models/drive-folder';
-import serialize from '../serializers/drive-file';
+import { pack } from '../models/drive-file';
import event, { publishDriveStream } from '../event';
import config from '../../conf';
@@ -282,7 +282,7 @@ export default (user: any, file: string | stream.Readable, ...args) => new Promi
log(`drive file has been created ${file._id}`);
resolve(file);
- serialize(file).then(serializedFile => {
+ pack(file).then(serializedFile => {
// Publish drive_file_created event
event(user._id, 'drive_file_created', serializedFile);
publishDriveStream(user._id, 'file_created', serializedFile);
diff --git a/src/api/common/notify.ts b/src/api/common/notify.ts
index 2b79416a30..ae5669b84c 100644
--- a/src/api/common/notify.ts
+++ b/src/api/common/notify.ts
@@ -2,7 +2,7 @@ import * as mongo from 'mongodb';
import Notification from '../models/notification';
import Mute from '../models/mute';
import event from '../event';
-import serialize from '../serializers/notification';
+import { pack } from '../models/notification';
export default (
notifiee: mongo.ObjectID,
@@ -27,7 +27,7 @@ export default (
// Publish notification event
event(notifiee, 'notification',
- await serialize(notification));
+ await pack(notification));
// 3秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する
setTimeout(async () => {
@@ -44,7 +44,7 @@ export default (
}
//#endregion
- event(notifiee, 'unread_notification', await serialize(notification));
+ event(notifiee, 'unread_notification', await pack(notification));
}
}, 3000);
});
diff --git a/src/api/endpoints/app/create.ts b/src/api/endpoints/app/create.ts
index ca684de02d..320163ebd9 100644
--- a/src/api/endpoints/app/create.ts
+++ b/src/api/endpoints/app/create.ts
@@ -5,7 +5,7 @@ import rndstr from 'rndstr';
import $ from 'cafy';
import App from '../../models/app';
import { isValidNameId } from '../../models/app';
-import serialize from '../../serializers/app';
+import { pack } from '../../models/app';
/**
* @swagger
@@ -106,5 +106,5 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
});
// Response
- res(await serialize(app));
+ res(await pack(app));
});
diff --git a/src/api/endpoints/app/show.ts b/src/api/endpoints/app/show.ts
index 054aab8596..a3ef24717d 100644
--- a/src/api/endpoints/app/show.ts
+++ b/src/api/endpoints/app/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import App from '../../models/app';
-import serialize from '../../serializers/app';
+import { pack } from '../../models/app';
/**
* @swagger
@@ -67,7 +67,7 @@ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) =>
}
// Send response
- res(await serialize(app, user, {
+ res(await pack(app, user, {
includeSecret: isSecure && app.user_id.equals(user._id)
}));
});
diff --git a/src/api/endpoints/auth/session/show.ts b/src/api/endpoints/auth/session/show.ts
index ede8a67634..1fe3b873fe 100644
--- a/src/api/endpoints/auth/session/show.ts
+++ b/src/api/endpoints/auth/session/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import AuthSess from '../../../models/auth-session';
-import serialize from '../../../serializers/auth-session';
+import { pack } from '../../../models/auth-session';
/**
* @swagger
@@ -67,5 +67,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Response
- res(await serialize(session, user));
+ res(await pack(session, user));
});
diff --git a/src/api/endpoints/auth/session/userkey.ts b/src/api/endpoints/auth/session/userkey.ts
index afd3250b04..fc989bf8c2 100644
--- a/src/api/endpoints/auth/session/userkey.ts
+++ b/src/api/endpoints/auth/session/userkey.ts
@@ -5,7 +5,7 @@ import $ from 'cafy';
import App from '../../../models/app';
import AuthSess from '../../../models/auth-session';
import AccessToken from '../../../models/access-token';
-import serialize from '../../../serializers/user';
+import { pack } from '../../../models/user';
/**
* @swagger
@@ -102,7 +102,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
// Response
res({
access_token: accessToken.token,
- user: await serialize(session.user_id, null, {
+ user: await pack(session.user_id, null, {
detail: true
})
});
diff --git a/src/api/endpoints/channels.ts b/src/api/endpoints/channels.ts
index 14817d9bd8..92dcee83db 100644
--- a/src/api/endpoints/channels.ts
+++ b/src/api/endpoints/channels.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Channel from '../models/channel';
-import serialize from '../serializers/channel';
+import { pack } from '../models/channel';
/**
* Get all channels
@@ -55,5 +55,5 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(channels.map(async channel =>
- await serialize(channel, me))));
+ await pack(channel, me))));
});
diff --git a/src/api/endpoints/channels/create.ts b/src/api/endpoints/channels/create.ts
index a8d7c29dc1..695b4515b3 100644
--- a/src/api/endpoints/channels/create.ts
+++ b/src/api/endpoints/channels/create.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Channel from '../../models/channel';
import Watching from '../../models/channel-watching';
-import serialize from '../../serializers/channel';
+import { pack } from '../../models/channel';
/**
* Create a channel
@@ -28,7 +28,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
});
// Response
- res(await serialize(channel));
+ res(await pack(channel));
// Create Watching
await Watching.insert({
diff --git a/src/api/endpoints/channels/posts.ts b/src/api/endpoints/channels/posts.ts
index 9c2d607edb..3feee51f76 100644
--- a/src/api/endpoints/channels/posts.ts
+++ b/src/api/endpoints/channels/posts.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import { default as Channel, IChannel } from '../../models/channel';
import Post from '../../models/post';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Show a posts of a channel
@@ -74,6 +74,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(posts.map(async (post) =>
- await serialize(post, user)
+ await pack(post, user)
)));
});
diff --git a/src/api/endpoints/channels/show.ts b/src/api/endpoints/channels/show.ts
index 8861e54594..89c48379a4 100644
--- a/src/api/endpoints/channels/show.ts
+++ b/src/api/endpoints/channels/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import { default as Channel, IChannel } from '../../models/channel';
-import serialize from '../../serializers/channel';
+import { pack } from '../../models/channel';
/**
* Show a channel
@@ -27,5 +27,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Serialize
- res(await serialize(channel, user));
+ res(await pack(channel, user));
});
diff --git a/src/api/endpoints/drive/files.ts b/src/api/endpoints/drive/files.ts
index 3d5f81339a..3bd80e7282 100644
--- a/src/api/endpoints/drive/files.ts
+++ b/src/api/endpoints/drive/files.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFile from '../../models/drive-file';
-import serialize from '../../serializers/drive-file';
+import { pack } from '../../models/drive-file';
/**
* Get drive files
@@ -69,6 +69,6 @@ module.exports = async (params, user, app) => {
});
// Serialize
- const _files = await Promise.all(files.map(file => serialize(file)));
+ const _files = await Promise.all(files.map(file => pack(file)));
return _files;
};
diff --git a/src/api/endpoints/drive/files/create.ts b/src/api/endpoints/drive/files/create.ts
index 437348a1ef..6fa76d7e95 100644
--- a/src/api/endpoints/drive/files/create.ts
+++ b/src/api/endpoints/drive/files/create.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import { validateFileName } from '../../../models/drive-file';
-import serialize from '../../../serializers/drive-file';
+import { pack } from '../../../models/drive-file';
import create from '../../../common/add-file-to-drive';
/**
@@ -43,7 +43,7 @@ module.exports = async (file, params, user): Promise => {
const driveFile = await create(user, file.path, name, null, folderId);
// Serialize
- return serialize(driveFile);
+ return pack(driveFile);
} catch (e) {
console.error(e);
diff --git a/src/api/endpoints/drive/files/find.ts b/src/api/endpoints/drive/files/find.ts
index a1cdf1643e..571aba81f4 100644
--- a/src/api/endpoints/drive/files/find.ts
+++ b/src/api/endpoints/drive/files/find.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFile from '../../../models/drive-file';
-import serialize from '../../../serializers/drive-file';
+import { pack } from '../../../models/drive-file';
/**
* Find a file(s)
@@ -31,5 +31,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(files.map(async file =>
- await serialize(file))));
+ await pack(file))));
});
diff --git a/src/api/endpoints/drive/files/show.ts b/src/api/endpoints/drive/files/show.ts
index 3c7cf774f9..00f69f1415 100644
--- a/src/api/endpoints/drive/files/show.ts
+++ b/src/api/endpoints/drive/files/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFile from '../../../models/drive-file';
-import serialize from '../../../serializers/drive-file';
+import { pack } from '../../../models/drive-file';
/**
* Show a file
@@ -29,7 +29,7 @@ module.exports = async (params, user) => {
}
// Serialize
- const _file = await serialize(file, {
+ const _file = await pack(file, {
detail: true
});
diff --git a/src/api/endpoints/drive/files/update.ts b/src/api/endpoints/drive/files/update.ts
index f39a420d6e..9ef8215b1a 100644
--- a/src/api/endpoints/drive/files/update.ts
+++ b/src/api/endpoints/drive/files/update.ts
@@ -5,7 +5,7 @@ import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
import DriveFile from '../../../models/drive-file';
import { validateFileName } from '../../../models/drive-file';
-import serialize from '../../../serializers/drive-file';
+import { pack } from '../../../models/drive-file';
import { publishDriveStream } from '../../../event';
/**
@@ -67,7 +67,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- const fileObj = await serialize(file);
+ const fileObj = await pack(file);
// Response
res(fileObj);
diff --git a/src/api/endpoints/drive/files/upload_from_url.ts b/src/api/endpoints/drive/files/upload_from_url.ts
index 519e0bdf65..f0398bfc5d 100644
--- a/src/api/endpoints/drive/files/upload_from_url.ts
+++ b/src/api/endpoints/drive/files/upload_from_url.ts
@@ -4,7 +4,7 @@
import * as URL from 'url';
import $ from 'cafy';
import { validateFileName } from '../../../models/drive-file';
-import serialize from '../../../serializers/drive-file';
+import { pack } from '../../../models/drive-file';
import create from '../../../common/add-file-to-drive';
import * as debug from 'debug';
import * as tmp from 'tmp';
@@ -63,5 +63,5 @@ module.exports = async (params, user): Promise => {
if (e) log(e.stack);
});
- return serialize(driveFile);
+ return pack(driveFile);
};
diff --git a/src/api/endpoints/drive/folders.ts b/src/api/endpoints/drive/folders.ts
index 7944e2c6a6..e650fb74aa 100644
--- a/src/api/endpoints/drive/folders.ts
+++ b/src/api/endpoints/drive/folders.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFolder from '../../models/drive-folder';
-import serialize from '../../serializers/drive-folder';
+import { pack } from '../../models/drive-folder';
/**
* Get drive folders
@@ -63,5 +63,5 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(folders.map(async folder =>
- await serialize(folder))));
+ await pack(folder))));
});
diff --git a/src/api/endpoints/drive/folders/create.ts b/src/api/endpoints/drive/folders/create.ts
index be847b2153..1953c09ee0 100644
--- a/src/api/endpoints/drive/folders/create.ts
+++ b/src/api/endpoints/drive/folders/create.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
import { isValidFolderName } from '../../../models/drive-folder';
-import serialize from '../../../serializers/drive-folder';
+import { pack } from '../../../models/drive-folder';
import { publishDriveStream } from '../../../event';
/**
@@ -47,7 +47,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- const folderObj = await serialize(folder);
+ const folderObj = await pack(folder);
// Response
res(folderObj);
diff --git a/src/api/endpoints/drive/folders/find.ts b/src/api/endpoints/drive/folders/find.ts
index a5eb8e015d..caad45d740 100644
--- a/src/api/endpoints/drive/folders/find.ts
+++ b/src/api/endpoints/drive/folders/find.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
-import serialize from '../../../serializers/drive-folder';
+import { pack } from '../../../models/drive-folder';
/**
* Find a folder(s)
@@ -30,5 +30,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- res(await Promise.all(folders.map(folder => serialize(folder))));
+ res(await Promise.all(folders.map(folder => pack(folder))));
});
diff --git a/src/api/endpoints/drive/folders/show.ts b/src/api/endpoints/drive/folders/show.ts
index 9b1c04ca3c..fd3061ca54 100644
--- a/src/api/endpoints/drive/folders/show.ts
+++ b/src/api/endpoints/drive/folders/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
-import serialize from '../../../serializers/drive-folder';
+import { pack } from '../../../models/drive-folder';
/**
* Show a folder
@@ -29,7 +29,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Serialize
- res(await serialize(folder, {
+ res(await pack(folder, {
detail: true
}));
});
diff --git a/src/api/endpoints/drive/folders/update.ts b/src/api/endpoints/drive/folders/update.ts
index ff673402ab..8f50a9d009 100644
--- a/src/api/endpoints/drive/folders/update.ts
+++ b/src/api/endpoints/drive/folders/update.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
import { isValidFolderName } from '../../../models/drive-folder';
-import serialize from '../../../serializers/drive-folder';
+import { pack } from '../../../models/drive-folder';
import { publishDriveStream } from '../../../event';
/**
@@ -91,7 +91,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- const folderObj = await serialize(folder);
+ const folderObj = await pack(folder);
// Response
res(folderObj);
diff --git a/src/api/endpoints/drive/stream.ts b/src/api/endpoints/drive/stream.ts
index 5b0eb0a0d8..3527d70500 100644
--- a/src/api/endpoints/drive/stream.ts
+++ b/src/api/endpoints/drive/stream.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFile from '../../models/drive-file';
-import serialize from '../../serializers/drive-file';
+import { pack } from '../../models/drive-file';
/**
* Get drive stream
@@ -64,5 +64,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(files.map(async file =>
- await serialize(file))));
+ await pack(file))));
});
diff --git a/src/api/endpoints/i.ts b/src/api/endpoints/i.ts
index ae75f11d54..1b6c1e58de 100644
--- a/src/api/endpoints/i.ts
+++ b/src/api/endpoints/i.ts
@@ -2,7 +2,7 @@
* Module dependencies
*/
import User from '../models/user';
-import serialize from '../serializers/user';
+import { pack } from '../models/user';
/**
* Show myself
@@ -15,7 +15,7 @@ import serialize from '../serializers/user';
*/
module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => {
// Serialize
- res(await serialize(user, user, {
+ res(await pack(user, user, {
detail: true,
includeSecrets: isSecure
}));
diff --git a/src/api/endpoints/i/authorized_apps.ts b/src/api/endpoints/i/authorized_apps.ts
index 807ca5b1e7..40ce7a68c8 100644
--- a/src/api/endpoints/i/authorized_apps.ts
+++ b/src/api/endpoints/i/authorized_apps.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import AccessToken from '../../models/access-token';
-import serialize from '../../serializers/app';
+import { pack } from '../../models/app';
/**
* Get authorized apps of my account
@@ -39,5 +39,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(tokens.map(async token =>
- await serialize(token.app_id))));
+ await pack(token.app_id))));
});
diff --git a/src/api/endpoints/i/favorites.ts b/src/api/endpoints/i/favorites.ts
index a66eaa7546..eb464cf0f0 100644
--- a/src/api/endpoints/i/favorites.ts
+++ b/src/api/endpoints/i/favorites.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Favorite from '../../models/favorite';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Get followers of a user
@@ -39,6 +39,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(favorites.map(async favorite =>
- await serialize(favorite.post)
+ await pack(favorite.post)
)));
});
diff --git a/src/api/endpoints/i/notifications.ts b/src/api/endpoints/i/notifications.ts
index fb9be7f61b..688039a0dd 100644
--- a/src/api/endpoints/i/notifications.ts
+++ b/src/api/endpoints/i/notifications.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Notification from '../../models/notification';
import Mute from '../../models/mute';
-import serialize from '../../serializers/notification';
+import { pack } from '../../models/notification';
import getFriends from '../../common/get-friends';
import read from '../../common/read-notification';
@@ -101,7 +101,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(notifications.map(async notification =>
- await serialize(notification))));
+ await pack(notification))));
// Mark as read all
if (notifications.length > 0 && markAsRead) {
diff --git a/src/api/endpoints/i/pin.ts b/src/api/endpoints/i/pin.ts
index a94950d22b..ff546fc2bd 100644
--- a/src/api/endpoints/i/pin.ts
+++ b/src/api/endpoints/i/pin.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../models/user';
import Post from '../../models/post';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
/**
* Pin post
@@ -35,7 +35,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- const iObj = await serialize(user, user, {
+ const iObj = await pack(user, user, {
detail: true
});
diff --git a/src/api/endpoints/i/signin_history.ts b/src/api/endpoints/i/signin_history.ts
index e38bfa4d98..3ab59b694d 100644
--- a/src/api/endpoints/i/signin_history.ts
+++ b/src/api/endpoints/i/signin_history.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Signin from '../../models/signin';
-import serialize from '../../serializers/signin';
+import { pack } from '../../models/signin';
/**
* Get signin history of my account
@@ -58,5 +58,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(history.map(async record =>
- await serialize(record))));
+ await pack(record))));
});
diff --git a/src/api/endpoints/i/update.ts b/src/api/endpoints/i/update.ts
index c484c51a96..a138832e54 100644
--- a/src/api/endpoints/i/update.ts
+++ b/src/api/endpoints/i/update.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../models/user';
import { isValidName, isValidDescription, isValidLocation, isValidBirthday } from '../../models/user';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
import event from '../../event';
import config from '../../../conf';
@@ -65,7 +65,7 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
});
// Serialize
- const iObj = await serialize(user, user, {
+ const iObj = await pack(user, user, {
detail: true,
includeSecrets: isSecure
});
diff --git a/src/api/endpoints/messaging/history.ts b/src/api/endpoints/messaging/history.ts
index f14740dff5..1683ca7a89 100644
--- a/src/api/endpoints/messaging/history.ts
+++ b/src/api/endpoints/messaging/history.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import History from '../../models/messaging-history';
import Mute from '../../models/mute';
-import serialize from '../../serializers/messaging-message';
+import { pack } from '../../models/messaging-message';
/**
* Show messaging history
@@ -39,5 +39,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(history.map(async h =>
- await serialize(h.message, user))));
+ await pack(h.message, user))));
});
diff --git a/src/api/endpoints/messaging/messages.ts b/src/api/endpoints/messaging/messages.ts
index 3d3c6950a1..67ba5e9d6d 100644
--- a/src/api/endpoints/messaging/messages.ts
+++ b/src/api/endpoints/messaging/messages.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Message from '../../models/messaging-message';
import User from '../../models/user';
-import serialize from '../../serializers/messaging-message';
+import { pack } from '../../models/messaging-message';
import read from '../../common/read-messaging-message';
/**
@@ -87,7 +87,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(messages.map(async message =>
- await serialize(message, user, {
+ await pack(message, user, {
populateRecipient: false
}))));
diff --git a/src/api/endpoints/messaging/messages/create.ts b/src/api/endpoints/messaging/messages/create.ts
index 4e9d10197c..1b8a5f59e6 100644
--- a/src/api/endpoints/messaging/messages/create.ts
+++ b/src/api/endpoints/messaging/messages/create.ts
@@ -8,7 +8,7 @@ import History from '../../../models/messaging-history';
import User from '../../../models/user';
import Mute from '../../../models/mute';
import DriveFile from '../../../models/drive-file';
-import serialize from '../../../serializers/messaging-message';
+import { pack } from '../../../models/messaging-message';
import publishUserStream from '../../../event';
import { publishMessagingStream, publishMessagingIndexStream, pushSw } from '../../../event';
import config from '../../../../conf';
@@ -79,7 +79,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- const messageObj = await serialize(message);
+ const messageObj = await pack(message);
// Reponse
res(messageObj);
diff --git a/src/api/endpoints/mute/list.ts b/src/api/endpoints/mute/list.ts
index 740e19f0bb..19e3b157e6 100644
--- a/src/api/endpoints/mute/list.ts
+++ b/src/api/endpoints/mute/list.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Mute from '../../models/mute';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
import getFriends from '../../common/get-friends';
/**
@@ -63,7 +63,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
const users = await Promise.all(mutes.map(async m =>
- await serialize(m.mutee_id, me, { detail: true })));
+ await pack(m.mutee_id, me, { detail: true })));
// Response
res({
diff --git a/src/api/endpoints/my/apps.ts b/src/api/endpoints/my/apps.ts
index eb9c758768..fe583db86a 100644
--- a/src/api/endpoints/my/apps.ts
+++ b/src/api/endpoints/my/apps.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import App from '../../models/app';
-import serialize from '../../serializers/app';
+import { pack } from '../../models/app';
/**
* Get my apps
@@ -37,5 +37,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Reply
res(await Promise.all(apps.map(async app =>
- await serialize(app))));
+ await pack(app))));
});
diff --git a/src/api/endpoints/posts.ts b/src/api/endpoints/posts.ts
index db166cd67a..d10c6ab408 100644
--- a/src/api/endpoints/posts.ts
+++ b/src/api/endpoints/posts.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../models/post';
-import serialize from '../serializers/post';
+import { pack } from '../models/post';
/**
* Lists all posts
@@ -85,5 +85,5 @@ module.exports = (params) => new Promise(async (res, rej) => {
});
// Serialize
- res(await Promise.all(posts.map(async post => await serialize(post))));
+ res(await Promise.all(posts.map(async post => await pack(post))));
});
diff --git a/src/api/endpoints/posts/context.ts b/src/api/endpoints/posts/context.ts
index bad59a6bee..3051e7af17 100644
--- a/src/api/endpoints/posts/context.ts
+++ b/src/api/endpoints/posts/context.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Show a context of a post
@@ -60,5 +60,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(context.map(async post =>
- await serialize(post, user))));
+ await pack(post, user))));
});
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index a1d05c67c6..0fa52221f9 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -12,7 +12,7 @@ import Mute from '../../models/mute';
import DriveFile from '../../models/drive-file';
import Watching from '../../models/post-watching';
import ChannelWatching from '../../models/channel-watching';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
import notify from '../../common/notify';
import watch from '../../common/watch-post';
import event, { pushSw, publishChannelStream } from '../../event';
@@ -224,7 +224,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
});
// Serialize
- const postObj = await serialize(post);
+ const postObj = await pack(post);
// Reponse
res({
diff --git a/src/api/endpoints/posts/mentions.ts b/src/api/endpoints/posts/mentions.ts
index 3bb4ec3fa0..7127db0ad1 100644
--- a/src/api/endpoints/posts/mentions.ts
+++ b/src/api/endpoints/posts/mentions.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Post from '../../models/post';
import getFriends from '../../common/get-friends';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Get mentions of myself
@@ -73,6 +73,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(mentions.map(async mention =>
- await serialize(mention, user)
+ await pack(mention, user)
)));
});
diff --git a/src/api/endpoints/posts/polls/recommendation.ts b/src/api/endpoints/posts/polls/recommendation.ts
index 9c92d6cac4..5ccb754496 100644
--- a/src/api/endpoints/posts/polls/recommendation.ts
+++ b/src/api/endpoints/posts/polls/recommendation.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Vote from '../../../models/poll-vote';
import Post from '../../../models/post';
-import serialize from '../../../serializers/post';
+import { pack } from '../../../models/post';
/**
* Get recommended polls
@@ -56,5 +56,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(posts.map(async post =>
- await serialize(post, user, { detail: true }))));
+ await pack(post, user, { detail: true }))));
});
diff --git a/src/api/endpoints/posts/reactions.ts b/src/api/endpoints/posts/reactions.ts
index eab5d9b258..f60334df8a 100644
--- a/src/api/endpoints/posts/reactions.ts
+++ b/src/api/endpoints/posts/reactions.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Post from '../../models/post';
import Reaction from '../../models/post-reaction';
-import serialize from '../../serializers/post-reaction';
+import { pack } from '../../models/post-reaction';
/**
* Show reactions of a post
@@ -54,5 +54,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(reactions.map(async reaction =>
- await serialize(reaction, user))));
+ await pack(reaction, user))));
});
diff --git a/src/api/endpoints/posts/replies.ts b/src/api/endpoints/posts/replies.ts
index 3fd6a46769..1442b8a4c5 100644
--- a/src/api/endpoints/posts/replies.ts
+++ b/src/api/endpoints/posts/replies.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Show a replies of a post
@@ -50,5 +50,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(replies.map(async post =>
- await serialize(post, user))));
+ await pack(post, user))));
});
diff --git a/src/api/endpoints/posts/reposts.ts b/src/api/endpoints/posts/reposts.ts
index bcc6163a11..0fbb0687b9 100644
--- a/src/api/endpoints/posts/reposts.ts
+++ b/src/api/endpoints/posts/reposts.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Show a reposts of a post
@@ -70,5 +70,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(reposts.map(async post =>
- await serialize(post, user))));
+ await pack(post, user))));
});
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index 31c9a8d3c8..6e26f55390 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -7,7 +7,7 @@ import Post from '../../models/post';
import User from '../../models/user';
import Mute from '../../models/mute';
import getFriends from '../../common/get-friends';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Search a post
@@ -351,5 +351,5 @@ async function search(
// Serialize
res(await Promise.all(posts.map(async post =>
- await serialize(post, me))));
+ await pack(post, me))));
}
diff --git a/src/api/endpoints/posts/show.ts b/src/api/endpoints/posts/show.ts
index 5bfe4f6605..c312449710 100644
--- a/src/api/endpoints/posts/show.ts
+++ b/src/api/endpoints/posts/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Show a post
@@ -27,7 +27,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Serialize
- res(await serialize(post, user, {
+ res(await pack(post, user, {
detail: true
}));
});
diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts
index da7ffd0c14..c41cfdb8bd 100644
--- a/src/api/endpoints/posts/timeline.ts
+++ b/src/api/endpoints/posts/timeline.ts
@@ -7,7 +7,7 @@ import Post from '../../models/post';
import Mute from '../../models/mute';
import ChannelWatching from '../../models/channel-watching';
import getFriends from '../../common/get-friends';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Get timeline of myself
@@ -128,5 +128,5 @@ module.exports = async (params, user, app) => {
});
// Serialize
- return await Promise.all(timeline.map(post => serialize(post, user)));
+ return await Promise.all(timeline.map(post => pack(post, user)));
};
diff --git a/src/api/endpoints/posts/trend.ts b/src/api/endpoints/posts/trend.ts
index 64a195dff1..b2b1d327a8 100644
--- a/src/api/endpoints/posts/trend.ts
+++ b/src/api/endpoints/posts/trend.ts
@@ -4,7 +4,7 @@
const ms = require('ms');
import $ from 'cafy';
import Post from '../../models/post';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Get trend posts
@@ -76,5 +76,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(posts.map(async post =>
- await serialize(post, user, { detail: true }))));
+ await pack(post, user, { detail: true }))));
});
diff --git a/src/api/endpoints/users.ts b/src/api/endpoints/users.ts
index f3c9b66a5e..ba33b1aeb7 100644
--- a/src/api/endpoints/users.ts
+++ b/src/api/endpoints/users.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import User from '../models/user';
-import serialize from '../serializers/user';
+import { pack } from '../models/user';
/**
* Lists all users
@@ -55,5 +55,5 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(users.map(async user =>
- await serialize(user, me))));
+ await pack(user, me))));
});
diff --git a/src/api/endpoints/users/followers.ts b/src/api/endpoints/users/followers.ts
index 4905323ba5..b0fb83c683 100644
--- a/src/api/endpoints/users/followers.ts
+++ b/src/api/endpoints/users/followers.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../models/user';
import Following from '../../models/following';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
import getFriends from '../../common/get-friends';
/**
@@ -82,7 +82,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
const users = await Promise.all(following.map(async f =>
- await serialize(f.follower_id, me, { detail: true })));
+ await pack(f.follower_id, me, { detail: true })));
// Response
res({
diff --git a/src/api/endpoints/users/following.ts b/src/api/endpoints/users/following.ts
index dc2ff49bbe..8e88431e92 100644
--- a/src/api/endpoints/users/following.ts
+++ b/src/api/endpoints/users/following.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../models/user';
import Following from '../../models/following';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
import getFriends from '../../common/get-friends';
/**
@@ -82,7 +82,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
const users = await Promise.all(following.map(async f =>
- await serialize(f.followee_id, me, { detail: true })));
+ await pack(f.followee_id, me, { detail: true })));
// Response
res({
diff --git a/src/api/endpoints/users/get_frequently_replied_users.ts b/src/api/endpoints/users/get_frequently_replied_users.ts
index a8add623d4..3cbc761322 100644
--- a/src/api/endpoints/users/get_frequently_replied_users.ts
+++ b/src/api/endpoints/users/get_frequently_replied_users.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Post from '../../models/post';
import User from '../../models/user';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'user_id' parameter
@@ -91,7 +91,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Make replies object (includes weights)
const repliesObj = await Promise.all(topRepliedUsers.map(async (user) => ({
- user: await serialize(user, me, { detail: true }),
+ user: await pack(user, me, { detail: true }),
weight: repliedUsers[user] / peak
})));
diff --git a/src/api/endpoints/users/posts.ts b/src/api/endpoints/users/posts.ts
index 0d8384a43d..1f3db3cf79 100644
--- a/src/api/endpoints/users/posts.ts
+++ b/src/api/endpoints/users/posts.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Post from '../../models/post';
import User from '../../models/user';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Get posts of a user
@@ -124,6 +124,6 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(posts.map(async (post) =>
- await serialize(post, me)
+ await pack(post, me)
)));
});
diff --git a/src/api/endpoints/users/recommendation.ts b/src/api/endpoints/users/recommendation.ts
index 731d68a7b1..b80fd63ce7 100644
--- a/src/api/endpoints/users/recommendation.ts
+++ b/src/api/endpoints/users/recommendation.ts
@@ -4,7 +4,7 @@
const ms = require('ms');
import $ from 'cafy';
import User from '../../models/user';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
import getFriends from '../../common/get-friends';
/**
@@ -44,5 +44,5 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(users.map(async user =>
- await serialize(user, me, { detail: true }))));
+ await pack(user, me, { detail: true }))));
});
diff --git a/src/api/endpoints/users/search.ts b/src/api/endpoints/users/search.ts
index 73a5db47e2..213038403b 100644
--- a/src/api/endpoints/users/search.ts
+++ b/src/api/endpoints/users/search.ts
@@ -4,7 +4,7 @@
import * as mongo from 'mongodb';
import $ from 'cafy';
import User from '../../models/user';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
import config from '../../../conf';
const escapeRegexp = require('escape-regexp');
@@ -94,6 +94,6 @@ async function byElasticsearch(res, rej, me, query, offset, max) {
// Serialize
res(await Promise.all(users.map(async user =>
- await serialize(user, me, { detail: true }))));
+ await pack(user, me, { detail: true }))));
});
}
diff --git a/src/api/endpoints/users/search_by_username.ts b/src/api/endpoints/users/search_by_username.ts
index 7f2f42f0a6..63e206b1f2 100644
--- a/src/api/endpoints/users/search_by_username.ts
+++ b/src/api/endpoints/users/search_by_username.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import User from '../../models/user';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
/**
* Search a user by username
@@ -35,5 +35,5 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(users.map(async user =>
- await serialize(user, me, { detail: true }))));
+ await pack(user, me, { detail: true }))));
});
diff --git a/src/api/endpoints/users/show.ts b/src/api/endpoints/users/show.ts
index 8e74b0fe3f..a51cb619d4 100644
--- a/src/api/endpoints/users/show.ts
+++ b/src/api/endpoints/users/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import User from '../../models/user';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
/**
* Show a user
@@ -41,7 +41,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
}
// Send response
- res(await serialize(user, me, {
+ res(await pack(user, me, {
detail: true
}));
});
diff --git a/src/api/models/drive-file.ts b/src/api/models/drive-file.ts
index 6a8db3ad42..9b9df1dac6 100644
--- a/src/api/models/drive-file.ts
+++ b/src/api/models/drive-file.ts
@@ -20,8 +20,14 @@ export { getGridFSBucket };
export type IDriveFile = {
_id: mongodb.ObjectID;
- created_at: Date;
- user_id: mongodb.ObjectID;
+ uploadDate: Date;
+ md5: string;
+ filename: string;
+ metadata: {
+ properties: any;
+ user_id: mongodb.ObjectID;
+ folder_id: mongodb.ObjectID;
+ }
};
export function validateFileName(name: string): boolean {
diff --git a/src/api/models/drive-folder.ts b/src/api/models/drive-folder.ts
index 48b26c2bd6..54b45049b9 100644
--- a/src/api/models/drive-folder.ts
+++ b/src/api/models/drive-folder.ts
@@ -9,7 +9,9 @@ export default DriveFolder;
export type IDriveFolder = {
_id: mongo.ObjectID;
created_at: Date;
+ name: string;
user_id: mongo.ObjectID;
+ parent_id: mongo.ObjectID;
};
export function isValidFolderName(name: string): boolean {
diff --git a/src/api/models/messaging-message.ts b/src/api/models/messaging-message.ts
index ffdda1db21..90cf1cd71c 100644
--- a/src/api/models/messaging-message.ts
+++ b/src/api/models/messaging-message.ts
@@ -10,6 +10,11 @@ export default MessagingMessage;
export interface IMessagingMessage {
_id: mongo.ObjectID;
+ created_at: Date;
+ text: string;
+ user_id: mongo.ObjectID;
+ recipient_id: mongo.ObjectID;
+ is_read: boolean;
}
export function isValidText(text: string): boolean {
diff --git a/src/api/private/signin.ts b/src/api/private/signin.ts
index a26c8f6c5a..ab6e93562c 100644
--- a/src/api/private/signin.ts
+++ b/src/api/private/signin.ts
@@ -3,7 +3,7 @@ import * as bcrypt from 'bcryptjs';
import * as speakeasy from 'speakeasy';
import { default as User, IUser } from '../models/user';
import Signin from '../models/signin';
-import serialize from '../serializers/signin';
+import { pack } from '../models/signin';
import event from '../event';
import signin from '../common/signin';
import config from '../../conf';
@@ -85,5 +85,5 @@ export default async (req: express.Request, res: express.Response) => {
});
// Publish signin event
- event(user._id, 'signin', await serialize(record));
+ event(user._id, 'signin', await pack(record));
};
diff --git a/src/api/private/signup.ts b/src/api/private/signup.ts
index 466c6a489f..105fe319a5 100644
--- a/src/api/private/signup.ts
+++ b/src/api/private/signup.ts
@@ -4,7 +4,7 @@ import * as bcrypt from 'bcryptjs';
import recaptcha = require('recaptcha-promise');
import { default as User, IUser } from '../models/user';
import { validateUsername, validatePassword } from '../models/user';
-import serialize from '../serializers/user';
+import { pack } from '../models/user';
import generateUserToken from '../common/generate-native-user-token';
import config from '../../conf';
@@ -142,7 +142,7 @@ export default async (req: express.Request, res: express.Response) => {
});
// Response
- res.send(await serialize(account));
+ res.send(await pack(account));
// Create search index
if (config.elasticsearch.enable) {
diff --git a/src/api/service/twitter.ts b/src/api/service/twitter.ts
index 0e75ee0bdb..ca4f8abcca 100644
--- a/src/api/service/twitter.ts
+++ b/src/api/service/twitter.ts
@@ -6,7 +6,7 @@ import * as uuid from 'uuid';
import autwh from 'autwh';
import redis from '../../db/redis';
import User from '../models/user';
-import serialize from '../serializers/user';
+import { pack } from '../models/user';
import event from '../event';
import config from '../../conf';
import signin from '../common/signin';
@@ -50,7 +50,7 @@ module.exports = (app: express.Application) => {
res.send(`Twitterの連携を解除しました :v:`);
// Publish i updated event
- event(user._id, 'i_updated', await serialize(user, user, {
+ event(user._id, 'i_updated', await pack(user, user, {
detail: true,
includeSecrets: true
}));
--
cgit v1.2.3-freya
From 2cb0511dba7463ad50725fd2dfd1966f0a108a45 Mon Sep 17 00:00:00 2001
From: こぴなたみぽ
Date: Fri, 2 Feb 2018 10:31:17 +0900
Subject: wip
---
src/api/endpoints/app/create.ts | 3 +--
src/api/endpoints/app/show.ts | 3 +--
src/api/endpoints/auth/session/show.ts | 3 +--
src/api/endpoints/channels.ts | 3 +--
src/api/endpoints/channels/posts.ts | 3 +--
src/api/endpoints/channels/show.ts | 3 +--
src/api/endpoints/drive/files.ts | 3 +--
src/api/endpoints/drive/files/create.ts | 3 +--
src/api/endpoints/drive/files/find.ts | 3 +--
src/api/endpoints/drive/files/show.ts | 3 +--
src/api/endpoints/drive/files/update.ts | 3 +--
src/api/endpoints/drive/files/upload_from_url.ts | 3 +--
src/api/endpoints/drive/folders.ts | 3 +--
src/api/endpoints/drive/folders/create.ts | 3 +--
src/api/endpoints/drive/folders/find.ts | 3 +--
src/api/endpoints/drive/folders/show.ts | 3 +--
src/api/endpoints/drive/folders/update.ts | 3 +--
src/api/endpoints/drive/stream.ts | 3 +--
src/api/endpoints/i.ts | 3 +--
src/api/endpoints/i/signin_history.ts | 3 +--
src/api/endpoints/i/update.ts | 3 +--
src/api/endpoints/my/apps.ts | 3 +--
src/api/endpoints/posts.ts | 3 +--
src/api/endpoints/posts/context.ts | 3 +--
src/api/endpoints/posts/polls/recommendation.ts | 3 +--
src/api/endpoints/posts/reactions.ts | 3 +--
src/api/endpoints/posts/replies.ts | 3 +--
src/api/endpoints/posts/reposts.ts | 3 +--
src/api/endpoints/posts/show.ts | 3 +--
src/api/endpoints/posts/trend.ts | 3 +--
src/api/endpoints/users.ts | 3 +--
src/api/endpoints/users/get_frequently_replied_users.ts | 3 +--
src/api/endpoints/users/posts.ts | 3 +--
src/api/endpoints/users/recommendation.ts | 3 +--
src/api/endpoints/users/search.ts | 3 +--
src/api/endpoints/users/search_by_username.ts | 3 +--
src/api/endpoints/users/show.ts | 3 +--
src/api/private/signin.ts | 3 +--
src/api/private/signup.ts | 3 +--
src/api/service/twitter.ts | 3 +--
40 files changed, 40 insertions(+), 80 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/app/create.ts b/src/api/endpoints/app/create.ts
index 320163ebd9..71633f7def 100644
--- a/src/api/endpoints/app/create.ts
+++ b/src/api/endpoints/app/create.ts
@@ -4,8 +4,7 @@
import rndstr from 'rndstr';
import $ from 'cafy';
import App from '../../models/app';
-import { isValidNameId } from '../../models/app';
-import { pack } from '../../models/app';
+import { isValidNameId }, { pack } from '../../models/app';
/**
* @swagger
diff --git a/src/api/endpoints/app/show.ts b/src/api/endpoints/app/show.ts
index a3ef24717d..8bc3dda42c 100644
--- a/src/api/endpoints/app/show.ts
+++ b/src/api/endpoints/app/show.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import App from '../../models/app';
-import { pack } from '../../models/app';
+import App, { pack } from '../../models/app';
/**
* @swagger
diff --git a/src/api/endpoints/auth/session/show.ts b/src/api/endpoints/auth/session/show.ts
index 1fe3b873fe..73ac3185f6 100644
--- a/src/api/endpoints/auth/session/show.ts
+++ b/src/api/endpoints/auth/session/show.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import AuthSess from '../../../models/auth-session';
-import { pack } from '../../../models/auth-session';
+import AuthSess, { pack } from '../../../models/auth-session';
/**
* @swagger
diff --git a/src/api/endpoints/channels.ts b/src/api/endpoints/channels.ts
index 92dcee83db..b9a7d1b788 100644
--- a/src/api/endpoints/channels.ts
+++ b/src/api/endpoints/channels.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import Channel from '../models/channel';
-import { pack } from '../models/channel';
+import Channel, { pack } from '../models/channel';
/**
* Get all channels
diff --git a/src/api/endpoints/channels/posts.ts b/src/api/endpoints/channels/posts.ts
index 3feee51f76..d722589c20 100644
--- a/src/api/endpoints/channels/posts.ts
+++ b/src/api/endpoints/channels/posts.ts
@@ -3,8 +3,7 @@
*/
import $ from 'cafy';
import { default as Channel, IChannel } from '../../models/channel';
-import Post from '../../models/post';
-import { pack } from '../../models/post';
+import Post, { pack } from '../../models/post';
/**
* Show a posts of a channel
diff --git a/src/api/endpoints/channels/show.ts b/src/api/endpoints/channels/show.ts
index 89c48379a4..3238616fa5 100644
--- a/src/api/endpoints/channels/show.ts
+++ b/src/api/endpoints/channels/show.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import { default as Channel, IChannel } from '../../models/channel';
-import { pack } from '../../models/channel';
+import { default as Channel, IChannel }, { pack } from '../../models/channel';
/**
* Show a channel
diff --git a/src/api/endpoints/drive/files.ts b/src/api/endpoints/drive/files.ts
index 3bd80e7282..89915331ea 100644
--- a/src/api/endpoints/drive/files.ts
+++ b/src/api/endpoints/drive/files.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import DriveFile from '../../models/drive-file';
-import { pack } from '../../models/drive-file';
+import DriveFile, { pack } from '../../models/drive-file';
/**
* Get drive files
diff --git a/src/api/endpoints/drive/files/create.ts b/src/api/endpoints/drive/files/create.ts
index 6fa76d7e95..7b424f3f5a 100644
--- a/src/api/endpoints/drive/files/create.ts
+++ b/src/api/endpoints/drive/files/create.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import { validateFileName } from '../../../models/drive-file';
-import { pack } from '../../../models/drive-file';
+import { validateFileName }, { pack } from '../../../models/drive-file';
import create from '../../../common/add-file-to-drive';
/**
diff --git a/src/api/endpoints/drive/files/find.ts b/src/api/endpoints/drive/files/find.ts
index 571aba81f4..e026afe936 100644
--- a/src/api/endpoints/drive/files/find.ts
+++ b/src/api/endpoints/drive/files/find.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import DriveFile from '../../../models/drive-file';
-import { pack } from '../../../models/drive-file';
+import DriveFile, { pack } from '../../../models/drive-file';
/**
* Find a file(s)
diff --git a/src/api/endpoints/drive/files/show.ts b/src/api/endpoints/drive/files/show.ts
index 00f69f1415..21664f7ba4 100644
--- a/src/api/endpoints/drive/files/show.ts
+++ b/src/api/endpoints/drive/files/show.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import DriveFile from '../../../models/drive-file';
-import { pack } from '../../../models/drive-file';
+import DriveFile, { pack } from '../../../models/drive-file';
/**
* Show a file
diff --git a/src/api/endpoints/drive/files/update.ts b/src/api/endpoints/drive/files/update.ts
index 9ef8215b1a..ff65a48f71 100644
--- a/src/api/endpoints/drive/files/update.ts
+++ b/src/api/endpoints/drive/files/update.ts
@@ -4,8 +4,7 @@
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
import DriveFile from '../../../models/drive-file';
-import { validateFileName } from '../../../models/drive-file';
-import { pack } from '../../../models/drive-file';
+import { validateFileName }, { pack } from '../../../models/drive-file';
import { publishDriveStream } from '../../../event';
/**
diff --git a/src/api/endpoints/drive/files/upload_from_url.ts b/src/api/endpoints/drive/files/upload_from_url.ts
index f0398bfc5d..009f06aaaf 100644
--- a/src/api/endpoints/drive/files/upload_from_url.ts
+++ b/src/api/endpoints/drive/files/upload_from_url.ts
@@ -3,8 +3,7 @@
*/
import * as URL from 'url';
import $ from 'cafy';
-import { validateFileName } from '../../../models/drive-file';
-import { pack } from '../../../models/drive-file';
+import { validateFileName }, { pack } from '../../../models/drive-file';
import create from '../../../common/add-file-to-drive';
import * as debug from 'debug';
import * as tmp from 'tmp';
diff --git a/src/api/endpoints/drive/folders.ts b/src/api/endpoints/drive/folders.ts
index e650fb74aa..428bde3507 100644
--- a/src/api/endpoints/drive/folders.ts
+++ b/src/api/endpoints/drive/folders.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import DriveFolder from '../../models/drive-folder';
-import { pack } from '../../models/drive-folder';
+import DriveFolder, { pack } from '../../models/drive-folder';
/**
* Get drive folders
diff --git a/src/api/endpoints/drive/folders/create.ts b/src/api/endpoints/drive/folders/create.ts
index 1953c09ee0..6543b11274 100644
--- a/src/api/endpoints/drive/folders/create.ts
+++ b/src/api/endpoints/drive/folders/create.ts
@@ -3,8 +3,7 @@
*/
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
-import { isValidFolderName } from '../../../models/drive-folder';
-import { pack } from '../../../models/drive-folder';
+import { isValidFolderName }, { pack } from '../../../models/drive-folder';
import { publishDriveStream } from '../../../event';
/**
diff --git a/src/api/endpoints/drive/folders/find.ts b/src/api/endpoints/drive/folders/find.ts
index caad45d740..fc84766bc8 100644
--- a/src/api/endpoints/drive/folders/find.ts
+++ b/src/api/endpoints/drive/folders/find.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import DriveFolder from '../../../models/drive-folder';
-import { pack } from '../../../models/drive-folder';
+import DriveFolder, { pack } from '../../../models/drive-folder';
/**
* Find a folder(s)
diff --git a/src/api/endpoints/drive/folders/show.ts b/src/api/endpoints/drive/folders/show.ts
index fd3061ca54..e07d14d20d 100644
--- a/src/api/endpoints/drive/folders/show.ts
+++ b/src/api/endpoints/drive/folders/show.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import DriveFolder from '../../../models/drive-folder';
-import { pack } from '../../../models/drive-folder';
+import DriveFolder, { pack } from '../../../models/drive-folder';
/**
* Show a folder
diff --git a/src/api/endpoints/drive/folders/update.ts b/src/api/endpoints/drive/folders/update.ts
index 8f50a9d009..2adcadcb08 100644
--- a/src/api/endpoints/drive/folders/update.ts
+++ b/src/api/endpoints/drive/folders/update.ts
@@ -3,8 +3,7 @@
*/
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
-import { isValidFolderName } from '../../../models/drive-folder';
-import { pack } from '../../../models/drive-folder';
+import { isValidFolderName }, { pack } from '../../../models/drive-folder';
import { publishDriveStream } from '../../../event';
/**
diff --git a/src/api/endpoints/drive/stream.ts b/src/api/endpoints/drive/stream.ts
index 3527d70500..8352c7dd4c 100644
--- a/src/api/endpoints/drive/stream.ts
+++ b/src/api/endpoints/drive/stream.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import DriveFile from '../../models/drive-file';
-import { pack } from '../../models/drive-file';
+import DriveFile, { pack } from '../../models/drive-file';
/**
* Get drive stream
diff --git a/src/api/endpoints/i.ts b/src/api/endpoints/i.ts
index 1b6c1e58de..7efdbcd7c9 100644
--- a/src/api/endpoints/i.ts
+++ b/src/api/endpoints/i.ts
@@ -1,8 +1,7 @@
/**
* Module dependencies
*/
-import User from '../models/user';
-import { pack } from '../models/user';
+import User, { pack } from '../models/user';
/**
* Show myself
diff --git a/src/api/endpoints/i/signin_history.ts b/src/api/endpoints/i/signin_history.ts
index 3ab59b694d..859e81653d 100644
--- a/src/api/endpoints/i/signin_history.ts
+++ b/src/api/endpoints/i/signin_history.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import Signin from '../../models/signin';
-import { pack } from '../../models/signin';
+import Signin, { pack } from '../../models/signin';
/**
* Get signin history of my account
diff --git a/src/api/endpoints/i/update.ts b/src/api/endpoints/i/update.ts
index a138832e54..cd4b1a13f5 100644
--- a/src/api/endpoints/i/update.ts
+++ b/src/api/endpoints/i/update.ts
@@ -3,8 +3,7 @@
*/
import $ from 'cafy';
import User from '../../models/user';
-import { isValidName, isValidDescription, isValidLocation, isValidBirthday } from '../../models/user';
-import { pack } from '../../models/user';
+import { isValidName, isValidDescription, isValidLocation, isValidBirthday }, { pack } from '../../models/user';
import event from '../../event';
import config from '../../../conf';
diff --git a/src/api/endpoints/my/apps.ts b/src/api/endpoints/my/apps.ts
index fe583db86a..b236190506 100644
--- a/src/api/endpoints/my/apps.ts
+++ b/src/api/endpoints/my/apps.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import App from '../../models/app';
-import { pack } from '../../models/app';
+import App, { pack } from '../../models/app';
/**
* Get my apps
diff --git a/src/api/endpoints/posts.ts b/src/api/endpoints/posts.ts
index d10c6ab408..3b29425927 100644
--- a/src/api/endpoints/posts.ts
+++ b/src/api/endpoints/posts.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import Post from '../models/post';
-import { pack } from '../models/post';
+import Post, { pack } from '../models/post';
/**
* Lists all posts
diff --git a/src/api/endpoints/posts/context.ts b/src/api/endpoints/posts/context.ts
index 3051e7af17..5ba3758975 100644
--- a/src/api/endpoints/posts/context.ts
+++ b/src/api/endpoints/posts/context.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import Post from '../../models/post';
-import { pack } from '../../models/post';
+import Post, { pack } from '../../models/post';
/**
* Show a context of a post
diff --git a/src/api/endpoints/posts/polls/recommendation.ts b/src/api/endpoints/posts/polls/recommendation.ts
index 5ccb754496..4a3fa3f55e 100644
--- a/src/api/endpoints/posts/polls/recommendation.ts
+++ b/src/api/endpoints/posts/polls/recommendation.ts
@@ -3,8 +3,7 @@
*/
import $ from 'cafy';
import Vote from '../../../models/poll-vote';
-import Post from '../../../models/post';
-import { pack } from '../../../models/post';
+import Post, { pack } from '../../../models/post';
/**
* Get recommended polls
diff --git a/src/api/endpoints/posts/reactions.ts b/src/api/endpoints/posts/reactions.ts
index f60334df8a..feb140ab41 100644
--- a/src/api/endpoints/posts/reactions.ts
+++ b/src/api/endpoints/posts/reactions.ts
@@ -3,8 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
-import Reaction from '../../models/post-reaction';
-import { pack } from '../../models/post-reaction';
+import Reaction, { pack } from '../../models/post-reaction';
/**
* Show reactions of a post
diff --git a/src/api/endpoints/posts/replies.ts b/src/api/endpoints/posts/replies.ts
index 1442b8a4c5..613c4fa24c 100644
--- a/src/api/endpoints/posts/replies.ts
+++ b/src/api/endpoints/posts/replies.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import Post from '../../models/post';
-import { pack } from '../../models/post';
+import Post, { pack } from '../../models/post';
/**
* Show a replies of a post
diff --git a/src/api/endpoints/posts/reposts.ts b/src/api/endpoints/posts/reposts.ts
index 0fbb0687b9..89ab0e3d55 100644
--- a/src/api/endpoints/posts/reposts.ts
+++ b/src/api/endpoints/posts/reposts.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import Post from '../../models/post';
-import { pack } from '../../models/post';
+import Post, { pack } from '../../models/post';
/**
* Show a reposts of a post
diff --git a/src/api/endpoints/posts/show.ts b/src/api/endpoints/posts/show.ts
index c312449710..3839490597 100644
--- a/src/api/endpoints/posts/show.ts
+++ b/src/api/endpoints/posts/show.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import Post from '../../models/post';
-import { pack } from '../../models/post';
+import Post, { pack } from '../../models/post';
/**
* Show a post
diff --git a/src/api/endpoints/posts/trend.ts b/src/api/endpoints/posts/trend.ts
index b2b1d327a8..caded92bf5 100644
--- a/src/api/endpoints/posts/trend.ts
+++ b/src/api/endpoints/posts/trend.ts
@@ -3,8 +3,7 @@
*/
const ms = require('ms');
import $ from 'cafy';
-import Post from '../../models/post';
-import { pack } from '../../models/post';
+import Post, { pack } from '../../models/post';
/**
* Get trend posts
diff --git a/src/api/endpoints/users.ts b/src/api/endpoints/users.ts
index ba33b1aeb7..095b9fe40d 100644
--- a/src/api/endpoints/users.ts
+++ b/src/api/endpoints/users.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import User from '../models/user';
-import { pack } from '../models/user';
+import User, { pack } from '../models/user';
/**
* Lists all users
diff --git a/src/api/endpoints/users/get_frequently_replied_users.ts b/src/api/endpoints/users/get_frequently_replied_users.ts
index 3cbc761322..87f4f77a5b 100644
--- a/src/api/endpoints/users/get_frequently_replied_users.ts
+++ b/src/api/endpoints/users/get_frequently_replied_users.ts
@@ -3,8 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
-import User from '../../models/user';
-import { pack } from '../../models/user';
+import User, { pack } from '../../models/user';
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'user_id' parameter
diff --git a/src/api/endpoints/users/posts.ts b/src/api/endpoints/users/posts.ts
index 1f3db3cf79..285e5bc46c 100644
--- a/src/api/endpoints/users/posts.ts
+++ b/src/api/endpoints/users/posts.ts
@@ -3,8 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
-import User from '../../models/user';
-import { pack } from '../../models/post';
+import User, { pack } from '../../models/user';
/**
* Get posts of a user
diff --git a/src/api/endpoints/users/recommendation.ts b/src/api/endpoints/users/recommendation.ts
index b80fd63ce7..736233b340 100644
--- a/src/api/endpoints/users/recommendation.ts
+++ b/src/api/endpoints/users/recommendation.ts
@@ -3,8 +3,7 @@
*/
const ms = require('ms');
import $ from 'cafy';
-import User from '../../models/user';
-import { pack } from '../../models/user';
+import User, { pack } from '../../models/user';
import getFriends from '../../common/get-friends';
/**
diff --git a/src/api/endpoints/users/search.ts b/src/api/endpoints/users/search.ts
index 213038403b..1142db9e9b 100644
--- a/src/api/endpoints/users/search.ts
+++ b/src/api/endpoints/users/search.ts
@@ -3,8 +3,7 @@
*/
import * as mongo from 'mongodb';
import $ from 'cafy';
-import User from '../../models/user';
-import { pack } from '../../models/user';
+import User, { pack } from '../../models/user';
import config from '../../../conf';
const escapeRegexp = require('escape-regexp');
diff --git a/src/api/endpoints/users/search_by_username.ts b/src/api/endpoints/users/search_by_username.ts
index 63e206b1f2..9c5e1905aa 100644
--- a/src/api/endpoints/users/search_by_username.ts
+++ b/src/api/endpoints/users/search_by_username.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import User from '../../models/user';
-import { pack } from '../../models/user';
+import User, { pack } from '../../models/user';
/**
* Search a user by username
diff --git a/src/api/endpoints/users/show.ts b/src/api/endpoints/users/show.ts
index a51cb619d4..7aea59296a 100644
--- a/src/api/endpoints/users/show.ts
+++ b/src/api/endpoints/users/show.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import User from '../../models/user';
-import { pack } from '../../models/user';
+import User, { pack } from '../../models/user';
/**
* Show a user
diff --git a/src/api/private/signin.ts b/src/api/private/signin.ts
index ab6e93562c..b49d25d99a 100644
--- a/src/api/private/signin.ts
+++ b/src/api/private/signin.ts
@@ -2,8 +2,7 @@ import * as express from 'express';
import * as bcrypt from 'bcryptjs';
import * as speakeasy from 'speakeasy';
import { default as User, IUser } from '../models/user';
-import Signin from '../models/signin';
-import { pack } from '../models/signin';
+import Signin, { pack } from '../models/signin';
import event from '../event';
import signin from '../common/signin';
import config from '../../conf';
diff --git a/src/api/private/signup.ts b/src/api/private/signup.ts
index 105fe319a5..392f3b1fc7 100644
--- a/src/api/private/signup.ts
+++ b/src/api/private/signup.ts
@@ -3,8 +3,7 @@ import * as express from 'express';
import * as bcrypt from 'bcryptjs';
import recaptcha = require('recaptcha-promise');
import { default as User, IUser } from '../models/user';
-import { validateUsername, validatePassword } from '../models/user';
-import { pack } from '../models/user';
+import { validateUsername, validatePassword }, { pack } from '../models/user';
import generateUserToken from '../common/generate-native-user-token';
import config from '../../conf';
diff --git a/src/api/service/twitter.ts b/src/api/service/twitter.ts
index ca4f8abcca..7d4964eba6 100644
--- a/src/api/service/twitter.ts
+++ b/src/api/service/twitter.ts
@@ -5,8 +5,7 @@ import * as uuid from 'uuid';
// const Twitter = require('twitter');
import autwh from 'autwh';
import redis from '../../db/redis';
-import User from '../models/user';
-import { pack } from '../models/user';
+import User, { pack } from '../models/user';
import event from '../event';
import config from '../../conf';
import signin from '../common/signin';
--
cgit v1.2.3-freya
From bcd65d290d25219631bb47570478378a698d0fa0 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Sun, 4 Feb 2018 14:52:33 +0900
Subject: wip
---
src/api/endpoints/aggregation/posts/reactions.ts | 11 +++++++----
src/api/endpoints/aggregation/users.ts | 13 ++++++++-----
src/api/endpoints/app/create.ts | 3 +--
src/api/endpoints/channels/show.ts | 2 +-
src/api/endpoints/drive/files/create.ts | 2 +-
src/api/endpoints/drive/files/update.ts | 3 +--
src/api/endpoints/drive/files/upload_from_url.ts | 2 +-
src/api/endpoints/drive/folders/create.ts | 3 +--
src/api/endpoints/drive/folders/update.ts | 3 +--
src/api/endpoints/following/create.ts | 7 +++----
src/api/endpoints/following/delete.ts | 5 ++---
src/api/endpoints/i/update.ts | 3 +--
src/api/endpoints/posts/reactions/create.ts | 9 ++++-----
src/api/endpoints/users/posts.ts | 4 ++--
src/api/endpoints/users/search.ts | 2 +-
src/api/models/app.ts | 1 +
src/api/models/drive-file.ts | 1 +
src/api/models/post-reaction.ts | 3 +++
src/api/models/post.ts | 4 +++-
src/api/models/user.ts | 1 +
src/api/private/signup.ts | 3 +--
src/api/service/twitter.ts | 2 +-
src/api/stream/home.ts | 4 ++--
23 files changed, 48 insertions(+), 43 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/aggregation/posts/reactions.ts b/src/api/endpoints/aggregation/posts/reactions.ts
index 2cd4588ae1..790b523be9 100644
--- a/src/api/endpoints/aggregation/posts/reactions.ts
+++ b/src/api/endpoints/aggregation/posts/reactions.ts
@@ -35,10 +35,13 @@ module.exports = (params) => new Promise(async (res, rej) => {
{ deleted_at: { $gt: startTime } }
]
}, {
- _id: false,
- post_id: false
- }, {
- sort: { created_at: -1 }
+ sort: {
+ _id: -1
+ },
+ fields: {
+ _id: false,
+ post_id: false
+ }
});
const graph = [];
diff --git a/src/api/endpoints/aggregation/users.ts b/src/api/endpoints/aggregation/users.ts
index 9eb2d035ec..e38ce92ff9 100644
--- a/src/api/endpoints/aggregation/users.ts
+++ b/src/api/endpoints/aggregation/users.ts
@@ -17,11 +17,14 @@ module.exports = params => new Promise(async (res, rej) => {
const users = await User
.find({}, {
- _id: false,
- created_at: true,
- deleted_at: true
- }, {
- sort: { created_at: -1 }
+ sort: {
+ _id: -1
+ },
+ fields: {
+ _id: false,
+ created_at: true,
+ deleted_at: true
+ }
});
const graph = [];
diff --git a/src/api/endpoints/app/create.ts b/src/api/endpoints/app/create.ts
index 71633f7def..0f688792a7 100644
--- a/src/api/endpoints/app/create.ts
+++ b/src/api/endpoints/app/create.ts
@@ -3,8 +3,7 @@
*/
import rndstr from 'rndstr';
import $ from 'cafy';
-import App from '../../models/app';
-import { isValidNameId }, { pack } from '../../models/app';
+import App, { isValidNameId, pack } from '../../models/app';
/**
* @swagger
diff --git a/src/api/endpoints/channels/show.ts b/src/api/endpoints/channels/show.ts
index 3238616fa5..332da64675 100644
--- a/src/api/endpoints/channels/show.ts
+++ b/src/api/endpoints/channels/show.ts
@@ -2,7 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import { default as Channel, IChannel }, { pack } from '../../models/channel';
+import Channel, { IChannel, pack } from '../../models/channel';
/**
* Show a channel
diff --git a/src/api/endpoints/drive/files/create.ts b/src/api/endpoints/drive/files/create.ts
index 7b424f3f5a..96bcace886 100644
--- a/src/api/endpoints/drive/files/create.ts
+++ b/src/api/endpoints/drive/files/create.ts
@@ -2,7 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import { validateFileName }, { pack } from '../../../models/drive-file';
+import { validateFileName, pack } from '../../../models/drive-file';
import create from '../../../common/add-file-to-drive';
/**
diff --git a/src/api/endpoints/drive/files/update.ts b/src/api/endpoints/drive/files/update.ts
index ff65a48f71..83da462113 100644
--- a/src/api/endpoints/drive/files/update.ts
+++ b/src/api/endpoints/drive/files/update.ts
@@ -3,8 +3,7 @@
*/
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
-import DriveFile from '../../../models/drive-file';
-import { validateFileName }, { pack } from '../../../models/drive-file';
+import DriveFile, { validateFileName, pack } from '../../../models/drive-file';
import { publishDriveStream } from '../../../event';
/**
diff --git a/src/api/endpoints/drive/files/upload_from_url.ts b/src/api/endpoints/drive/files/upload_from_url.ts
index 009f06aaaf..68428747ef 100644
--- a/src/api/endpoints/drive/files/upload_from_url.ts
+++ b/src/api/endpoints/drive/files/upload_from_url.ts
@@ -3,7 +3,7 @@
*/
import * as URL from 'url';
import $ from 'cafy';
-import { validateFileName }, { pack } from '../../../models/drive-file';
+import { validateFileName, pack } from '../../../models/drive-file';
import create from '../../../common/add-file-to-drive';
import * as debug from 'debug';
import * as tmp from 'tmp';
diff --git a/src/api/endpoints/drive/folders/create.ts b/src/api/endpoints/drive/folders/create.ts
index 6543b11274..03f396ddc9 100644
--- a/src/api/endpoints/drive/folders/create.ts
+++ b/src/api/endpoints/drive/folders/create.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import DriveFolder from '../../../models/drive-folder';
-import { isValidFolderName }, { pack } from '../../../models/drive-folder';
+import DriveFolder, { isValidFolderName, pack } from '../../../models/drive-folder';
import { publishDriveStream } from '../../../event';
/**
diff --git a/src/api/endpoints/drive/folders/update.ts b/src/api/endpoints/drive/folders/update.ts
index 2adcadcb08..d3df8bdae5 100644
--- a/src/api/endpoints/drive/folders/update.ts
+++ b/src/api/endpoints/drive/folders/update.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import DriveFolder from '../../../models/drive-folder';
-import { isValidFolderName }, { pack } from '../../../models/drive-folder';
+import DriveFolder, { isValidFolderName, pack } from '../../../models/drive-folder';
import { publishDriveStream } from '../../../event';
/**
diff --git a/src/api/endpoints/following/create.ts b/src/api/endpoints/following/create.ts
index b4a2217b16..8e1aa34713 100644
--- a/src/api/endpoints/following/create.ts
+++ b/src/api/endpoints/following/create.ts
@@ -2,11 +2,10 @@
* Module dependencies
*/
import $ from 'cafy';
-import User from '../../models/user';
+import User, { pack as packUser } from '../../models/user';
import Following from '../../models/following';
import notify from '../../common/notify';
import event from '../../event';
-import serializeUser from '../../serializers/user';
/**
* Follow a user
@@ -77,8 +76,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Publish follow event
- event(follower._id, 'follow', await serializeUser(followee, follower));
- event(followee._id, 'followed', await serializeUser(follower, followee));
+ event(follower._id, 'follow', await packUser(followee, follower));
+ event(followee._id, 'followed', await packUser(follower, followee));
// Notify
notify(followee._id, follower._id, 'follow');
diff --git a/src/api/endpoints/following/delete.ts b/src/api/endpoints/following/delete.ts
index aa1639ef6c..b68cec09dd 100644
--- a/src/api/endpoints/following/delete.ts
+++ b/src/api/endpoints/following/delete.ts
@@ -2,10 +2,9 @@
* Module dependencies
*/
import $ from 'cafy';
-import User from '../../models/user';
+import User, { pack as packUser } from '../../models/user';
import Following from '../../models/following';
import event from '../../event';
-import serializeUser from '../../serializers/user';
/**
* Unfollow a user
@@ -78,5 +77,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Publish follow event
- event(follower._id, 'unfollow', await serializeUser(followee, follower));
+ event(follower._id, 'unfollow', await packUser(followee, follower));
});
diff --git a/src/api/endpoints/i/update.ts b/src/api/endpoints/i/update.ts
index cd4b1a13f5..7bbbf95900 100644
--- a/src/api/endpoints/i/update.ts
+++ b/src/api/endpoints/i/update.ts
@@ -2,8 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
-import User from '../../models/user';
-import { isValidName, isValidDescription, isValidLocation, isValidBirthday }, { pack } from '../../models/user';
+import User, { isValidName, isValidDescription, isValidLocation, isValidBirthday, pack } from '../../models/user';
import event from '../../event';
import config from '../../../conf';
diff --git a/src/api/endpoints/posts/reactions/create.ts b/src/api/endpoints/posts/reactions/create.ts
index d537463dfe..0b0e0e294d 100644
--- a/src/api/endpoints/posts/reactions/create.ts
+++ b/src/api/endpoints/posts/reactions/create.ts
@@ -3,13 +3,12 @@
*/
import $ from 'cafy';
import Reaction from '../../../models/post-reaction';
-import Post from '../../../models/post';
+import Post, { pack as packPost } from '../../../models/post';
+import { pack as packUser } from '../../../models/user';
import Watching from '../../../models/post-watching';
import notify from '../../../common/notify';
import watch from '../../../common/watch-post';
import { publishPostStream, pushSw } from '../../../event';
-import serializePost from '../../../serializers/post';
-import serializeUser from '../../../serializers/user';
/**
* React to a post
@@ -90,8 +89,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
pushSw(post.user_id, 'reaction', {
- user: await serializeUser(user, post.user_id),
- post: await serializePost(post, post.user_id),
+ user: await packUser(user, post.user_id),
+ post: await packPost(post, post.user_id),
reaction: reaction
});
diff --git a/src/api/endpoints/users/posts.ts b/src/api/endpoints/users/posts.ts
index 285e5bc46c..0c8bceee3d 100644
--- a/src/api/endpoints/users/posts.ts
+++ b/src/api/endpoints/users/posts.ts
@@ -2,8 +2,8 @@
* Module dependencies
*/
import $ from 'cafy';
-import Post from '../../models/post';
-import User, { pack } from '../../models/user';
+import Post, { pack } from '../../models/post';
+import User from '../../models/user';
/**
* Get posts of a user
diff --git a/src/api/endpoints/users/search.ts b/src/api/endpoints/users/search.ts
index 1142db9e9b..39e2ff9890 100644
--- a/src/api/endpoints/users/search.ts
+++ b/src/api/endpoints/users/search.ts
@@ -51,7 +51,7 @@ async function byNative(res, rej, me, query, offset, max) {
// Serialize
res(await Promise.all(users.map(async user =>
- await serialize(user, me, { detail: true }))));
+ await pack(user, me, { detail: true }))));
}
// Search by Elasticsearch
diff --git a/src/api/models/app.ts b/src/api/models/app.ts
index fe9d49ff67..34e9867db7 100644
--- a/src/api/models/app.ts
+++ b/src/api/models/app.ts
@@ -14,6 +14,7 @@ export type IApp = {
_id: mongo.ObjectID;
created_at: Date;
user_id: mongo.ObjectID;
+ secret: string;
};
export function isValidNameId(nameId: string): boolean {
diff --git a/src/api/models/drive-file.ts b/src/api/models/drive-file.ts
index 9b9df1dac6..2a46d8dc4d 100644
--- a/src/api/models/drive-file.ts
+++ b/src/api/models/drive-file.ts
@@ -23,6 +23,7 @@ export type IDriveFile = {
uploadDate: Date;
md5: string;
filename: string;
+ contentType: string;
metadata: {
properties: any;
user_id: mongodb.ObjectID;
diff --git a/src/api/models/post-reaction.ts b/src/api/models/post-reaction.ts
index 568bfc89a2..639a70e006 100644
--- a/src/api/models/post-reaction.ts
+++ b/src/api/models/post-reaction.ts
@@ -9,6 +9,9 @@ export default PostReaction;
export interface IPostReaction {
_id: mongo.ObjectID;
+ created_at: Date;
+ deleted_at: Date;
+ reaction: string;
}
/**
diff --git a/src/api/models/post.ts b/src/api/models/post.ts
index ecc5e1a5e4..0bbacebf66 100644
--- a/src/api/models/post.ts
+++ b/src/api/models/post.ts
@@ -25,10 +25,12 @@ export type IPost = {
media_ids: mongo.ObjectID[];
reply_id: mongo.ObjectID;
repost_id: mongo.ObjectID;
- poll: {}; // todo
+ poll: any; // todo
text: string;
user_id: mongo.ObjectID;
app_id: mongo.ObjectID;
+ category: string;
+ is_category_verified: boolean;
};
/**
diff --git a/src/api/models/user.ts b/src/api/models/user.ts
index 48a45ac2f7..e92f244dd0 100644
--- a/src/api/models/user.ts
+++ b/src/api/models/user.ts
@@ -42,6 +42,7 @@ export function isValidBirthday(birthday: string): boolean {
export type IUser = {
_id: mongo.ObjectID;
created_at: Date;
+ deleted_at: Date;
email: string;
followers_count: number;
following_count: number;
diff --git a/src/api/private/signup.ts b/src/api/private/signup.ts
index 392f3b1fc7..8efdb6db47 100644
--- a/src/api/private/signup.ts
+++ b/src/api/private/signup.ts
@@ -2,8 +2,7 @@ import * as uuid from 'uuid';
import * as express from 'express';
import * as bcrypt from 'bcryptjs';
import recaptcha = require('recaptcha-promise');
-import { default as User, IUser } from '../models/user';
-import { validateUsername, validatePassword }, { pack } from '../models/user';
+import User, { IUser, validateUsername, validatePassword, pack } from '../models/user';
import generateUserToken from '../common/generate-native-user-token';
import config from '../../conf';
diff --git a/src/api/service/twitter.ts b/src/api/service/twitter.ts
index 7d4964eba6..adcd5ac49b 100644
--- a/src/api/service/twitter.ts
+++ b/src/api/service/twitter.ts
@@ -163,7 +163,7 @@ module.exports = (app: express.Application) => {
res.send(`Twitter: @${result.screenName} を、Misskey: @${user.username} に接続しました!`);
// Publish i updated event
- event(user._id, 'i_updated', await serialize(user, user, {
+ event(user._id, 'i_updated', await pack(user, user, {
detail: true,
includeSecrets: true
}));
diff --git a/src/api/stream/home.ts b/src/api/stream/home.ts
index 7dcdb5ed73..10078337c3 100644
--- a/src/api/stream/home.ts
+++ b/src/api/stream/home.ts
@@ -4,7 +4,7 @@ import * as debug from 'debug';
import User from '../models/user';
import Mute from '../models/mute';
-import serializePost from '../serializers/post';
+import { pack as packPost } from '../models/post';
import readNotification from '../common/read-notification';
const log = debug('misskey');
@@ -49,7 +49,7 @@ export default async function(request: websocket.request, connection: websocket.
case 'post-stream':
const postId = channel.split(':')[2];
log(`RECEIVED: ${postId} ${data} by @${user.username}`);
- const post = await serializePost(postId, user, {
+ const post = await packPost(postId, user, {
detail: true
});
connection.send(JSON.stringify({
--
cgit v1.2.3-freya
From c686a1047248749b21c76fd9f5d867c9324cdd82 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 23 Feb 2018 02:06:35 +0900
Subject: wip
---
src/api/endpoints.ts | 5 ++
src/api/endpoints/i/update.ts | 8 +---
src/api/endpoints/i/update_client_setting.ts | 43 +++++++++++++++++
src/web/app/common/views/components/post-html.ts | 6 ++-
src/web/app/desktop/views/components/home.vue | 54 +++++++++++++---------
.../desktop/views/components/settings-window.vue | 12 +++--
src/web/app/desktop/views/components/settings.vue | 33 ++++++++++++-
7 files changed, 127 insertions(+), 34 deletions(-)
create mode 100644 src/api/endpoints/i/update_client_setting.ts
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts
index e846381578..ff214c3004 100644
--- a/src/api/endpoints.ts
+++ b/src/api/endpoints.ts
@@ -194,6 +194,11 @@ const endpoints: Endpoint[] = [
withCredential: true,
secure: true
},
+ {
+ name: 'i/update_client_setting',
+ withCredential: true,
+ secure: true
+ },
{
name: 'i/pin',
kind: 'account-write'
diff --git a/src/api/endpoints/i/update.ts b/src/api/endpoints/i/update.ts
index 7bbbf95900..43c5245044 100644
--- a/src/api/endpoints/i/update.ts
+++ b/src/api/endpoints/i/update.ts
@@ -46,19 +46,13 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
if (bannerIdErr) return rej('invalid banner_id param');
if (bannerId) user.banner_id = bannerId;
- // Get 'show_donation' parameter
- const [showDonation, showDonationErr] = $(params.show_donation).optional.boolean().$;
- if (showDonationErr) return rej('invalid show_donation param');
- if (showDonation) user.client_settings.show_donation = showDonation;
-
await User.update(user._id, {
$set: {
name: user.name,
description: user.description,
avatar_id: user.avatar_id,
banner_id: user.banner_id,
- profile: user.profile,
- 'client_settings.show_donation': user.client_settings.show_donation
+ profile: user.profile
}
});
diff --git a/src/api/endpoints/i/update_client_setting.ts b/src/api/endpoints/i/update_client_setting.ts
new file mode 100644
index 0000000000..b817ff354c
--- /dev/null
+++ b/src/api/endpoints/i/update_client_setting.ts
@@ -0,0 +1,43 @@
+/**
+ * Module dependencies
+ */
+import $ from 'cafy';
+import User, { pack } from '../../models/user';
+import event from '../../event';
+
+/**
+ * Update myself
+ *
+ * @param {any} params
+ * @param {any} user
+ * @return {Promise}
+ */
+module.exports = async (params, user) => new Promise(async (res, rej) => {
+ // Get 'name' parameter
+ const [name, nameErr] = $(params.name).string().$;
+ if (nameErr) return rej('invalid name param');
+
+ // Get 'value' parameter
+ const [value, valueErr] = $(params.value).nullable.any().$;
+ if (valueErr) return rej('invalid value param');
+
+ const x = {};
+ x[`client_settings.${name}`] = value;
+
+ await User.update(user._id, {
+ $set: x
+ });
+
+ // Serialize
+ user.client_settings[name] = value;
+ const iObj = await pack(user, user, {
+ detail: true,
+ includeSecrets: true
+ });
+
+ // Send response
+ res(iObj);
+
+ // Publish i updated event
+ event(user._id, 'i_updated', iObj);
+});
diff --git a/src/web/app/common/views/components/post-html.ts b/src/web/app/common/views/components/post-html.ts
index afd95f8e38..16d670e851 100644
--- a/src/web/app/common/views/components/post-html.ts
+++ b/src/web/app/common/views/components/post-html.ts
@@ -33,7 +33,11 @@ export default Vue.component('mk-post-html', {
.replace(/(\r\n|\n|\r)/g, '\n');
if ((this as any).shouldBreak) {
- return text.split('\n').map(t => [createElement('span', t), createElement('br')]);
+ if (text.indexOf('\n') != -1) {
+ return text.split('\n').map(t => [createElement('span', t), createElement('br')]);
+ } else {
+ return createElement('span', text);
+ }
} else {
return createElement('span', text.replace(/\n/g, ' '));
}
diff --git a/src/web/app/desktop/views/components/home.vue b/src/web/app/desktop/views/components/home.vue
index eabcc485dd..8a61c378ed 100644
--- a/src/web/app/desktop/views/components/home.vue
+++ b/src/web/app/desktop/views/components/home.vue
@@ -1,7 +1,7 @@
-
%fa:check%完了
+
%fa:check%完了
ウィジェットを追加:
@@ -51,7 +51,11 @@
@@ -59,6 +63,7 @@
+
@@ -126,23 +131,19 @@ export default Vue.extend({
deep: true
});
},
- mounted() {
- this.$nextTick(() => {
- if (this.customize) {
- (this as any).apis.dialog({
- title: '%fa:info-circle%カスタマイズのヒント',
- text: '
ホームのカスタマイズでは、ウィジェットを追加/削除したり、ドラッグ&ドロップして並べ替えたりすることができます。
' +
- '
一部のウィジェットは、右クリックすることで表示を変更することができます。
' +
- '
ウィジェットを削除するには、ヘッダーの「ゴミ箱」と書かれたエリアにウィジェットをドラッグ&ドロップします。
' +
- '
カスタマイズを終了するには、右上の「完了」をクリックします。
',
- actions: [{
- text: 'Got it!'
- }]
- });
- }
- });
- },
methods: {
+ hint() {
+ (this as any).apis.dialog({
+ title: '%fa:info-circle%カスタマイズのヒント',
+ text: '
ホームのカスタマイズでは、ウィジェットを追加/削除したり、ドラッグ&ドロップして並べ替えたりすることができます。
' +
+ '
一部のウィジェットは、右クリックすることで表示を変更することができます。
' +
+ '
ウィジェットを削除するには、ヘッダーの「ゴミ箱」と書かれたエリアにウィジェットをドラッグ&ドロップします。
' +
+ '
カスタマイズを終了するには、右上の「完了」をクリックします。
',
+ actions: [{
+ text: 'Got it!'
+ }]
+ });
+ },
onTlLoaded() {
this.$emit('loaded');
},
@@ -193,10 +194,16 @@ export default Vue.extend({
background-image url('/assets/desktop/grid.svg')
> .main > .main
- cursor not-allowed !important
+ > a
+ display block
+ margin-bottom 8px
+ text-align center
- > *
- pointer-events none
+ > div
+ cursor not-allowed !important
+
+ > *
+ pointer-events none
&:not([data-customize])
> .main > *:empty
@@ -287,6 +294,11 @@ export default Vue.extend({
width calc(100% - 275px * 2)
order 2
+ .mk-post-form
+ margin-bottom 16px
+ border solid 1px #e5e5e5
+ border-radius 4px
+
> *:not(.main)
width 275px
padding 16px 0 16px 0
diff --git a/src/web/app/desktop/views/components/settings-window.vue b/src/web/app/desktop/views/components/settings-window.vue
index c4e1d6a0af..d5be177dcc 100644
--- a/src/web/app/desktop/views/components/settings-window.vue
+++ b/src/web/app/desktop/views/components/settings-window.vue
@@ -1,13 +1,19 @@
-
+
%fa:cog%設定
-
+
--
cgit v1.2.3-freya
From df8a2aea358ca3bcec60c878a6399df46390e3e1 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Sat, 24 Feb 2018 02:46:09 +0900
Subject: Implement #1098
---
src/api/endpoints.ts | 7 +-
src/api/endpoints/i/update_home.ts | 11 +-
src/api/endpoints/i/update_mobile_home.ts | 50 ++++++
src/web/app/common/define-widget.ts | 26 ++-
src/web/app/common/scripts/check-for-update.ts | 4 +-
src/web/app/common/views/components/index.ts | 30 ++++
.../common/views/components/widgets/access-log.vue | 90 ++++++++++
.../common/views/components/widgets/broadcast.vue | 161 +++++++++++++++++
.../common/views/components/widgets/calendar.vue | 199 +++++++++++++++++++++
.../common/views/components/widgets/donation.vue | 58 ++++++
.../app/common/views/components/widgets/nav.vue | 31 ++++
.../views/components/widgets/photo-stream.vue | 104 +++++++++++
.../common/views/components/widgets/profile.vue | 125 +++++++++++++
.../app/common/views/components/widgets/rss.vue | 93 ++++++++++
.../views/components/widgets/server.cpu-memory.vue | 127 +++++++++++++
.../common/views/components/widgets/server.cpu.vue | 68 +++++++
.../views/components/widgets/server.disk.vue | 76 ++++++++
.../views/components/widgets/server.info.vue | 25 +++
.../views/components/widgets/server.memory.vue | 76 ++++++++
.../common/views/components/widgets/server.pie.vue | 61 +++++++
.../views/components/widgets/server.uptimes.vue | 46 +++++
.../app/common/views/components/widgets/server.vue | 93 ++++++++++
.../common/views/components/widgets/slideshow.vue | 153 ++++++++++++++++
.../app/common/views/components/widgets/tips.vue | 108 +++++++++++
.../common/views/components/widgets/version.vue | 28 +++
src/web/app/desktop/views/components/index.ts | 32 +---
.../desktop/views/components/widget-container.vue | 72 ++++++++
.../views/components/widgets/access-log.vue | 108 -----------
.../desktop/views/components/widgets/broadcast.vue | 153 ----------------
.../desktop/views/components/widgets/calendar.vue | 192 --------------------
.../desktop/views/components/widgets/donation.vue | 45 -----
.../app/desktop/views/components/widgets/nav.vue | 29 ---
.../views/components/widgets/photo-stream.vue | 122 -------------
.../desktop/views/components/widgets/profile.vue | 125 -------------
.../app/desktop/views/components/widgets/rss.vue | 111 ------------
.../views/components/widgets/server.cpu-memory.vue | 127 -------------
.../views/components/widgets/server.cpu.vue | 68 -------
.../views/components/widgets/server.disk.vue | 76 --------
.../views/components/widgets/server.info.vue | 25 ---
.../views/components/widgets/server.memory.vue | 76 --------
.../views/components/widgets/server.pie.vue | 61 -------
.../views/components/widgets/server.uptimes.vue | 46 -----
.../desktop/views/components/widgets/server.vue | 131 --------------
.../desktop/views/components/widgets/slideshow.vue | 153 ----------------
.../app/desktop/views/components/widgets/tips.vue | 108 -----------
.../desktop/views/components/widgets/version.vue | 28 ---
src/web/app/mobile/views/components/activity.vue | 62 +++++++
src/web/app/mobile/views/components/home.vue | 29 ---
src/web/app/mobile/views/components/index.ts | 14 +-
src/web/app/mobile/views/components/ui.header.vue | 4 +-
src/web/app/mobile/views/components/ui.vue | 6 +-
.../mobile/views/components/widget-container.vue | 65 +++++++
.../mobile/views/components/widgets/activity.vue | 23 +++
src/web/app/mobile/views/pages/drive.vue | 4 +-
src/web/app/mobile/views/pages/home.vue | 174 +++++++++++++++++-
src/web/app/mobile/views/pages/notifications.vue | 4 +-
src/web/app/mobile/views/pages/user.vue | 1 -
.../app/mobile/views/pages/user/home.activity.vue | 62 -------
src/web/app/mobile/views/pages/user/home.vue | 6 +-
59 files changed, 2252 insertions(+), 1940 deletions(-)
create mode 100644 src/api/endpoints/i/update_mobile_home.ts
create mode 100644 src/web/app/common/views/components/widgets/access-log.vue
create mode 100644 src/web/app/common/views/components/widgets/broadcast.vue
create mode 100644 src/web/app/common/views/components/widgets/calendar.vue
create mode 100644 src/web/app/common/views/components/widgets/donation.vue
create mode 100644 src/web/app/common/views/components/widgets/nav.vue
create mode 100644 src/web/app/common/views/components/widgets/photo-stream.vue
create mode 100644 src/web/app/common/views/components/widgets/profile.vue
create mode 100644 src/web/app/common/views/components/widgets/rss.vue
create mode 100644 src/web/app/common/views/components/widgets/server.cpu-memory.vue
create mode 100644 src/web/app/common/views/components/widgets/server.cpu.vue
create mode 100644 src/web/app/common/views/components/widgets/server.disk.vue
create mode 100644 src/web/app/common/views/components/widgets/server.info.vue
create mode 100644 src/web/app/common/views/components/widgets/server.memory.vue
create mode 100644 src/web/app/common/views/components/widgets/server.pie.vue
create mode 100644 src/web/app/common/views/components/widgets/server.uptimes.vue
create mode 100644 src/web/app/common/views/components/widgets/server.vue
create mode 100644 src/web/app/common/views/components/widgets/slideshow.vue
create mode 100644 src/web/app/common/views/components/widgets/tips.vue
create mode 100644 src/web/app/common/views/components/widgets/version.vue
create mode 100644 src/web/app/desktop/views/components/widget-container.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/access-log.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/broadcast.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/calendar.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/donation.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/nav.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/photo-stream.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/profile.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/rss.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/server.cpu-memory.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/server.cpu.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/server.disk.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/server.info.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/server.memory.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/server.pie.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/server.uptimes.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/server.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/slideshow.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/tips.vue
delete mode 100644 src/web/app/desktop/views/components/widgets/version.vue
create mode 100644 src/web/app/mobile/views/components/activity.vue
delete mode 100644 src/web/app/mobile/views/components/home.vue
create mode 100644 src/web/app/mobile/views/components/widget-container.vue
create mode 100644 src/web/app/mobile/views/components/widgets/activity.vue
delete mode 100644 src/web/app/mobile/views/pages/user/home.activity.vue
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts
index ff214c3004..cbc016f20f 100644
--- a/src/api/endpoints.ts
+++ b/src/api/endpoints.ts
@@ -182,7 +182,12 @@ const endpoints: Endpoint[] = [
{
name: 'i/update_home',
withCredential: true,
- kind: 'account-write'
+ secure: true
+ },
+ {
+ name: 'i/update_mobile_home',
+ withCredential: true,
+ secure: true
},
{
name: 'i/change_password',
diff --git a/src/api/endpoints/i/update_home.ts b/src/api/endpoints/i/update_home.ts
index 429e88529a..5dfb7d7915 100644
--- a/src/api/endpoints/i/update_home.ts
+++ b/src/api/endpoints/i/update_home.ts
@@ -4,16 +4,7 @@
import $ from 'cafy';
import User from '../../models/user';
-/**
- * Update myself
- *
- * @param {any} params
- * @param {any} user
- * @param {any} _
- * @param {boolean} isSecure
- * @return {Promise}
- */
-module.exports = async (params, user, _, isSecure) => new Promise(async (res, rej) => {
+module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'home' parameter
const [home, homeErr] = $(params.home).optional.array().each(
$().strict.object()
diff --git a/src/api/endpoints/i/update_mobile_home.ts b/src/api/endpoints/i/update_mobile_home.ts
new file mode 100644
index 0000000000..a87d89cad7
--- /dev/null
+++ b/src/api/endpoints/i/update_mobile_home.ts
@@ -0,0 +1,50 @@
+/**
+ * Module dependencies
+ */
+import $ from 'cafy';
+import User from '../../models/user';
+
+module.exports = async (params, user) => new Promise(async (res, rej) => {
+ // Get 'home' parameter
+ const [home, homeErr] = $(params.home).optional.array().each(
+ $().strict.object()
+ .have('name', $().string())
+ .have('id', $().string())
+ .have('data', $().object())).$;
+ if (homeErr) return rej('invalid home param');
+
+ // Get 'id' parameter
+ const [id, idErr] = $(params.id).optional.string().$;
+ if (idErr) return rej('invalid id param');
+
+ // Get 'data' parameter
+ const [data, dataErr] = $(params.data).optional.object().$;
+ if (dataErr) return rej('invalid data param');
+
+ if (home) {
+ await User.update(user._id, {
+ $set: {
+ 'client_settings.mobile_home': home
+ }
+ });
+
+ res();
+ } else {
+ if (id == null && data == null) return rej('you need to set id and data params if home param unset');
+
+ const _home = user.client_settings.mobile_home || [];
+ const widget = _home.find(w => w.id == id);
+
+ if (widget == null) return rej('widget not found');
+
+ widget.data = data;
+
+ await User.update(user._id, {
+ $set: {
+ 'client_settings.mobile_home': _home
+ }
+ });
+
+ res();
+ }
+});
diff --git a/src/web/app/common/define-widget.ts b/src/web/app/common/define-widget.ts
index fd13a3395b..60cd1969c0 100644
--- a/src/web/app/common/define-widget.ts
+++ b/src/web/app/common/define-widget.ts
@@ -8,6 +8,10 @@ export default function(data: {
props: {
widget: {
type: Object
+ },
+ isMobile: {
+ type: Boolean,
+ default: false
}
},
computed: {
@@ -21,6 +25,7 @@ export default function(data: {
};
},
created() {
+ if (this.widget.data == null) this.widget.data = {};
if (this.props) {
Object.keys(this.props).forEach(prop => {
if (this.widget.data.hasOwnProperty(prop)) {
@@ -30,12 +35,21 @@ export default function(data: {
}
this.$watch('props', newProps => {
- (this as any).api('i/update_home', {
- id: this.id,
- data: newProps
- }).then(() => {
- (this as any).os.i.client_settings.home.find(w => w.id == this.id).data = newProps;
- });
+ if (this.isMobile) {
+ (this as any).api('i/update_mobile_home', {
+ id: this.id,
+ data: newProps
+ }).then(() => {
+ (this as any).os.i.client_settings.mobile_home.find(w => w.id == this.id).data = newProps;
+ });
+ } else {
+ (this as any).api('i/update_home', {
+ id: this.id,
+ data: newProps
+ }).then(() => {
+ (this as any).os.i.client_settings.home.find(w => w.id == this.id).data = newProps;
+ });
+ }
}, {
deep: true
});
diff --git a/src/web/app/common/scripts/check-for-update.ts b/src/web/app/common/scripts/check-for-update.ts
index 0855676a42..fe539407da 100644
--- a/src/web/app/common/scripts/check-for-update.ts
+++ b/src/web/app/common/scripts/check-for-update.ts
@@ -9,7 +9,9 @@ export default async function(mios: MiOS) {
// Clear cache (serive worker)
try {
- navigator.serviceWorker.controller.postMessage('clear');
+ if (navigator.serviceWorker.controller) {
+ navigator.serviceWorker.controller.postMessage('clear');
+ }
navigator.serviceWorker.getRegistrations().then(registrations => {
registrations.forEach(registration => registration.unregister());
diff --git a/src/web/app/common/views/components/index.ts b/src/web/app/common/views/components/index.ts
index ab0f1767d4..e66a323266 100644
--- a/src/web/app/common/views/components/index.ts
+++ b/src/web/app/common/views/components/index.ts
@@ -21,6 +21,21 @@ import urlPreview from './url-preview.vue';
import twitterSetting from './twitter-setting.vue';
import fileTypeIcon from './file-type-icon.vue';
+//#region widgets
+import wAccessLog from './widgets/access-log.vue';
+import wVersion from './widgets/version.vue';
+import wRss from './widgets/rss.vue';
+import wProfile from './widgets/profile.vue';
+import wServer from './widgets/server.vue';
+import wBroadcast from './widgets/broadcast.vue';
+import wCalendar from './widgets/calendar.vue';
+import wPhotoStream from './widgets/photo-stream.vue';
+import wSlideshow from './widgets/slideshow.vue';
+import wTips from './widgets/tips.vue';
+import wDonation from './widgets/donation.vue';
+import wNav from './widgets/nav.vue';
+//#endregion
+
Vue.component('mk-signin', signin);
Vue.component('mk-signup', signup);
Vue.component('mk-forkit', forkit);
@@ -41,3 +56,18 @@ Vue.component('mk-messaging-room', messagingRoom);
Vue.component('mk-url-preview', urlPreview);
Vue.component('mk-twitter-setting', twitterSetting);
Vue.component('mk-file-type-icon', fileTypeIcon);
+
+//#region widgets
+Vue.component('mkw-nav', wNav);
+Vue.component('mkw-calendar', wCalendar);
+Vue.component('mkw-photo-stream', wPhotoStream);
+Vue.component('mkw-slideshow', wSlideshow);
+Vue.component('mkw-tips', wTips);
+Vue.component('mkw-donation', wDonation);
+Vue.component('mkw-broadcast', wBroadcast);
+Vue.component('mkw-profile', wProfile);
+Vue.component('mkw-server', wServer);
+Vue.component('mkw-rss', wRss);
+Vue.component('mkw-version', wVersion);
+Vue.component('mkw-access-log', wAccessLog);
+//#endregion
diff --git a/src/web/app/common/views/components/widgets/access-log.vue b/src/web/app/common/views/components/widgets/access-log.vue
new file mode 100644
index 0000000000..c810c2d157
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/access-log.vue
@@ -0,0 +1,90 @@
+
+
+
+ %fa:server%%i18n:desktop.tags.mk-access-log-home-widget.title%
+
+
+
+ {{ req.ip }}
+ {{ req.method }}
+ {{ req.path }}
+
+
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/broadcast.vue b/src/web/app/common/views/components/widgets/broadcast.vue
new file mode 100644
index 0000000000..0bb59caf43
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/broadcast.vue
@@ -0,0 +1,161 @@
+
+
+
+
%i18n:desktop.tags.mk-broadcast-home-widget.fetching%
+
{{ broadcasts.length == 0 ? '%i18n:desktop.tags.mk-broadcast-home-widget.no-broadcasts%' : broadcasts[i].title }}
+
+
+ %i18n:desktop.tags.mk-broadcast-home-widget.have-a-nice-day%
+
+
%i18n:desktop.tags.mk-broadcast-home-widget.next% >>
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/calendar.vue b/src/web/app/common/views/components/widgets/calendar.vue
new file mode 100644
index 0000000000..bfcbd7f68d
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/calendar.vue
@@ -0,0 +1,199 @@
+
+
+
+
+ {{ year }}年
+ {{ month }}月
+
+
{{ day }}日
+
{{ weekDay }}曜日
+
+
+
+
今日:{{ dayP.toFixed(1) }}%
+
+
+
+
今月:{{ monthP.toFixed(1) }}%
+
+
+
+
今年:{{ yearP.toFixed(1) }}%
+
+
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/donation.vue b/src/web/app/common/views/components/widgets/donation.vue
new file mode 100644
index 0000000000..08aab8ecd1
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/donation.vue
@@ -0,0 +1,58 @@
+
+
+
+ %fa:heart%%i18n:desktop.tags.mk-donation-home-widget.title%
+
+ {{ '%i18n:desktop.tags.mk-donation-home-widget.text%'.substr(0, '%i18n:desktop.tags.mk-donation-home-widget.text%'.indexOf('{')) }}
+ @syuilo
+ {{ '%i18n:desktop.tags.mk-donation-home-widget.text%'.substr('%i18n:desktop.tags.mk-donation-home-widget.text%'.indexOf('}') + 1) }}
+
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/nav.vue b/src/web/app/common/views/components/widgets/nav.vue
new file mode 100644
index 0000000000..ce88e587a8
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/nav.vue
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/photo-stream.vue b/src/web/app/common/views/components/widgets/photo-stream.vue
new file mode 100644
index 0000000000..dcaa6624dd
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/photo-stream.vue
@@ -0,0 +1,104 @@
+
+
+
+ %fa:camera%%i18n:desktop.tags.mk-photo-stream-home-widget.title%
+
+ %fa:spinner .pulse .fw%%i18n:common.loading%
+
+ %i18n:desktop.tags.mk-photo-stream-home-widget.no-photos%
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/profile.vue b/src/web/app/common/views/components/widgets/profile.vue
new file mode 100644
index 0000000000..68cf469788
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/profile.vue
@@ -0,0 +1,125 @@
+
+
+
+
![クリックでアバター編集 avatar]()
+
{{ os.i.name }}
+
@{{ os.i.username }}
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/rss.vue b/src/web/app/common/views/components/widgets/rss.vue
new file mode 100644
index 0000000000..e80896bea6
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/rss.vue
@@ -0,0 +1,93 @@
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/server.cpu-memory.vue b/src/web/app/common/views/components/widgets/server.cpu-memory.vue
new file mode 100644
index 0000000000..d75a142568
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/server.cpu-memory.vue
@@ -0,0 +1,127 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/server.cpu.vue b/src/web/app/common/views/components/widgets/server.cpu.vue
new file mode 100644
index 0000000000..596c856da8
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/server.cpu.vue
@@ -0,0 +1,68 @@
+
+
+
+
+
%fa:microchip%CPU
+
{{ meta.cpu.cores }} Cores
+
{{ meta.cpu.model }}
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/server.disk.vue b/src/web/app/common/views/components/widgets/server.disk.vue
new file mode 100644
index 0000000000..2af1982a96
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/server.disk.vue
@@ -0,0 +1,76 @@
+
+
+
+
+
%fa:R hdd%Storage
+
Total: {{ total | bytes(1) }}
+
Available: {{ available | bytes(1) }}
+
Used: {{ used | bytes(1) }}
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/server.info.vue b/src/web/app/common/views/components/widgets/server.info.vue
new file mode 100644
index 0000000000..bed6a1b743
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/server.info.vue
@@ -0,0 +1,25 @@
+
+
+
Maintainer: {{ meta.maintainer }}
+
Machine: {{ meta.machine }}
+
Node: {{ meta.node }}
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/server.memory.vue b/src/web/app/common/views/components/widgets/server.memory.vue
new file mode 100644
index 0000000000..834a62671d
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/server.memory.vue
@@ -0,0 +1,76 @@
+
+
+
+
+
%fa:flask%Memory
+
Total: {{ total | bytes(1) }}
+
Used: {{ used | bytes(1) }}
+
Free: {{ free | bytes(1) }}
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/server.pie.vue b/src/web/app/common/views/components/widgets/server.pie.vue
new file mode 100644
index 0000000000..ce2cff1d00
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/server.pie.vue
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/server.uptimes.vue b/src/web/app/common/views/components/widgets/server.uptimes.vue
new file mode 100644
index 0000000000..06713d83ce
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/server.uptimes.vue
@@ -0,0 +1,46 @@
+
+
+
Uptimes
+
Process: {{ process ? process.toFixed(0) : '---' }}s
+
OS: {{ os ? os.toFixed(0) : '---' }}s
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/server.vue b/src/web/app/common/views/components/widgets/server.vue
new file mode 100644
index 0000000000..4ebc5767d6
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/server.vue
@@ -0,0 +1,93 @@
+
+
+
+ %fa:server%%i18n:desktop.tags.mk-server-home-widget.title%
+
+
+ %fa:spinner .pulse .fw%%i18n:common.loading%
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/slideshow.vue b/src/web/app/common/views/components/widgets/slideshow.vue
new file mode 100644
index 0000000000..c2f4eb70d3
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/slideshow.vue
@@ -0,0 +1,153 @@
+
+
+
+
クリックしてフォルダを指定してください
+
このフォルダには画像がありません
+
+
+
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/tips.vue b/src/web/app/common/views/components/widgets/tips.vue
new file mode 100644
index 0000000000..2991fbc3b9
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/tips.vue
@@ -0,0 +1,108 @@
+
+
+
+
+
+
+
diff --git a/src/web/app/common/views/components/widgets/version.vue b/src/web/app/common/views/components/widgets/version.vue
new file mode 100644
index 0000000000..ad2b27bc40
--- /dev/null
+++ b/src/web/app/common/views/components/widgets/version.vue
@@ -0,0 +1,28 @@
+
+ver {{ v }} (葵 aoi)
+
+
+
+
+
diff --git a/src/web/app/desktop/views/components/index.ts b/src/web/app/desktop/views/components/index.ts
index da59d9219e..7584cb4983 100644
--- a/src/web/app/desktop/views/components/index.ts
+++ b/src/web/app/desktop/views/components/index.ts
@@ -27,27 +27,19 @@ import friendsMaker from './friends-maker.vue';
import followers from './followers.vue';
import following from './following.vue';
import usersList from './users-list.vue';
-import wNav from './widgets/nav.vue';
-import wCalendar from './widgets/calendar.vue';
-import wPhotoStream from './widgets/photo-stream.vue';
-import wSlideshow from './widgets/slideshow.vue';
-import wTips from './widgets/tips.vue';
-import wDonation from './widgets/donation.vue';
+import widgetContainer from './widget-container.vue';
+
+//#region widgets
import wNotifications from './widgets/notifications.vue';
-import wBroadcast from './widgets/broadcast.vue';
import wTimemachine from './widgets/timemachine.vue';
-import wProfile from './widgets/profile.vue';
-import wServer from './widgets/server.vue';
import wActivity from './widgets/activity.vue';
-import wRss from './widgets/rss.vue';
import wTrends from './widgets/trends.vue';
-import wVersion from './widgets/version.vue';
import wUsers from './widgets/users.vue';
import wPolls from './widgets/polls.vue';
import wPostForm from './widgets/post-form.vue';
import wMessaging from './widgets/messaging.vue';
import wChannel from './widgets/channel.vue';
-import wAccessLog from './widgets/access-log.vue';
+//#endregion
Vue.component('mk-ui', ui);
Vue.component('mk-ui-notification', uiNotification);
@@ -76,24 +68,16 @@ Vue.component('mk-friends-maker', friendsMaker);
Vue.component('mk-followers', followers);
Vue.component('mk-following', following);
Vue.component('mk-users-list', usersList);
-Vue.component('mkw-nav', wNav);
-Vue.component('mkw-calendar', wCalendar);
-Vue.component('mkw-photo-stream', wPhotoStream);
-Vue.component('mkw-slideshow', wSlideshow);
-Vue.component('mkw-tips', wTips);
-Vue.component('mkw-donation', wDonation);
+Vue.component('mk-widget-container', widgetContainer);
+
+//#region widgets
Vue.component('mkw-notifications', wNotifications);
-Vue.component('mkw-broadcast', wBroadcast);
Vue.component('mkw-timemachine', wTimemachine);
-Vue.component('mkw-profile', wProfile);
-Vue.component('mkw-server', wServer);
Vue.component('mkw-activity', wActivity);
-Vue.component('mkw-rss', wRss);
Vue.component('mkw-trends', wTrends);
-Vue.component('mkw-version', wVersion);
Vue.component('mkw-users', wUsers);
Vue.component('mkw-polls', wPolls);
Vue.component('mkw-post-form', wPostForm);
Vue.component('mkw-messaging', wMessaging);
Vue.component('mkw-channel', wChannel);
-Vue.component('mkw-access-log', wAccessLog);
+//#endregion
diff --git a/src/web/app/desktop/views/components/widget-container.vue b/src/web/app/desktop/views/components/widget-container.vue
new file mode 100644
index 0000000000..7b4e1f55f0
--- /dev/null
+++ b/src/web/app/desktop/views/components/widget-container.vue
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
diff --git a/src/web/app/desktop/views/components/widgets/access-log.vue b/src/web/app/desktop/views/components/widgets/access-log.vue
deleted file mode 100644
index a04da1daaf..0000000000
--- a/src/web/app/desktop/views/components/widgets/access-log.vue
+++ /dev/null
@@ -1,108 +0,0 @@
-
-
-
- %fa:server%%i18n:desktop.tags.mk-access-log-home-widget.title%
-
-
-
- {{ req.ip }}
- {{ req.method }}
- {{ req.path }}
-
-
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/broadcast.vue b/src/web/app/desktop/views/components/widgets/broadcast.vue
deleted file mode 100644
index e4b7e25321..0000000000
--- a/src/web/app/desktop/views/components/widgets/broadcast.vue
+++ /dev/null
@@ -1,153 +0,0 @@
-
-
-
-
%i18n:desktop.tags.mk-broadcast-home-widget.fetching%
-
{{ broadcasts.length == 0 ? '%i18n:desktop.tags.mk-broadcast-home-widget.no-broadcasts%' : broadcasts[i].title }}
-
-
- %i18n:desktop.tags.mk-broadcast-home-widget.have-a-nice-day%
-
-
%i18n:desktop.tags.mk-broadcast-home-widget.next% >>
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/calendar.vue b/src/web/app/desktop/views/components/widgets/calendar.vue
deleted file mode 100644
index c16602db46..0000000000
--- a/src/web/app/desktop/views/components/widgets/calendar.vue
+++ /dev/null
@@ -1,192 +0,0 @@
-
-
-
-
- {{ year }}年
- {{ month }}月
-
-
{{ day }}日
-
{{ weekDay }}曜日
-
-
-
-
今日:{{ dayP.toFixed(1) }}%
-
-
-
-
今月:{{ monthP.toFixed(1) }}%
-
-
-
-
今年:{{ yearP.toFixed(1) }}%
-
-
-
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/donation.vue b/src/web/app/desktop/views/components/widgets/donation.vue
deleted file mode 100644
index fbab0fca6c..0000000000
--- a/src/web/app/desktop/views/components/widgets/donation.vue
+++ /dev/null
@@ -1,45 +0,0 @@
-
-
-
- %fa:heart%%i18n:desktop.tags.mk-donation-home-widget.title%
-
- {{ '%i18n:desktop.tags.mk-donation-home-widget.text%'.substr(0, '%i18n:desktop.tags.mk-donation-home-widget.text%'.indexOf('{')) }}
- @syuilo
- {{ '%i18n:desktop.tags.mk-donation-home-widget.text%'.substr('%i18n:desktop.tags.mk-donation-home-widget.text%'.indexOf('}') + 1) }}
-
-
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/nav.vue b/src/web/app/desktop/views/components/widgets/nav.vue
deleted file mode 100644
index 5e04c266cf..0000000000
--- a/src/web/app/desktop/views/components/widgets/nav.vue
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/photo-stream.vue b/src/web/app/desktop/views/components/widgets/photo-stream.vue
deleted file mode 100644
index 04b71975b3..0000000000
--- a/src/web/app/desktop/views/components/widgets/photo-stream.vue
+++ /dev/null
@@ -1,122 +0,0 @@
-
-
-
%fa:camera%%i18n:desktop.tags.mk-photo-stream-home-widget.title%
-
%fa:spinner .pulse .fw%%i18n:common.loading%
-
-
%i18n:desktop.tags.mk-photo-stream-home-widget.no-photos%
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/profile.vue b/src/web/app/desktop/views/components/widgets/profile.vue
deleted file mode 100644
index 68cf469788..0000000000
--- a/src/web/app/desktop/views/components/widgets/profile.vue
+++ /dev/null
@@ -1,125 +0,0 @@
-
-
-
-
![クリックでアバター編集 avatar]()
-
{{ os.i.name }}
-
@{{ os.i.username }}
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/rss.vue b/src/web/app/desktop/views/components/widgets/rss.vue
deleted file mode 100644
index 3507129716..0000000000
--- a/src/web/app/desktop/views/components/widgets/rss.vue
+++ /dev/null
@@ -1,111 +0,0 @@
-
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/server.cpu-memory.vue b/src/web/app/desktop/views/components/widgets/server.cpu-memory.vue
deleted file mode 100644
index d75a142568..0000000000
--- a/src/web/app/desktop/views/components/widgets/server.cpu-memory.vue
+++ /dev/null
@@ -1,127 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/server.cpu.vue b/src/web/app/desktop/views/components/widgets/server.cpu.vue
deleted file mode 100644
index 596c856da8..0000000000
--- a/src/web/app/desktop/views/components/widgets/server.cpu.vue
+++ /dev/null
@@ -1,68 +0,0 @@
-
-
-
-
-
%fa:microchip%CPU
-
{{ meta.cpu.cores }} Cores
-
{{ meta.cpu.model }}
-
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/server.disk.vue b/src/web/app/desktop/views/components/widgets/server.disk.vue
deleted file mode 100644
index 2af1982a96..0000000000
--- a/src/web/app/desktop/views/components/widgets/server.disk.vue
+++ /dev/null
@@ -1,76 +0,0 @@
-
-
-
-
-
%fa:R hdd%Storage
-
Total: {{ total | bytes(1) }}
-
Available: {{ available | bytes(1) }}
-
Used: {{ used | bytes(1) }}
-
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/server.info.vue b/src/web/app/desktop/views/components/widgets/server.info.vue
deleted file mode 100644
index bed6a1b743..0000000000
--- a/src/web/app/desktop/views/components/widgets/server.info.vue
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
Maintainer: {{ meta.maintainer }}
-
Machine: {{ meta.machine }}
-
Node: {{ meta.node }}
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/server.memory.vue b/src/web/app/desktop/views/components/widgets/server.memory.vue
deleted file mode 100644
index 834a62671d..0000000000
--- a/src/web/app/desktop/views/components/widgets/server.memory.vue
+++ /dev/null
@@ -1,76 +0,0 @@
-
-
-
-
-
%fa:flask%Memory
-
Total: {{ total | bytes(1) }}
-
Used: {{ used | bytes(1) }}
-
Free: {{ free | bytes(1) }}
-
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/server.pie.vue b/src/web/app/desktop/views/components/widgets/server.pie.vue
deleted file mode 100644
index ce2cff1d00..0000000000
--- a/src/web/app/desktop/views/components/widgets/server.pie.vue
+++ /dev/null
@@ -1,61 +0,0 @@
-
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/server.uptimes.vue b/src/web/app/desktop/views/components/widgets/server.uptimes.vue
deleted file mode 100644
index 06713d83ce..0000000000
--- a/src/web/app/desktop/views/components/widgets/server.uptimes.vue
+++ /dev/null
@@ -1,46 +0,0 @@
-
-
-
Uptimes
-
Process: {{ process ? process.toFixed(0) : '---' }}s
-
OS: {{ os ? os.toFixed(0) : '---' }}s
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/server.vue b/src/web/app/desktop/views/components/widgets/server.vue
deleted file mode 100644
index 1c0da84225..0000000000
--- a/src/web/app/desktop/views/components/widgets/server.vue
+++ /dev/null
@@ -1,131 +0,0 @@
-
-
-
- %fa:server%%i18n:desktop.tags.mk-server-home-widget.title%
-
-
-
%fa:spinner .pulse .fw%%i18n:common.loading%
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/slideshow.vue b/src/web/app/desktop/views/components/widgets/slideshow.vue
deleted file mode 100644
index c2f4eb70d3..0000000000
--- a/src/web/app/desktop/views/components/widgets/slideshow.vue
+++ /dev/null
@@ -1,153 +0,0 @@
-
-
-
-
クリックしてフォルダを指定してください
-
このフォルダには画像がありません
-
-
-
-
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/tips.vue b/src/web/app/desktop/views/components/widgets/tips.vue
deleted file mode 100644
index 2991fbc3b9..0000000000
--- a/src/web/app/desktop/views/components/widgets/tips.vue
+++ /dev/null
@@ -1,108 +0,0 @@
-
-
-
-
-
-
-
diff --git a/src/web/app/desktop/views/components/widgets/version.vue b/src/web/app/desktop/views/components/widgets/version.vue
deleted file mode 100644
index ad2b27bc40..0000000000
--- a/src/web/app/desktop/views/components/widgets/version.vue
+++ /dev/null
@@ -1,28 +0,0 @@
-
-ver {{ v }} (葵 aoi)
-
-
-
-
-
diff --git a/src/web/app/mobile/views/components/activity.vue b/src/web/app/mobile/views/components/activity.vue
new file mode 100644
index 0000000000..b50044b3de
--- /dev/null
+++ b/src/web/app/mobile/views/components/activity.vue
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/web/app/mobile/views/components/home.vue b/src/web/app/mobile/views/components/home.vue
deleted file mode 100644
index 3feab581d2..0000000000
--- a/src/web/app/mobile/views/components/home.vue
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/src/web/app/mobile/views/components/index.ts b/src/web/app/mobile/views/components/index.ts
index 905baaf20d..d372f22332 100644
--- a/src/web/app/mobile/views/components/index.ts
+++ b/src/web/app/mobile/views/components/index.ts
@@ -1,7 +1,6 @@
import Vue from 'vue';
import ui from './ui.vue';
-import home from './home.vue';
import timeline from './timeline.vue';
import posts from './posts.vue';
import imagesImage from './images-image.vue';
@@ -19,9 +18,14 @@ import notificationPreview from './notification-preview.vue';
import usersList from './users-list.vue';
import userPreview from './user-preview.vue';
import userTimeline from './user-timeline.vue';
+import activity from './activity.vue';
+import widgetContainer from './widget-container.vue';
+
+//#region widgets
+import wActivity from './widgets/activity.vue';
+//#endregion
Vue.component('mk-ui', ui);
-Vue.component('mk-home', home);
Vue.component('mk-timeline', timeline);
Vue.component('mk-posts', posts);
Vue.component('mk-images-image', imagesImage);
@@ -39,3 +43,9 @@ Vue.component('mk-notification-preview', notificationPreview);
Vue.component('mk-users-list', usersList);
Vue.component('mk-user-preview', userPreview);
Vue.component('mk-user-timeline', userTimeline);
+Vue.component('mk-activity', activity);
+Vue.component('mk-widget-container', widgetContainer);
+
+//#region widgets
+Vue.component('mkw-activity', wActivity);
+//#endregion
diff --git a/src/web/app/mobile/views/components/ui.header.vue b/src/web/app/mobile/views/components/ui.header.vue
index 2df5ea162e..026e7eb1b4 100644
--- a/src/web/app/mobile/views/components/ui.header.vue
+++ b/src/web/app/mobile/views/components/ui.header.vue
@@ -9,9 +9,7 @@
Misskey
-
+
diff --git a/src/web/app/mobile/views/components/ui.vue b/src/web/app/mobile/views/components/ui.vue
index 91d7ea29b6..325ce9d40e 100644
--- a/src/web/app/mobile/views/components/ui.vue
+++ b/src/web/app/mobile/views/components/ui.vue
@@ -1,7 +1,7 @@
-
-
+
+
@@ -23,7 +23,7 @@ export default Vue.extend({
XHeader,
XNav
},
- props: ['title', 'func'],
+ props: ['title'],
data() {
return {
isDrawerOpening: false,
diff --git a/src/web/app/mobile/views/components/widget-container.vue b/src/web/app/mobile/views/components/widget-container.vue
new file mode 100644
index 0000000000..1775188a93
--- /dev/null
+++ b/src/web/app/mobile/views/components/widget-container.vue
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
diff --git a/src/web/app/mobile/views/components/widgets/activity.vue b/src/web/app/mobile/views/components/widgets/activity.vue
new file mode 100644
index 0000000000..c3fe63f264
--- /dev/null
+++ b/src/web/app/mobile/views/components/widgets/activity.vue
@@ -0,0 +1,23 @@
+
+
+
+ %fa:chart-bar%アクティビティ
+
+
+
+
+
+
+
+
+
+
diff --git a/src/web/app/mobile/views/pages/drive.vue b/src/web/app/mobile/views/pages/drive.vue
index 47aeb52f49..ea61661cf6 100644
--- a/src/web/app/mobile/views/pages/drive.vue
+++ b/src/web/app/mobile/views/pages/drive.vue
@@ -1,11 +1,11 @@
-
+
%fa:R folder-open%{{ folder.name }}
{{ file.name }}
%fa:cloud%%i18n:mobile.tags.mk-drive-page.drive%
- %fa:ellipsis-h%
+
-
- %fa:home%%i18n:mobile.tags.mk-home.home%
- %fa:pencil-alt%
-
+
+
+ %fa:home%タイムライン
+ %fa:home%ウィジェット
+
+ %fa:angle-down%
+ %fa:angle-up%
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/web/app/mobile/views/pages/notifications.vue b/src/web/app/mobile/views/pages/notifications.vue
index b1243dbc74..3dcfb2f38c 100644
--- a/src/web/app/mobile/views/pages/notifications.vue
+++ b/src/web/app/mobile/views/pages/notifications.vue
@@ -1,7 +1,7 @@
-
+
%fa:R bell%%i18n:mobile.tags.mk-notifications-page.notifications%
- %fa:check%
+
diff --git a/src/web/app/mobile/views/pages/user.vue b/src/web/app/mobile/views/pages/user.vue
index 27f65e623d..378beeaf13 100644
--- a/src/web/app/mobile/views/pages/user.vue
+++ b/src/web/app/mobile/views/pages/user.vue
@@ -1,7 +1,6 @@
%fa:user% {{ user.name }}
- %fa:pencil-alt%
diff --git a/src/web/app/mobile/views/pages/user/home.activity.vue b/src/web/app/mobile/views/pages/user/home.activity.vue
deleted file mode 100644
index 87970795b2..0000000000
--- a/src/web/app/mobile/views/pages/user/home.activity.vue
+++ /dev/null
@@ -1,62 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/src/web/app/mobile/views/pages/user/home.vue b/src/web/app/mobile/views/pages/user/home.vue
index 4c68317879..fdbfd1bf55 100644
--- a/src/web/app/mobile/views/pages/user/home.vue
+++ b/src/web/app/mobile/views/pages/user/home.vue
@@ -16,7 +16,7 @@
%fa:chart-bar%%i18n:mobile.tags.mk-user-overview.activity%
-
+
@@ -41,15 +41,13 @@ import XPosts from './home.posts.vue';
import XPhotos from './home.photos.vue';
import XFriends from './home.friends.vue';
import XFollowersYouKnow from './home.followers-you-know.vue';
-import XActivity from './home.activity.vue';
export default Vue.extend({
components: {
XPosts,
XPhotos,
XFriends,
- XFollowersYouKnow,
- XActivity
+ XFollowersYouKnow
},
props: ['user']
});
--
cgit v1.2.3-freya
From a2ed259501f58008af4c61321549c83b9b5358e7 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Sat, 24 Feb 2018 07:49:03 +0900
Subject: :v:
---
src/api/endpoints/i/update_home.ts | 9 ++++++++
src/api/endpoints/i/update_mobile_home.ts | 9 ++++++++
src/web/app/common/define-widget.ts | 24 +++++++++++++++++----
src/web/app/desktop/views/components/home.vue | 30 ++++++++++++++++++++++++++-
src/web/app/desktop/views/components/index.ts | 2 ++
src/web/app/mobile/views/pages/home.vue | 18 +++++++++++++++-
6 files changed, 86 insertions(+), 6 deletions(-)
(limited to 'src/api/endpoints')
diff --git a/src/api/endpoints/i/update_home.ts b/src/api/endpoints/i/update_home.ts
index 5dfb7d7915..394686cbd1 100644
--- a/src/api/endpoints/i/update_home.ts
+++ b/src/api/endpoints/i/update_home.ts
@@ -3,6 +3,7 @@
*/
import $ from 'cafy';
import User from '../../models/user';
+import event from '../../event';
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'home' parameter
@@ -30,6 +31,10 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
});
res();
+
+ event(user._id, 'home_updated', {
+ home
+ });
} else {
if (id == null && data == null) return rej('you need to set id and data params if home param unset');
@@ -47,5 +52,9 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
});
res();
+
+ event(user._id, 'home_updated', {
+ id, data
+ });
}
});
diff --git a/src/api/endpoints/i/update_mobile_home.ts b/src/api/endpoints/i/update_mobile_home.ts
index a87d89cad7..70181431a2 100644
--- a/src/api/endpoints/i/update_mobile_home.ts
+++ b/src/api/endpoints/i/update_mobile_home.ts
@@ -3,6 +3,7 @@
*/
import $ from 'cafy';
import User from '../../models/user';
+import event from '../../event';
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'home' parameter
@@ -29,6 +30,10 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
});
res();
+
+ event(user._id, 'mobile_home_updated', {
+ home
+ });
} else {
if (id == null && data == null) return rej('you need to set id and data params if home param unset');
@@ -46,5 +51,9 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
});
res();
+
+ event(user._id, 'mobile_home_updated', {
+ id, data
+ });
}
});
diff --git a/src/web/app/common/define-widget.ts b/src/web/app/common/define-widget.ts
index 21821629ad..844603daa3 100644
--- a/src/web/app/common/define-widget.ts
+++ b/src/web/app/common/define-widget.ts
@@ -21,7 +21,9 @@ export default function(data: {
},
data() {
return {
- props: data.props ? data.props() : {} as T
+ props: data.props ? data.props() : {} as T,
+ bakedOldProps: null,
+ preventSave: false
};
},
created() {
@@ -33,26 +35,40 @@ export default function(data: {
});
}
+ this.bakeProps();
+
this.$watch('props', newProps => {
- const w = (this as any).os.i.client_settings.mobile_home.find(w => w.id == this.id);
+ if (this.preventSave) {
+ this.preventSave = false;
+ return;
+ }
+ if (this.bakedOldProps == JSON.stringify(newProps)) return;
+
+ this.bakeProps();
+
if (this.isMobile) {
(this as any).api('i/update_mobile_home', {
id: this.id,
data: newProps
}).then(() => {
- w.data = newProps;
+ (this as any).os.i.client_settings.mobile_home.find(w => w.id == this.id).data = newProps;
});
} else {
(this as any).api('i/update_home', {
id: this.id,
data: newProps
}).then(() => {
- w.data = newProps;
+ (this as any).os.i.client_settings.home.find(w => w.id == this.id).data = newProps;
});
}
}, {
deep: true
});
+ },
+ methods: {
+ bakeProps() {
+ this.bakedOldProps = JSON.stringify(this.props);
+ }
}
});
}
diff --git a/src/web/app/desktop/views/components/home.vue b/src/web/app/desktop/views/components/home.vue
index 8a61c378ed..d64d836982 100644
--- a/src/web/app/desktop/views/components/home.vue
+++ b/src/web/app/desktop/views/components/home.vue
@@ -60,7 +60,7 @@
-
+
@@ -90,6 +90,8 @@ export default Vue.extend({
},
data() {
return {
+ connection: null,
+ connectionId: null,
widgetAdderSelected: null,
trash: [],
widgets: {
@@ -131,6 +133,16 @@ export default Vue.extend({
deep: true
});
},
+ mounted() {
+ this.connection = (this as any).os.stream.getConnection();
+ this.connectionId = (this as any).os.stream.use();
+
+ this.connection.on('home_updated', this.onHomeUpdated);
+ },
+ beforeDestroy() {
+ this.connection.off('home_updated', this.onHomeUpdated);
+ (this as any).os.stream.dispose(this.connectionId);
+ },
methods: {
hint() {
(this as any).apis.dialog({
@@ -147,6 +159,22 @@ export default Vue.extend({
onTlLoaded() {
this.$emit('loaded');
},
+ onHomeUpdated(data) {
+ if (data.home) {
+ (this as any).os.i.client_settings.home = data.home;
+ this.widgets.left = data.home.filter(w => w.place == 'left');
+ this.widgets.right = data.home.filter(w => w.place == 'right');
+ } else {
+ const w = (this as any).os.i.client_settings.home.find(w => w.id == data.id);
+ if (w != null) {
+ w.data = data.data;
+ this.$refs[w.id][0].preventSave = true;
+ this.$refs[w.id][0].props = w.data;
+ this.widgets.left = (this as any).os.i.client_settings.home.filter(w => w.place == 'left');
+ this.widgets.right = (this as any).os.i.client_settings.home.filter(w => w.place == 'right');
+ }
+ }
+ },
onWidgetContextmenu(widgetId) {
const w = (this.$refs[widgetId] as any)[0];
if (w.func) w.func();
diff --git a/src/web/app/desktop/views/components/index.ts b/src/web/app/desktop/views/components/index.ts
index 7584cb4983..5cb09e0319 100644
--- a/src/web/app/desktop/views/components/index.ts
+++ b/src/web/app/desktop/views/components/index.ts
@@ -39,6 +39,7 @@ import wPolls from './widgets/polls.vue';
import wPostForm from './widgets/post-form.vue';
import wMessaging from './widgets/messaging.vue';
import wChannel from './widgets/channel.vue';
+import wProfile from './widgets/profile.vue';
//#endregion
Vue.component('mk-ui', ui);
@@ -80,4 +81,5 @@ Vue.component('mkw-polls', wPolls);
Vue.component('mkw-post-form', wPostForm);
Vue.component('mkw-messaging', wMessaging);
Vue.component('mkw-channel', wChannel);
+Vue.component('mkw-profile', wProfile);
//#endregion
diff --git a/src/web/app/mobile/views/pages/home.vue b/src/web/app/mobile/views/pages/home.vue
index 5e80bbcebf..f4f458068a 100644
--- a/src/web/app/mobile/views/pages/home.vue
+++ b/src/web/app/mobile/views/pages/home.vue
@@ -51,7 +51,7 @@
-
+
@@ -124,12 +124,14 @@ export default Vue.extend({
this.connectionId = (this as any).os.stream.use();
this.connection.on('post', this.onStreamPost);
+ this.connection.on('mobile_home_updated', this.onHomeUpdated);
document.addEventListener('visibilitychange', this.onVisibilitychange, false);
Progress.start();
},
beforeDestroy() {
this.connection.off('post', this.onStreamPost);
+ this.connection.off('mobile_home_updated', this.onHomeUpdated);
(this as any).os.stream.dispose(this.connectionId);
document.removeEventListener('visibilitychange', this.onVisibilitychange);
},
@@ -152,6 +154,20 @@ export default Vue.extend({
document.title = 'Misskey';
}
},
+ onHomeUpdated(data) {
+ if (data.home) {
+ (this as any).os.i.client_settings.mobile_home = data.home;
+ this.widgets = data.home;
+ } else {
+ const w = (this as any).os.i.client_settings.mobile_home.find(w => w.id == data.id);
+ if (w != null) {
+ w.data = data.data;
+ this.$refs[w.id][0].preventSave = true;
+ this.$refs[w.id][0].props = w.data;
+ this.widgets = (this as any).os.i.client_settings.mobile_home;
+ }
+ }
+ },
hint() {
alert('ウィジェットを追加/削除したり並べ替えたりできます。ウィジェットを移動するには「三」をドラッグします。ウィジェットを削除するには「x」をタップします。いくつかのウィジェットはタップすることで表示を変更できます。');
},
--
cgit v1.2.3-freya
From 3ae824c3542b0e232b9847ae702956e631acb276 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Mon, 26 Feb 2018 00:39:05 +0900
Subject: :v:
---
src/api/endpoints/posts/create.ts | 24 ++++++++-
.../app/desktop/views/components/post-detail.vue | 29 +++++++++++
.../app/desktop/views/components/posts.post.vue | 35 +++++++++++--
src/web/app/desktop/views/components/timeline.vue | 14 ++++-
src/web/app/desktop/views/pages/search.vue | 55 ++++++++++++++------
.../app/mobile/views/components/post-detail.vue | 25 +++++++++
src/web/app/mobile/views/components/posts.post.vue | 30 +++++++++--
src/web/app/mobile/views/pages/search.vue | 59 +++++++++++++++-------
8 files changed, 227 insertions(+), 44 deletions(-)
(limited to 'src/api/endpoints')
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
diff --git a/src/web/app/desktop/views/components/post-detail.vue b/src/web/app/desktop/views/components/post-detail.vue
index c453867dfb..1e31752fe7 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 }}
+
%fa:reply%
+
+ {{ tag }}
+
RP:
@@ -342,9 +345,9 @@ export default Vue.extend({
display block
float left
margin 0 16px 10px 0
- position -webkit-sticky
- position sticky
- top 74px
+ //position -webkit-sticky
+ //position sticky
+ //top 74px
> .avatar
display block
@@ -428,6 +431,32 @@ export default Vue.extend({
font-style oblique
color #a0bf46
+ > .tags
+ > *
+ margin 0 8px 0 0
+ padding 0 8px 0 16px
+ font-size 90%
+ color #8d969e
+ background #edf0f3
+ border-radius 4px
+
+ &:before
+ content ""
+ display block
+ position absolute
+ top 0
+ bottom 0
+ left 4px
+ width 8px
+ height 8px
+ margin auto 0
+ background #fff
+ border-radius 100%
+
+ &:hover
+ text-decoration none
+ background #e2e7ec
+
> .mk-poll
font-size 80%
diff --git a/src/web/app/desktop/views/components/timeline.vue b/src/web/app/desktop/views/components/timeline.vue
index eef62104eb..0d16d60df9 100644
--- a/src/web/app/desktop/views/components/timeline.vue
+++ b/src/web/app/desktop/views/components/timeline.vue
@@ -24,6 +24,7 @@ export default Vue.extend({
return {
fetching: true,
moreFetching: false,
+ existMore: false,
posts: [],
connection: null,
connectionId: null,
@@ -62,8 +63,13 @@ export default Vue.extend({
this.fetching = true;
(this as any).api('posts/timeline', {
+ limit: 11,
until_date: this.date ? this.date.getTime() : undefined
}).then(posts => {
+ if (posts.length == 11) {
+ posts.pop();
+ this.existMore = true;
+ }
this.posts = posts;
this.fetching = false;
this.$emit('loaded');
@@ -71,11 +77,17 @@ export default Vue.extend({
});
},
more() {
- if (this.moreFetching || this.fetching || this.posts.length == 0) return;
+ if (this.moreFetching || this.fetching || this.posts.length == 0 || !this.existMore) return;
this.moreFetching = true;
(this as any).api('posts/timeline', {
+ limit: 11,
until_id: this.posts[this.posts.length - 1].id
}).then(posts => {
+ if (posts.length == 11) {
+ posts.pop();
+ } else {
+ this.existMore = false;
+ }
this.posts = this.posts.concat(posts);
this.moreFetching = false;
});
diff --git a/src/web/app/desktop/views/pages/search.vue b/src/web/app/desktop/views/pages/search.vue
index b8e8db2e79..afd37c8cee 100644
--- a/src/web/app/desktop/views/pages/search.vue
+++ b/src/web/app/desktop/views/pages/search.vue
@@ -1,13 +1,13 @@
- %fa:search%「{{ query }}」に関する投稿は見つかりませんでした。
-
+ %fa:search%「{{ q }}」に関する投稿は見つかりませんでした。
+
%fa:search%
%fa:spinner .pulse .fw%
@@ -21,33 +21,34 @@ import Vue from 'vue';
import Progress from '../../../common/scripts/loading';
import parse from '../../../common/scripts/parse-search-query';
-const limit = 30;
+const limit = 20;
export default Vue.extend({
- props: ['query'],
data() {
return {
fetching: true,
moreFetching: false,
+ existMore: false,
offset: 0,
posts: []
};
},
+ watch: {
+ $route: 'fetch'
+ },
computed: {
empty(): boolean {
return this.posts.length == 0;
+ },
+ q(): string {
+ return this.$route.query.q;
}
},
mounted() {
- Progress.start();
-
document.addEventListener('keydown', this.onDocumentKeydown);
window.addEventListener('scroll', this.onScroll);
- (this as any).api('posts/search', parse(this.query)).then(posts => {
- this.posts = posts;
- this.fetching = false;
- });
+ this.fetch();
},
beforeDestroy() {
document.removeEventListener('keydown', this.onDocumentKeydown);
@@ -61,16 +62,38 @@ export default Vue.extend({
}
}
},
+ fetch() {
+ this.fetching = true;
+ Progress.start();
+
+ (this as any).api('posts/search', Object.assign({
+ limit: limit + 1,
+ offset: this.offset
+ }, parse(this.q))).then(posts => {
+ if (posts.length == limit + 1) {
+ posts.pop();
+ this.existMore = true;
+ }
+ this.posts = posts;
+ this.fetching = false;
+ Progress.done();
+ });
+ },
more() {
- if (this.moreFetching || this.fetching || this.posts.length == 0) return;
+ if (this.moreFetching || this.fetching || this.posts.length == 0 || !this.existMore) return;
this.offset += limit;
this.moreFetching = true;
- return (this as any).api('posts/search', Object.assign({}, parse(this.query), {
- limit: limit,
+ return (this as any).api('posts/search', Object.assign({
+ limit: limit + 1,
offset: this.offset
- })).then(posts => {
- this.moreFetching = false;
+ }, parse(this.q))).then(posts => {
+ if (posts.length == limit + 1) {
+ posts.pop();
+ } else {
+ this.existMore = false;
+ }
this.posts = this.posts.concat(posts);
+ this.moreFetching = false;
});
},
onScroll() {
diff --git a/src/web/app/mobile/views/components/post-detail.vue b/src/web/app/mobile/views/components/post-detail.vue
index 05138607ff..a83744ec4d 100644
--- a/src/web/app/mobile/views/components/post-detail.vue
+++ b/src/web/app/mobile/views/components/post-detail.vue
@@ -39,6 +39,9 @@
+
+ {{ tag }}
+
@@ -346,10 +349,7 @@ export default Vue.extend({
font-size 1.1em
color #717171
- > .dummy
- display none
-
- mk-url-preview
+ .mk-url-preview
margin-top 8px
> .channel
@@ -364,6 +364,28 @@ export default Vue.extend({
font-style oblique
color #a0bf46
+ > .tags
+ > *
+ margin 0 8px 0 0
+ padding 0 8px 0 16px
+ font-size 90%
+ color #8d969e
+ background #edf0f3
+ border-radius 4px
+
+ &:before
+ content ""
+ display block
+ position absolute
+ top 0
+ bottom 0
+ left 4px
+ width 8px
+ height 8px
+ margin auto 0
+ background #fff
+ border-radius 100%
+
[data-is-me]:after
content "you"
padding 0 4px
diff --git a/src/web/app/mobile/views/pages/search.vue b/src/web/app/mobile/views/pages/search.vue
index b6e114a82b..cbab504e3c 100644
--- a/src/web/app/mobile/views/pages/search.vue
+++ b/src/web/app/mobile/views/pages/search.vue
@@ -1,10 +1,10 @@
- %fa:search% {{ query }}
+ %fa:search% {{ q }}
- {{ '%i18n:mobile.tags.mk-search-posts.empty%'.replace('{}', query) }}
-
- {{ tag }}
+ {{ tag }}