mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 19:13:08 +02:00
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');
|
const escapeRegexp = require('escape-regexp');
|
||||||
import Post from '../../models/post';
|
import Post from '../../models/post';
|
||||||
import User from '../../models/user';
|
import User from '../../models/user';
|
||||||
|
import getFriends from '../../common/get-friends';
|
||||||
import serialize from '../../serializers/post';
|
import serialize from '../../serializers/post';
|
||||||
import config from '../../../conf';
|
import config from '../../../conf';
|
||||||
|
|
||||||
|
@ -29,6 +30,10 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||||
const [username, usernameErr] = $(params.username).optional.string().$;
|
const [username, usernameErr] = $(params.username).optional.string().$;
|
||||||
if (usernameErr) return rej('invalid username param');
|
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
|
// Get 'include_replies' parameter
|
||||||
const [includeReplies = true, includeRepliesErr] = $(params.include_replies).optional.boolean().$;
|
const [includeReplies = true, includeRepliesErr] = $(params.include_replies).optional.boolean().$;
|
||||||
if (includeRepliesErr) return rej('invalid include_replies param');
|
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 Elasticsearch is available, search by it
|
||||||
// If not, search by MongoDB
|
// If not, search by MongoDB
|
||||||
(config.elasticsearch.enable ? byElasticsearch : byNative)
|
(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
|
// 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 = {};
|
const q: any = {};
|
||||||
|
|
||||||
if (text) {
|
if (text) {
|
||||||
|
@ -84,6 +89,16 @@ async function byNative(res, rej, me, text, userId, includeReplies, withMedia, s
|
||||||
q.user_id = userId;
|
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) {
|
if (!includeReplies) {
|
||||||
q.reply_id = null;
|
q.reply_id = null;
|
||||||
}
|
}
|
||||||
|
@ -122,7 +137,7 @@ async function byNative(res, rej, me, text, userId, includeReplies, withMedia, s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search by Elasticsearch
|
// 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');
|
const es = require('../../db/elasticsearch');
|
||||||
|
|
||||||
es.search({
|
es.search({
|
||||||
|
|
|
@ -10,6 +10,9 @@ export default function(qs: string) {
|
||||||
case 'user':
|
case 'user':
|
||||||
q['username'] = value;
|
q['username'] = value;
|
||||||
break;
|
break;
|
||||||
|
case 'follow':
|
||||||
|
q['following'] = value == 'null' ? null : value == 'true';
|
||||||
|
break;
|
||||||
case 'reply':
|
case 'reply':
|
||||||
q['include_replies'] = value == 'true';
|
q['include_replies'] = value == 'true';
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -21,6 +21,9 @@ section
|
||||||
tr
|
tr
|
||||||
td user
|
td user
|
||||||
td ユーザー名。投稿者を限定します。
|
td ユーザー名。投稿者を限定します。
|
||||||
|
tr
|
||||||
|
td follow
|
||||||
|
td フォローしているユーザーのみに限定。(trueかfalse)
|
||||||
tr
|
tr
|
||||||
td reply
|
td reply
|
||||||
td 返信を含めるか否か。(trueかfalse)
|
td 返信を含めるか否か。(trueかfalse)
|
||||||
|
|
Loading…
Reference in a new issue