forked from FoundKeyGang/FoundKey
This commit is contained in:
parent
1b5d788c6c
commit
59120063fe
3 changed files with 24 additions and 3 deletions
|
@ -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({
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -21,6 +21,9 @@ section
|
|||
tr
|
||||
td user
|
||||
td ユーザー名。投稿者を限定します。
|
||||
tr
|
||||
td follow
|
||||
td フォローしているユーザーのみに限定。(trueかfalse)
|
||||
tr
|
||||
td reply
|
||||
td 返信を含めるか否か。(trueかfalse)
|
||||
|
|
Loading…
Reference in a new issue