From 216b20d2dbbc042c59bf421502904da468c931fb Mon Sep 17 00:00:00 2001
From: syuilo <Syuilotan@yahoo.co.jp>
Date: Fri, 20 Oct 2023 08:02:32 +0900
Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E8=87=AA=E5=88=86=E3=81=AE?=
 =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AD=E3=83=AF=E3=83=BC=E9=99=90=E5=AE=9A?=
 =?UTF-8?q?=E3=83=8E=E3=83=BC=E3=83=88=E3=81=8CWebsoket=E3=81=AB=E4=B9=97?=
 =?UTF-8?q?=E3=81=A3=E3=81=A6=E3=81=93=E3=81=AA=E3=81=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fix #12081
---
 .../src/server/api/stream/channels/home-timeline.ts       | 8 +++++---
 .../src/server/api/stream/channels/hybrid-timeline.ts     | 8 +++++---
 .../backend/src/server/api/stream/channels/user-list.ts   | 6 ++++--
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/packages/backend/src/server/api/stream/channels/home-timeline.ts b/packages/backend/src/server/api/stream/channels/home-timeline.ts
index 2b235b9822..46071e82fa 100644
--- a/packages/backend/src/server/api/stream/channels/home-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts
@@ -39,20 +39,22 @@ class HomeTimelineChannel extends Channel {
 
 	@bindThis
 	private async onNote(note: Packed<'Note'>) {
+		const isMe = this.user!.id === note.userId;
+
 		if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
 
 		if (note.channelId) {
 			if (!this.followingChannels.has(note.channelId)) return;
 		} else {
 			// その投稿のユーザーをフォローしていなかったら弾く
-			if ((this.user!.id !== note.userId) && !Object.hasOwn(this.following, note.userId)) return;
+			if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
 		}
 
 		// Ignore notes from instances the user has muted
 		if (isInstanceMuted(note, new Set<string>(this.userProfile!.mutedInstances))) return;
 
 		if (note.visibility === 'followers') {
-			if (!Object.hasOwn(this.following, note.userId)) return;
+			if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
 		} else if (note.visibility === 'specified') {
 			if (!note.visibleUserIds!.includes(this.user!.id)) return;
 		}
@@ -61,7 +63,7 @@ class HomeTimelineChannel extends Channel {
 		if (note.reply && !this.following[note.userId]?.withReplies) {
 			const reply = note.reply;
 			// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
-			if (reply.userId !== this.user!.id && note.userId !== this.user!.id && reply.userId !== note.userId) return;
+			if (reply.userId !== this.user!.id && !isMe && reply.userId !== note.userId) return;
 		}
 
 		if (note.renote && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !this.withRenotes) return;
diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
index 4e90912084..2722ebcd50 100644
--- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
@@ -49,6 +49,8 @@ class HybridTimelineChannel extends Channel {
 
 	@bindThis
 	private async onNote(note: Packed<'Note'>) {
+		const isMe = this.user!.id === note.userId;
+
 		if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
 
 		// チャンネルの投稿ではなく、自分自身の投稿 または
@@ -56,14 +58,14 @@ class HybridTimelineChannel extends Channel {
 		// チャンネルの投稿ではなく、全体公開のローカルの投稿 または
 		// フォローしているチャンネルの投稿 の場合だけ
 		if (!(
-			(note.channelId == null && this.user!.id === note.userId) ||
+			(note.channelId == null && isMe) ||
 			(note.channelId == null && Object.hasOwn(this.following, note.userId)) ||
 			(note.channelId == null && (note.user.host == null && note.visibility === 'public')) ||
 			(note.channelId != null && this.followingChannels.has(note.channelId))
 		)) return;
 
 		if (note.visibility === 'followers') {
-			if (!Object.hasOwn(this.following, note.userId)) return;
+			if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
 		} else if (note.visibility === 'specified') {
 			if (!note.visibleUserIds!.includes(this.user!.id)) return;
 		}
@@ -75,7 +77,7 @@ class HybridTimelineChannel extends Channel {
 		if (note.reply && !this.following[note.userId]?.withReplies && !this.withReplies) {
 			const reply = note.reply;
 			// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
-			if (reply.userId !== this.user!.id && note.userId !== this.user!.id && reply.userId !== note.userId) return;
+			if (reply.userId !== this.user!.id && !isMe && reply.userId !== note.userId) return;
 		}
 
 		if (note.renote && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !this.withRenotes) return;
diff --git a/packages/backend/src/server/api/stream/channels/user-list.ts b/packages/backend/src/server/api/stream/channels/user-list.ts
index 6d83d4cb5b..68927987d6 100644
--- a/packages/backend/src/server/api/stream/channels/user-list.ts
+++ b/packages/backend/src/server/api/stream/channels/user-list.ts
@@ -78,12 +78,14 @@ class UserListChannel extends Channel {
 
 	@bindThis
 	private async onNote(note: Packed<'Note'>) {
+		const isMe = this.user!.id === note.userId;
+
 		if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
 
 		if (!Object.hasOwn(this.membershipsMap, note.userId)) return;
 
 		if (note.visibility === 'followers') {
-			if (!Object.hasOwn(this.following, note.userId)) return;
+			if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
 		} else if (note.visibility === 'specified') {
 			if (!note.visibleUserIds!.includes(this.user!.id)) return;
 		}
@@ -92,7 +94,7 @@ class UserListChannel extends Channel {
 		if (note.reply && !this.membershipsMap[note.userId]?.withReplies) {
 			const reply = note.reply;
 			// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
-			if (reply.userId !== this.user!.id && note.userId !== this.user!.id && reply.userId !== note.userId) return;
+			if (reply.userId !== this.user!.id && !isMe && reply.userId !== note.userId) return;
 		}
 
 		// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する