From 6bbccedb2db040fb70ea0176e78bcb84daf9109e Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Mon, 21 Jan 2019 12:19:20 +0900
Subject: [PATCH] [Server] Fix #3528

---
 CHANGELOG.md                |  2 ++
 src/services/note/create.ts | 15 ++++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d4a79e5ac0..e6d6f16e94 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,8 @@ unreleased
 * ストーク機能の廃止
 * ソーシャルタイムラインにフォロワー限定投稿が含まれていない問題を修正
 * リストタイムラインでフォロワー限定投稿が含まれていない問題を修正
+* リストタイムラインに自分宛てでないダイレクト投稿が非公開扱いで表示される問題を修正
+* 自分宛てのダイレクト投稿がホーム/ソーシャルタイムラインにストリームで流れない問題を修正
 * ストリームで投稿が流れてきたとき、返信先が「この投稿は非公開です」となる問題を修正
 * 関係のない返信がタイムラインに流れる問題を修正
 * 常にメディアを閲覧注意として投稿するオプションが機能していなかった問題を修正
diff --git a/src/services/note/create.ts b/src/services/note/create.ts
index b5e5c4e49c..fbafe29107 100644
--- a/src/services/note/create.ts
+++ b/src/services/note/create.ts
@@ -369,6 +369,13 @@ async function publish(user: IUser, note: INote, noteObj: any, reply: INote, ren
 			// Publish event to myself's stream
 			publishHomeTimelineStream(note.userId, detailPackedNote);
 			publishHybridTimelineStream(note.userId, detailPackedNote);
+
+			if (note.visibility == 'specified') {
+				for (const u of visibleUsers) {
+					publishHomeTimelineStream(u._id, detailPackedNote);
+					publishHybridTimelineStream(u._id, detailPackedNote);
+				}
+			}
 		} else {
 			// Publish event to myself's stream
 			publishHomeTimelineStream(note.userId, noteObj);
@@ -526,7 +533,13 @@ async function publishToUserLists(note: INote, noteObj: any) {
 	});
 
 	for (const list of lists) {
-		publishUserListStream(list._id, 'note', noteObj);
+		if (note.visibility == 'specified') {
+			if (note.visibleUserIds.some(id => id.equals(list.userId))) {
+				publishUserListStream(list._id, 'note', noteObj);
+			}
+		} else {
+			publishUserListStream(list._id, 'note', noteObj);
+		}
 	}
 }