summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorこぴなたみぽ <syuilotan@yahoo.co.jp>2017-12-21 06:31:56 +0900
committerこぴなたみぽ <syuilotan@yahoo.co.jp>2017-12-21 06:31:56 +0900
commit59120063fe792ba0bc230749a36b1e4acf86443f (patch)
treec5975ea95f7b7cd11f9f9f7736d02ac5b33cb81e
parentv3420 (diff)
downloadmisskey-59120063fe792ba0bc230749a36b1e4acf86443f.tar.gz
misskey-59120063fe792ba0bc230749a36b1e4acf86443f.tar.bz2
misskey-59120063fe792ba0bc230749a36b1e4acf86443f.zip
#1023
-rw-r--r--src/api/endpoints/posts/search.ts21
-rw-r--r--src/web/app/common/scripts/parse-search-query.ts3
-rw-r--r--src/web/docs/search.ja.pug3
3 files changed, 24 insertions, 3 deletions
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
@@ -22,6 +22,9 @@ section
td user
td ユーザー名。投稿者を限定します。
tr
+ td follow
+ td フォローしているユーザーのみに限定。(trueかfalse)
+ tr
td reply
td 返信を含めるか否か。(trueかfalse)
tr