summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/notes
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-04-21 11:42:38 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-04-21 11:42:38 +0900
commita9a7a89b8b286f2cd00c00311c5b7b2ea49cafe6 (patch)
treec4b34f870f116e560d93b96844cecf6a089bc3f7 /src/server/api/endpoints/notes
parentDarken (diff)
downloadsharkey-a9a7a89b8b286f2cd00c00311c5b7b2ea49cafe6.tar.gz
sharkey-a9a7a89b8b286f2cd00c00311c5b7b2ea49cafe6.tar.bz2
sharkey-a9a7a89b8b286f2cd00c00311c5b7b2ea49cafe6.zip
#1506
Diffstat (limited to 'src/server/api/endpoints/notes')
-rw-r--r--src/server/api/endpoints/notes/timeline.ts102
1 files changed, 74 insertions, 28 deletions
diff --git a/src/server/api/endpoints/notes/timeline.ts b/src/server/api/endpoints/notes/timeline.ts
index cb14fa6eb0..de30afea57 100644
--- a/src/server/api/endpoints/notes/timeline.ts
+++ b/src/server/api/endpoints/notes/timeline.ts
@@ -37,6 +37,14 @@ module.exports = async (params, user, app) => {
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
}
+ // Get 'includeMyRenotes' parameter
+ const [includeMyRenotes = true, includeMyRenotesErr] = $(params.includeMyRenotes).optional.boolean().$;
+ if (includeMyRenotesErr) throw 'invalid includeMyRenotes param';
+
+ // Get 'includeRenotedMyNotes' parameter
+ const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $(params.includeRenotedMyNotes).optional.boolean().$;
+ if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param';
+
const [followings, watchingChannelIds, mutedUserIds] = await Promise.all([
// フォローを取得
// Fetch following
@@ -84,38 +92,76 @@ module.exports = async (params, user, app) => {
});
const query = {
- $or: [{
- $and: [{
- // フォローしている人のタイムラインへの投稿
- $or: followQuery
- }, {
- // 「タイムラインへの」投稿に限定するためにチャンネルが指定されていないもののみに限る
- $or: [{
- channelId: {
- $exists: false
- }
+ $and: [{
+ $or: [{
+ $and: [{
+ // フォローしている人のタイムラインへの投稿
+ $or: followQuery
}, {
- channelId: null
+ // 「タイムラインへの」投稿に限定するためにチャンネルが指定されていないもののみに限る
+ $or: [{
+ channelId: {
+ $exists: false
+ }
+ }, {
+ channelId: null
+ }]
}]
- }]
- }, {
- // Watchしているチャンネルへの投稿
- channelId: {
- $in: watchingChannelIds
- }
- }],
- // mute
- userId: {
- $nin: mutedUserIds
- },
- '_reply.userId': {
- $nin: mutedUserIds
- },
- '_renote.userId': {
- $nin: mutedUserIds
- },
+ }, {
+ // Watchしているチャンネルへの投稿
+ channelId: {
+ $in: watchingChannelIds
+ }
+ }],
+ // mute
+ userId: {
+ $nin: mutedUserIds
+ },
+ '_reply.userId': {
+ $nin: mutedUserIds
+ },
+ '_renote.userId': {
+ $nin: mutedUserIds
+ },
+ }]
} as any;
+ // MongoDBではトップレベルで否定ができないため、De Morganの法則を利用してクエリします。
+ // つまり、「『自分の投稿かつRenote』ではない」を「『自分の投稿ではない』または『Renoteではない』」と表現します。
+ // for details: https://en.wikipedia.org/wiki/De_Morgan%27s_laws
+
+ if (includeMyRenotes === false) {
+ query.$and.push({
+ $or: [{
+ userId: { $ne: user._id }
+ }, {
+ renoteId: null
+ }, {
+ text: { $ne: null }
+ }, {
+ mediaIds: { $ne: [] }
+ }, {
+ poll: { $ne: null }
+ }]
+ });
+ }
+
+ if (includeRenotedMyNotes === false) {
+ query.$and.push({
+ $or: [{
+ '_renote.userId': { $ne: user._id }
+ }, {
+ renoteId: null
+ }, {
+ text: { $ne: null }
+ }, {
+ mediaIds: { $ne: [] }
+ }, {
+ poll: { $ne: null }
+ }]
+ });
+ }
+
if (sinceId) {
sort._id = 1;
query._id = {