summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/posts/search.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api/endpoints/posts/search.ts')
-rw-r--r--src/server/api/endpoints/posts/search.ts98
1 files changed, 49 insertions, 49 deletions
diff --git a/src/server/api/endpoints/posts/search.ts b/src/server/api/endpoints/posts/search.ts
index a36d1178a5..bb5c438926 100644
--- a/src/server/api/endpoints/posts/search.ts
+++ b/src/server/api/endpoints/posts/search.ts
@@ -21,21 +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 'include_user_ids' parameter
- const [includeUserIds = [], includeUserIdsErr] = $(params.include_user_ids).optional.array('id').$;
- if (includeUserIdsErr) return rej('invalid include_user_ids param');
+ // Get 'includeUserIds' parameter
+ const [includeUserIds = [], includeUserIdsErr] = $(params.includeUserIds).optional.array('id').$;
+ if (includeUserIdsErr) return rej('invalid includeUserIds 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 'excludeUserIds' parameter
+ const [excludeUserIds = [], excludeUserIdsErr] = $(params.excludeUserIds).optional.array('id').$;
+ if (excludeUserIdsErr) return rej('invalid excludeUserIds 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 'includeUserUsernames' parameter
+ const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.includeUserUsernames).optional.array('string').$;
+ if (includeUserUsernamesErr) return rej('invalid includeUserUsernames 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 'excludeUserUsernames' parameter
+ const [excludeUserUsernames = [], excludeUserUsernamesErr] = $(params.excludeUserUsernames).optional.array('string').$;
+ if (excludeUserUsernamesErr) return rej('invalid excludeUserUsernames param');
// Get 'following' parameter
const [following = null, followingErr] = $(params.following).optional.nullable.boolean().$;
@@ -61,13 +61,13 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
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';
+ // Get 'sinceDate' parameter
+ const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().$;
+ if (sinceDateErr) throw 'invalid sinceDate param';
- // Get 'until_date' parameter
- const [untilDate, untilDateErr] = $(params.until_date).optional.number().$;
- if (untilDateErr) throw 'invalid until_date param';
+ // Get 'untilDate' parameter
+ const [untilDate, untilDateErr] = $(params.untilDate).optional.number().$;
+ if (untilDateErr) throw 'invalid untilDate param';
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
@@ -81,7 +81,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
if (includeUserUsernames != null) {
const ids = (await Promise.all(includeUserUsernames.map(async (username) => {
const _user = await User.findOne({
- username_lower: username.toLowerCase()
+ usernameLower: username.toLowerCase()
});
return _user ? _user._id : null;
}))).filter(id => id != null);
@@ -92,7 +92,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
if (excludeUserUsernames != null) {
const ids = (await Promise.all(excludeUserUsernames.map(async (username) => {
const _user = await User.findOne({
- username_lower: username.toLowerCase()
+ usernameLower: username.toLowerCase()
});
return _user ? _user._id : null;
}))).filter(id => id != null);
@@ -143,13 +143,13 @@ async function search(
if (includeUserIds && includeUserIds.length != 0) {
push({
- user_id: {
+ userId: {
$in: includeUserIds
}
});
} else if (excludeUserIds && excludeUserIds.length != 0) {
push({
- user_id: {
+ userId: {
$nin: excludeUserIds
}
});
@@ -158,7 +158,7 @@ async function search(
if (following != null && me != null) {
const ids = await getFriends(me._id, false);
push({
- user_id: following ? {
+ userId: following ? {
$in: ids
} : {
$nin: ids.concat(me._id)
@@ -168,45 +168,45 @@ async function search(
if (me != null) {
const mutes = await Mute.find({
- muter_id: me._id,
- deleted_at: { $exists: false }
+ muterId: me._id,
+ deletedAt: { $exists: false }
});
- const mutedUserIds = mutes.map(m => m.mutee_id);
+ const mutedUserIds = mutes.map(m => m.muteeId);
switch (mute) {
case 'mute_all':
push({
- user_id: {
+ userId: {
$nin: mutedUserIds
},
- '_reply.user_id': {
+ '_reply.userId': {
$nin: mutedUserIds
},
- '_repost.user_id': {
+ '_repost.userId': {
$nin: mutedUserIds
}
});
break;
case 'mute_related':
push({
- '_reply.user_id': {
+ '_reply.userId': {
$nin: mutedUserIds
},
- '_repost.user_id': {
+ '_repost.userId': {
$nin: mutedUserIds
}
});
break;
case 'mute_direct':
push({
- user_id: {
+ userId: {
$nin: mutedUserIds
}
});
break;
case 'direct_only':
push({
- user_id: {
+ userId: {
$in: mutedUserIds
}
});
@@ -214,11 +214,11 @@ async function search(
case 'related_only':
push({
$or: [{
- '_reply.user_id': {
+ '_reply.userId': {
$in: mutedUserIds
}
}, {
- '_repost.user_id': {
+ '_repost.userId': {
$in: mutedUserIds
}
}]
@@ -227,15 +227,15 @@ async function search(
case 'all_only':
push({
$or: [{
- user_id: {
+ userId: {
$in: mutedUserIds
}
}, {
- '_reply.user_id': {
+ '_reply.userId': {
$in: mutedUserIds
}
}, {
- '_repost.user_id': {
+ '_repost.userId': {
$in: mutedUserIds
}
}]
@@ -247,7 +247,7 @@ async function search(
if (reply != null) {
if (reply) {
push({
- reply_id: {
+ replyId: {
$exists: true,
$ne: null
}
@@ -255,11 +255,11 @@ async function search(
} else {
push({
$or: [{
- reply_id: {
+ replyId: {
$exists: false
}
}, {
- reply_id: null
+ replyId: null
}]
});
}
@@ -268,7 +268,7 @@ async function search(
if (repost != null) {
if (repost) {
push({
- repost_id: {
+ repostId: {
$exists: true,
$ne: null
}
@@ -276,11 +276,11 @@ async function search(
} else {
push({
$or: [{
- repost_id: {
+ repostId: {
$exists: false
}
}, {
- repost_id: null
+ repostId: null
}]
});
}
@@ -289,7 +289,7 @@ async function search(
if (media != null) {
if (media) {
push({
- media_ids: {
+ mediaIds: {
$exists: true,
$ne: null
}
@@ -297,11 +297,11 @@ async function search(
} else {
push({
$or: [{
- media_ids: {
+ mediaIds: {
$exists: false
}
}, {
- media_ids: null
+ mediaIds: null
}]
});
}
@@ -330,7 +330,7 @@ async function search(
if (sinceDate) {
push({
- created_at: {
+ createdAt: {
$gt: new Date(sinceDate)
}
});
@@ -338,7 +338,7 @@ async function search(
if (untilDate) {
push({
- created_at: {
+ createdAt: {
$lt: new Date(untilDate)
}
});