From e9feb8c9c8c5650ce529e49abbddb08609ecea84 Mon Sep 17 00:00:00 2001
From: piuvas <piuvas@proton.me>
Date: Thu, 28 Nov 2024 23:17:30 -0300
Subject: [PATCH 1/4] testing

---
 packages/backend/src/core/QueryService.ts | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/packages/backend/src/core/QueryService.ts b/packages/backend/src/core/QueryService.ts
index c4feeaf971..926e3c9ba9 100644
--- a/packages/backend/src/core/QueryService.ts
+++ b/packages/backend/src/core/QueryService.ts
@@ -4,7 +4,7 @@
  */
 
 import { Inject, Injectable } from '@nestjs/common';
-import { Brackets, ObjectLiteral } from 'typeorm';
+import { Brackets, createQueryBuilder, getRepository, ObjectLiteral } from 'typeorm';
 import { DI } from '@/di-symbols.js';
 import type { MiUser } from '@/models/User.js';
 import type { UserProfilesRepository, FollowingsRepository, ChannelFollowingsRepository, BlockingsRepository, NoteThreadMutingsRepository, MutingsRepository, RenoteMutingsRepository } from '@/models/_.js';
@@ -88,6 +88,11 @@ export class QueryService {
 				qb
 					.where('note.renoteUserId IS NULL')
 					.orWhere(`note.renoteUserId NOT IN (${ blockingQuery.getQuery() })`);
+			}))
+			.andWhere(new Brackets(qb => {
+				qb
+					.where('(SELECT note.replyUserId FROM note WHERE note.id = renote.Id) IS NULL')
+					.orWhere(`(SELECT note.replyUserId FROM note WHERE note.id = renote.Id) NOT IN (${ blockingQuery.getQuery() })`);
 			}));
 
 		q.setParameters(blockingQuery.getParameters());
@@ -155,6 +160,11 @@ export class QueryService {
 					.where('note.renoteUserId IS NULL')
 					.orWhere(`note.renoteUserId NOT IN (${ mutingQuery.getQuery() })`);
 			}))
+			.andWhere(new Brackets(qb => {
+				qb
+					.where('(SELECT note.replyUserId FROM note WHERE note.id = renote.Id) IS NULL')
+					.orWhere(`(SELECT note.replyUserId FROM note WHERE note.id = renote.Id) NOT IN (${ mutingQuery.getQuery() })`);
+			}))
 			// mute instances
 			.andWhere(new Brackets(qb => {
 				qb
-- 
GitLab


From 19a47e38358002ec8a5417e212534e9d03a025f8 Mon Sep 17 00:00:00 2001
From: piuvas <piuvas@proton.me>
Date: Fri, 29 Nov 2024 19:50:47 -0300
Subject: [PATCH 2/4] improve query

---
 packages/backend/src/core/QueryService.ts | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/packages/backend/src/core/QueryService.ts b/packages/backend/src/core/QueryService.ts
index 926e3c9ba9..ad253a0138 100644
--- a/packages/backend/src/core/QueryService.ts
+++ b/packages/backend/src/core/QueryService.ts
@@ -89,10 +89,11 @@ export class QueryService {
 					.where('note.renoteUserId IS NULL')
 					.orWhere(`note.renoteUserId NOT IN (${ blockingQuery.getQuery() })`);
 			}))
+			// filter out renotes where the user being replied to is muted.
 			.andWhere(new Brackets(qb => {
 				qb
-					.where('(SELECT note.replyUserId FROM note WHERE note.id = renote.Id) IS NULL')
-					.orWhere(`(SELECT note.replyUserId FROM note WHERE note.id = renote.Id) NOT IN (${ blockingQuery.getQuery() })`);
+					.where('(SELECT "replyUserId" FROM note n WHERE "n".id = note.renoteId) IS NULL')
+					.orWhere(`(SELECT "replyUserId" FROM note n WHERE "n".id = note.renoteId) NOT IN (${ blockingQuery.getQuery() })`);
 			}));
 
 		q.setParameters(blockingQuery.getParameters());
@@ -160,10 +161,11 @@ export class QueryService {
 					.where('note.renoteUserId IS NULL')
 					.orWhere(`note.renoteUserId NOT IN (${ mutingQuery.getQuery() })`);
 			}))
+			// filter out renotes where the user being replied to is muted.
 			.andWhere(new Brackets(qb => {
 				qb
-					.where('(SELECT note.replyUserId FROM note WHERE note.id = renote.Id) IS NULL')
-					.orWhere(`(SELECT note.replyUserId FROM note WHERE note.id = renote.Id) NOT IN (${ mutingQuery.getQuery() })`);
+					.where('(SELECT "replyUserId" FROM note n WHERE "n".id = note.renoteId) IS NULL')
+					.orWhere(`(SELECT "replyUserId" FROM note n WHERE "n".id = note.renoteId) NOT IN (${ mutingQuery.getQuery() })`);
 			}))
 			// mute instances
 			.andWhere(new Brackets(qb => {
-- 
GitLab


From c821b7f27b44cc796f5d8abf276f82424a11f57a Mon Sep 17 00:00:00 2001
From: piuvas <piuvas@proton.me>
Date: Sun, 1 Dec 2024 13:16:09 -0300
Subject: [PATCH 3/4] add logic to fanout timeline :3

---
 packages/backend/src/misc/is-user-related.ts | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/packages/backend/src/misc/is-user-related.ts b/packages/backend/src/misc/is-user-related.ts
index 862d6e6a38..f44765988d 100644
--- a/packages/backend/src/misc/is-user-related.ts
+++ b/packages/backend/src/misc/is-user-related.ts
@@ -20,5 +20,9 @@ export function isUserRelated(note: any, userIds: Set<string>, ignoreAuthor = fa
 		return true;
 	}
 
+	if (note.renote?.replyUserId != null && note.renote?.replyUserId !== note.userId && userIds.has(note.renote?.replyUserId)) {
+		return true;
+	}
+
 	return false;
 }
-- 
GitLab


From 0809b1f66af1092eb387e2a6bf61da03c786e0d0 Mon Sep 17 00:00:00 2001
From: piuvas <piuvas@proton.me>
Date: Sun, 1 Dec 2024 15:29:45 -0300
Subject: [PATCH 4/4] i dont remember adding this

---
 packages/backend/src/core/QueryService.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packages/backend/src/core/QueryService.ts b/packages/backend/src/core/QueryService.ts
index ad253a0138..1fbc9c4406 100644
--- a/packages/backend/src/core/QueryService.ts
+++ b/packages/backend/src/core/QueryService.ts
@@ -4,7 +4,7 @@
  */
 
 import { Inject, Injectable } from '@nestjs/common';
-import { Brackets, createQueryBuilder, getRepository, ObjectLiteral } from 'typeorm';
+import { Brackets, ObjectLiteral } from 'typeorm';
 import { DI } from '@/di-symbols.js';
 import type { MiUser } from '@/models/User.js';
 import type { UserProfilesRepository, FollowingsRepository, ChannelFollowingsRepository, BlockingsRepository, NoteThreadMutingsRepository, MutingsRepository, RenoteMutingsRepository } from '@/models/_.js';
-- 
GitLab