mirror of
https://github.com/MisskeyIO/misskey
synced 2024-12-01 08:18:41 +09:00
wip
This commit is contained in:
parent
a134aa5a81
commit
26b40d8886
@ -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 Mute from '../../models/mute';
|
||||||
import getFriends from '../../common/get-friends';
|
import getFriends from '../../common/get-friends';
|
||||||
import serialize from '../../serializers/post';
|
import serialize from '../../serializers/post';
|
||||||
import config from '../../../conf';
|
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().$;
|
const [following = null, followingErr] = $(params.following).optional.nullable.boolean().$;
|
||||||
if (followingErr) return rej('invalid following param');
|
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
|
// Get 'reply' parameter
|
||||||
const [reply = null, replyErr] = $(params.reply).optional.nullable.boolean().$;
|
const [reply = null, replyErr] = $(params.reply).optional.nullable.boolean().$;
|
||||||
if (replyErr) return rej('invalid reply param');
|
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 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, 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
|
// 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 = {
|
let q: any = {
|
||||||
$and: []
|
$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 != null) {
|
||||||
if (reply) {
|
if (reply) {
|
||||||
push({
|
push({
|
||||||
@ -236,7 +319,7 @@ async function byNative(res, rej, me, text, userId, following, reply, repost, me
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Search by Elasticsearch
|
// 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');
|
const es = require('../../db/elasticsearch');
|
||||||
|
|
||||||
es.search({
|
es.search({
|
||||||
|
@ -29,6 +29,22 @@ section
|
|||||||
| false ... フォローしていないユーザーに限定。
|
| false ... フォローしていないユーザーに限定。
|
||||||
br
|
br
|
||||||
| null ... 特に限定しない(デフォルト)
|
| 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
|
tr
|
||||||
td reply
|
td reply
|
||||||
td
|
td
|
||||||
|
Loading…
Reference in New Issue
Block a user