From 46432161b88b8213bd74cf8d8e14d179e8ae51d1 Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 17 Dec 2024 09:47:32 +0000 Subject: [PATCH 1/3] enforce restrictions for user's rss feed if `requireSigninToViewContents` in on, no notes are included in the feed notes covered by `makeNotesFollowersOnlyBefore` and `makeNotesHiddenBefore` are skipped --- .../backend/src/server/web/FeedService.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/web/FeedService.ts b/packages/backend/src/server/web/FeedService.ts index 57a32ca934..de22a0e80e 100644 --- a/packages/backend/src/server/web/FeedService.ts +++ b/packages/backend/src/server/web/FeedService.ts @@ -48,7 +48,7 @@ export class FeedService { const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id }); - const notes = await this.notesRepository.find({ + const notes = user.requireSigninToViewContents ? [] : await this.notesRepository.find({ where: { userId: user.id, renoteId: IsNull(), @@ -74,7 +74,16 @@ export class FeedService { copyright: user.name ?? user.username, }); + const followersOnlyBefore = user.makeNotesFollowersOnlyBefore; + const hiddenBefore = user.makeNotesHiddenBefore; + for (const note of notes) { + const createdAt = new Date(this.idService.parse(note.id).date); + + if (this.compareDates(followersOnlyBefore, createdAt) || this.compareDates(hiddenBefore, createdAt)) { + continue; + } + const files = note.fileIds.length > 0 ? await this.driveFilesRepository.findBy({ id: In(note.fileIds), }) : []; @@ -93,4 +102,17 @@ export class FeedService { return feed; } + + // this logic is copied from NoteEntityService.hideNote + private compareDates(reference, createdAt: Date): boolean { + if ((reference != null) + && ( + (reference <= 0 && (Date.now() - createdAt.getTime() > 0 - (reference * 1000))) + || (reference > 0 && (createdAt.getTime() < reference * 1000)) + ) + ) { + return true; + } + return false; + } } From 799cc0d0980512da4478e32edec3e11c6d09b963 Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 17 Dec 2024 10:06:30 +0000 Subject: [PATCH 2/3] pick lints --- packages/backend/src/server/web/FeedService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/web/FeedService.ts b/packages/backend/src/server/web/FeedService.ts index de22a0e80e..c9773dc231 100644 --- a/packages/backend/src/server/web/FeedService.ts +++ b/packages/backend/src/server/web/FeedService.ts @@ -104,13 +104,13 @@ export class FeedService { } // this logic is copied from NoteEntityService.hideNote - private compareDates(reference, createdAt: Date): boolean { + private compareDates(reference: number | null, createdAt: Date): boolean { if ((reference != null) && ( (reference <= 0 && (Date.now() - createdAt.getTime() > 0 - (reference * 1000))) || (reference > 0 && (createdAt.getTime() < reference * 1000)) ) - ) { + ) { return true; } return false; From f4537e70927d4c7ea96670dbced695f6b3fd4a7c Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 17 Dec 2024 16:45:56 +0000 Subject: [PATCH 3/3] better name, and other tweaks --- packages/backend/src/server/web/FeedService.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/server/web/FeedService.ts b/packages/backend/src/server/web/FeedService.ts index c9773dc231..664f21d308 100644 --- a/packages/backend/src/server/web/FeedService.ts +++ b/packages/backend/src/server/web/FeedService.ts @@ -80,7 +80,7 @@ export class FeedService { for (const note of notes) { const createdAt = new Date(this.idService.parse(note.id).date); - if (this.compareDates(followersOnlyBefore, createdAt) || this.compareDates(hiddenBefore, createdAt)) { + if (this.shouldHideNote(followersOnlyBefore, createdAt) || this.shouldHideNote(hiddenBefore, createdAt)) { continue; } @@ -104,13 +104,13 @@ export class FeedService { } // this logic is copied from NoteEntityService.hideNote - private compareDates(reference: number | null, createdAt: Date): boolean { - if ((reference != null) + private shouldHideNote(reference: number | null, createdAt: Date): boolean { + if ((reference !== null) && ( (reference <= 0 && (Date.now() - createdAt.getTime() > 0 - (reference * 1000))) || (reference > 0 && (createdAt.getTime() < reference * 1000)) ) - ) { + ) { return true; } return false;