mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-29 18:09:05 +01:00
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
This commit is contained in:
parent
e2352839e4
commit
46432161b8
1 changed files with 23 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue