ActivityPub-federated video streaming platform using P2P directly in your web browser
Update videos on query params change
Chocobozzz7ecfb807ada4
diff --git a/client/src/app/+accounts/account-videos/account-videos.component.html b/client/src/app/+accounts/account-videos/account-videos.component.htmlindex 887667ddfd..5c47519b7d 100644--- a/client/src/app/+accounts/account-videos/account-videos.component.html+++ b/client/src/app/+accounts/account-videos/account-videos.component.html@@ -11,7 +11,6 @@[defaultSort]="defaultSort"displayFilters="true"- displayModerationBlock="true"[displayAsRow]="displayAsRow()"hideScopeFilter="true"diff --git a/client/src/app/+accounts/accounts.component.html b/client/src/app/+accounts/accounts.component.htmlindex f7df3ca338..6204c0c9cc 100644--- a/client/src/app/+accounts/accounts.component.html+++ b/client/src/app/+accounts/accounts.component.html@@ -73,6 +73,7 @@<my-simple-search-inputclass="ms-auto"+ [initialValue]="search"[alwaysShow]="!isInSmallView()" (searchChanged)="searchChanged($event)"(inputDisplayChanged)="onSearchInputDisplayChanged($event)" name="search-videos"i18n-iconTitle icon-title="Search account videos"diff --git a/client/src/app/+accounts/accounts.component.ts b/client/src/app/+accounts/accounts.component.tsindex 55b9fd5ff0..a046a76c28 100644--- a/client/src/app/+accounts/accounts.component.ts+++ b/client/src/app/+accounts/accounts.component.ts@@ -1,7 +1,17 @@-import { NgClass, NgIf } from '@angular/common'+import { CommonModule } from '@angular/common'import { Component, OnDestroy, OnInit, inject, viewChild } from '@angular/core'import { ActivatedRoute, Router, RouterLink, RouterLinkActive, RouterOutlet } from '@angular/router'-import { AuthService, MarkdownService, MetaService, Notifier, RedirectService, RestExtractor, ScreenService, UserService } from '@app/core'+import {+ AuthService,+ MarkdownService,+ MetaService,+ Notifier,+ PeerTubeRouterService,+ RedirectService,+ RestExtractor,+ ScreenService,+ UserService+} from '@app/core'import { Account } from '@app/shared/shared-main/account/account.model'import { AccountService } from '@app/shared/shared-main/account/account.service'import { DropdownAction } from '@app/shared/shared-main/buttons/action-dropdown.component'@@ -26,13 +36,12 @@ import { SubscribeButtonComponent } from '../shared/shared-user-subscription/subtemplateUrl: './accounts.component.html',styleUrls: [ './accounts.component.scss' ],imports: [- NgIf,+ CommonModule,ActorAvatarComponent,UserModerationDropdownComponent,NgbTooltip,AccountBlockBadgesComponent,CopyButtonComponent,- NgClass,RouterLink,SubscribeButtonComponent,RouterLinkActive,@@ -45,7 +54,6 @@ import { SubscribeButtonComponent } from '../shared/shared-user-subscription/sub})export class AccountsComponent implements OnInit, OnDestroy {private route = inject(ActivatedRoute)- private router = inject(Router)private userService = inject(UserService)private accountService = inject(AccountService)private videoChannelService = inject(VideoChannelService)@@ -58,12 +66,15 @@ export class AccountsComponent implements OnInit, OnDestroy {private blocklist = inject(BlocklistService)private screenService = inject(ScreenService)private metaService = inject(MetaService)+ private peertubeRouter = inject(PeerTubeRouterService)readonly accountReportModal = viewChild<AccountReportComponent>('accountReportModal')account: AccountaccountUser: User+ search = ''+videoChannels: VideoChannel[] = []links: HorizontalMenuEntry[] = []@@ -104,6 +115,8 @@ export class AccountsComponent implements OnInit, OnDestroy {{ label: $localize`Channels`, routerLink: 'video-channels' },{ label: $localize`Videos`, routerLink: 'videos' }]++ this.search = this.route.snapshot.queryParams['search'] || ''}ngOnDestroy () {@@ -148,7 +161,7 @@ export class AccountsComponent implements OnInit, OnDestroy {searchChanged (search: string) {const queryParams = { search }- this.router.navigate([ './videos' ], { queryParams, relativeTo: this.route, queryParamsHandling: 'merge' })+ this.peertubeRouter.silentNavigate([ './videos' ], queryParams, this.route)}onSearchInputDisplayChanged (displayed: boolean) {diff --git a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.html b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.htmlindex f0659928a3..c4e62c5ed8 100644--- a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.html+++ b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.html@@ -11,9 +11,7 @@[defaultSort]="defaultSort"displayFilters="true"- displayModerationBlock="true"-- [displayOptions]="displayOptions"+ displayBy="false"[displayAsRow]="displayAsRow()"hideScopeFilter="true"diff --git a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.tsindex 3745359307..464d078e7c 100644--- a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts+++ b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts@@ -5,7 +5,6 @@ import { VideoChannel } from '@app/shared/shared-main/channel/video-channel.modeimport { VideoChannelService } from '@app/shared/shared-main/channel/video-channel.service'import { VideoService } from '@app/shared/shared-main/video/video.service'import { VideoFilters } from '@app/shared/shared-video-miniature/video-filters.model'-import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature/video-miniature.component'import { Video, VideoSortField } from '@peertube/peertube-models'import { Subscription } from 'rxjs'import { VideosListComponent } from '../../shared/shared-video-miniature/videos-list.component'@@ -28,16 +27,6 @@ export class VideoChannelVideosComponent implements OnInit, AfterViewInit, OnDesdefaultSort = '-publishedAt' as VideoSortField- displayOptions: MiniatureDisplayOptions = {- date: true,- views: true,- by: false,- avatar: false,- privacyLabel: true,- privacyText: false,- blacklistInfo: false- }-videoChannel: VideoChanneldisabled = falsediff --git a/client/src/app/+video-list/video-user-subscriptions.component.html b/client/src/app/+video-list/video-user-subscriptions.component.htmlindex dcd3a0890a..44ca2fa4ac 100644--- a/client/src/app/+video-list/video-user-subscriptions.component.html+++ b/client/src/app/+video-list/video-user-subscriptions.component.html@@ -7,7 +7,6 @@[defaultSort]="defaultSort"displayFilters="false"- displayModerationBlock="false"loadUserVideoPreferences="false"groupByDate="true"diff --git a/client/src/app/+video-list/videos-list-all.component.html b/client/src/app/+video-list/videos-list-all.component.htmlindex 1510a68adc..6a02b7b74e 100644--- a/client/src/app/+video-list/videos-list-all.component.html+++ b/client/src/app/+video-list/videos-list-all.component.html@@ -8,7 +8,6 @@[defaultScope]="defaultScope"displayFilters="true"- displayModerationBlock="true"loadUserVideoPreferences="true"[groupByDate]="groupByDate"diff --git a/client/src/app/shared/shared-main/search/simple-search-input.component.ts b/client/src/app/shared/shared-main/search/simple-search-input.component.tsindex 5fc7487598..82dae98fe7 100644--- a/client/src/app/shared/shared-main/search/simple-search-input.component.ts+++ b/client/src/app/shared/shared-main/search/simple-search-input.component.ts@@ -1,7 +1,7 @@-import { Component, ElementRef, OnInit, input, output, viewChild } from '@angular/core'import { NgIf } from '@angular/common'-import { GlobalIconComponent } from '../../shared-icons/global-icon.component'+import { Component, ElementRef, OnInit, input, output, viewChild } from '@angular/core'import { FormsModule } from '@angular/forms'+import { GlobalIconComponent } from '../../shared-icons/global-icon.component'@Component({selector: 'my-simple-search-input',@@ -12,6 +12,7 @@ import { FormsModule } from '@angular/forms'export class SimpleSearchInputComponent implements OnInit {readonly input = viewChild<ElementRef>('ref')+ readonly initialValue = input('')readonly name = input('search')readonly placeholder = input($localize`Search`)readonly iconTitle = input($localize`Search`)@@ -20,11 +21,13 @@ export class SimpleSearchInputComponent implements OnInit {readonly searchChanged = output<string>()readonly inputDisplayChanged = output<boolean>()- value = ''lastSearch = ''+ value = ''inputShown: booleanngOnInit () {+ this.value = this.initialValue()+if (this.isInputShown()) this.showInput(false)}diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.tsindex 318f41dc11..20214ae498 100644--- a/client/src/app/shared/shared-main/video/video.service.ts+++ b/client/src/app/shared/shared-main/video/video.service.ts@@ -155,11 +155,11 @@ export class VideoService {}getAccountVideos (- parameters: CommonVideoParams & {+ options: CommonVideoParams & {account: Pick<Account, 'nameWithHost'>}): Observable<ResultList<Video>> {- const { account } = parameters+ const { account, ...parameters } = optionslet params = new HttpParams()params = this.buildCommonVideosParams({ params, ...parameters })diff --git a/client/src/app/shared/shared-video-miniature/video-filters-header.component.html b/client/src/app/shared/shared-video-miniature/video-filters-header.component.htmlindex 0ad4bc9b10..2bbe8f6f6f 100644--- a/client/src/app/shared/shared-video-miniature/video-filters-header.component.html+++ b/client/src/app/shared/shared-video-miniature/video-filters-header.component.html@@ -5,7 +5,6 @@<my-buttontheme="secondary" [icon]="quickFilter.iconName" class="me-2 mb-2"ptRouterLink="." [ptQueryParams]="quickFilter.filters" [active]="quickFilter.isActive()" ptQueryParamsHandling="merge"- (click)="onQuickFilter($event, quickFilter)">{{ quickFilter.label }} </my-button>}</div>diff --git a/client/src/app/shared/shared-video-miniature/video-filters-header.component.ts b/client/src/app/shared/shared-video-miniature/video-filters-header.component.tsindex 27fc7c0100..d15d7fa995 100644--- a/client/src/app/shared/shared-video-miniature/video-filters-header.component.ts+++ b/client/src/app/shared/shared-video-miniature/video-filters-header.component.ts@@ -1,5 +1,5 @@import { NgClass, NgIf } from '@angular/common'-import { Component, OnInit, inject, input, output } from '@angular/core'+import { Component, OnInit, inject, input } from '@angular/core'import { FormBuilder, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms'import { RouterLink } from '@angular/router'import { AuthService, RedirectService } from '@app/core'@@ -61,8 +61,6 @@ export class VideoFiltersHeaderComponent implements OnInit {readonly displayModerationBlock = input(false)readonly hideScope = input(false)- readonly filtersChanged = output()-areFiltersCollapsed = trueform: FormGroup@@ -98,10 +96,9 @@ export class VideoFiltersHeaderComponent implements OnInit {})this.form.valueChanges.subscribe(values => {- debugLogger('Loading values from form: %O', values)+ debugLogger('Loading values from form', { values })- this.filters().load(values)- this.filtersChanged.emit()+ this.filters().load(values, true)})this.serverService.getVideoCategories()@@ -131,13 +128,6 @@ export class VideoFiltersHeaderComponent implements OnInit {// ---------------------------------------------------------------------------- onQuickFilter (e: Event, quickFilter: QuickFilter) {- e.preventDefault()-- this.filters().load(quickFilter.filters)- this.filtersChanged.emit()- }-private buildQuickFilters () {const trendingSort = this.redirectService.getDefaultTrendingSort()@@ -225,6 +215,6 @@ export class VideoFiltersHeaderComponent implements OnInit {const defaultValues = this.filters().toFormObject()this.form.patchValue(defaultValues, { emitEvent })- debugLogger('Patched form: %O', defaultValues)+ debugLogger('Patch form', { values: defaultValues })}}diff --git a/client/src/app/shared/shared-video-miniature/video-filters.model.ts b/client/src/app/shared/shared-video-miniature/video-filters.model.tsindex c746a1047d..872d4ede0f 100644--- a/client/src/app/shared/shared-video-miniature/video-filters.model.ts+++ b/client/src/app/shared/shared-video-miniature/video-filters.model.ts@@ -9,9 +9,12 @@ import {VideoSortField} from '@peertube/peertube-models'import { AttributesOnly } from '@peertube/peertube-typescript-utils'+import debug from 'debug'++const debugLogger = debug('peertube:videos:VideoFilters')type VideoFiltersKeys = {- [ id in keyof AttributesOnly<VideoFilters> ]: any+ [id in keyof AttributesOnly<VideoFilters>]: any}export type VideoFilterScope = 'local' | 'federated'@@ -55,6 +58,8 @@ export class VideoFilters {private onChangeCallbacks: (() => void)[] = []private oldFormObjectString: string+ private customizedByUser = false+private readonly hiddenFields: string[] = []constructor (defaultSort: string, defaultScope: VideoFilterScope, hiddenFields: string[] = []) {@@ -63,7 +68,7 @@ export class VideoFilters {this.hiddenFields = hiddenFields- this.reset()+ this.reset(undefined, false)}// ---------------------------------------------------------------------------@@ -72,10 +77,17 @@ export class VideoFilters {this.onChangeCallbacks.push(cb)}- triggerChange () {+ private triggerChange () {+ if (this.onChangeCallbacks.length === 0) return+// Don't run on change if the values did not changeconst currentFormObjectString = JSON.stringify(this.toFormObject())- if (this.oldFormObjectString && currentFormObjectString === this.oldFormObjectString) return++ const noChanges = !!this.oldFormObjectString && currentFormObjectString === this.oldFormObjectString++ debugLogger('Checking if we need to trigger change', { changes: !noChanges })++ if (noChanges) returnthis.oldFormObjectString = currentFormObjectString@@ -95,24 +107,40 @@ export class VideoFilters {}setNSFWPolicy (nsfwPolicy: NSFWPolicyType) {- this.updateDefaultNSFW(nsfwPolicy)+ const nsfw = nsfwPolicy === 'do_not_list'+ ? 'false'+ : 'both'++ this.defaultValues.set('nsfw', nsfw)+ this.defaultNSFWPolicy = nsfwPolicy++ return nsfw}// ---------------------------------------------------------------------------- reset (specificKey?: string) {+ reset (specificKey?: string, triggerChange = true) {+ debugLogger('Reset video filters', { specificKey, stack: new Error().stack })+for (const [ key, value ] of this.defaultValues) {if (specificKey && specificKey !== key) continue-- (this as any)[key] = value+ ;(this as any)[key] = value}this.buildActiveFilters()++ if (triggerChange) {+ this.triggerChange()+ }}// ---------------------------------------------------------------------------- load (obj: Partial<AttributesOnly<VideoFilters>>) {+ load (obj: Partial<AttributesOnly<VideoFilters>>, customizedByUser?: boolean) {+ debugLogger('Loading object in video filters', { obj, customizedByUser })++ if (customizedByUser) this.customizedByUser = customizedByUser+if (obj.sort !== undefined) this.sort = obj.sortif (obj.nsfw !== undefined) this.nsfw = obj.nsfw@@ -128,20 +156,29 @@ export class VideoFilters {if (obj.search !== undefined) this.search = obj.searchthis.buildActiveFilters()+ this.triggerChange()}clone () {+ debugLogger('Cloning video filters', { videoFilters: this })+const cloned = new VideoFilters(this.defaultValues.get('sort'), this.defaultValues.get('scope'), this.hiddenFields)cloned.setNSFWPolicy(this.defaultNSFWPolicy)- cloned.load(this.toUrlObject())+ cloned.load(this.toUrlObject(), this.customizedByUser)return cloned}// ---------------------------------------------------------------------------- buildActiveFilters () {+ hasBeenCustomizedByUser () {+ return this.customizedByUser+ }++ // ---------------------------------------------------------------------------++ private buildActiveFilters () {this.activeFilters = []this.activeFilters.push({@@ -203,7 +240,7 @@ export class VideoFilters {}this.activeFilters = this.activeFilters- .filter(a => this.hiddenFields.includes(a.key) === false)+ .filter(a => this.hiddenFields.includes(a.key) === false)}getActiveFilters () {@@ -223,7 +260,7 @@ export class VideoFilters {}toUrlObject () {- const result: { [ id: string ]: any } = {}+ const result: { [id: string]: any } = {}for (const [ key, defaultValue ] of this.defaultValues) {if (this[key] !== defaultValue) {@@ -279,15 +316,4 @@ export class VideoFilters {return $localize`displayed`}-- private updateDefaultNSFW (nsfwPolicy: NSFWPolicyType) {- const nsfw = nsfwPolicy === 'do_not_list'- ? 'false'- : 'both'-- this.defaultValues.set('nsfw', nsfw)- this.defaultNSFWPolicy = nsfwPolicy-- this.reset('nsfw')- }}diff --git a/client/src/app/shared/shared-video-miniature/videos-list.component.html b/client/src/app/shared/shared-video-miniature/videos-list.component.htmlindex d5a49e0ff5..68cf008c82 100644--- a/client/src/app/shared/shared-video-miniature/videos-list.component.html+++ b/client/src/app/shared/shared-video-miniature/videos-list.component.html@@ -11,8 +11,7 @@<my-video-filters-header*ngIf="displayFilters()" class="d-block"- [displayModerationBlock]="builtDisplayModerationBlock" [hideScope]="hideScopeFilter()" [filters]="filters"- (filtersChanged)="onFiltersChanged(true)"+ [displayModerationBlock]="displayModerationBlock" [hideScope]="hideScopeFilter()" [filters]="filters"></my-video-filters-header><div class="no-results" i18n *ngIf="hasDoneFirstQuery && videos.length === 0 && highlightedLives.length === 0">No results.</div>@@ -30,8 +29,8 @@<ng-container *ngFor="let live of highlightedLives; trackBy: videoById;"><div class="video-wrapper"><my-video-miniature- [video]="live" [user]="userMiniature" [displayAsRow]="displayAsRow()"- [displayVideoActions]="displayVideoActions()" [displayOptions]="builtDisplayOptions"+ [video]="live" [user]="user" [displayAsRow]="displayAsRow()"+ [displayVideoActions]="displayVideoActions()" [displayOptions]="displayOptions"(videoBlocked)="removeVideoFromArray(live)" (videoRemoved)="removeVideoFromArray(live)"></my-video-miniature>@@ -50,8 +49,8 @@<div class="video-wrapper"><my-video-miniature- [video]="video" [user]="userMiniature" [displayAsRow]="displayAsRow()"- [displayVideoActions]="displayVideoActions()" [displayOptions]="builtDisplayOptions"+ [video]="video" [user]="user" [displayAsRow]="displayAsRow()"+ [displayVideoActions]="displayVideoActions()" [displayOptions]="displayOptions"(videoBlocked)="removeVideoFromArray(video)" (videoRemoved)="removeVideoFromArray(video)"></my-video-miniature>diff --git a/client/src/app/shared/shared-video-miniature/videos-list.component.scss b/client/src/app/shared/shared-video-miniature/videos-list.component.scssindex 16e198654d..b1f25e9091 100644--- a/client/src/app/shared/shared-video-miniature/videos-list.component.scss+++ b/client/src/app/shared/shared-video-miniature/videos-list.component.scss@@ -6,6 +6,11 @@// Cannot set margin top to videos-header because of the main header fixed position$margin-top: 2rem;+.videos {+ // Prevent scroll when reloading videos+ min-height: 50vh;+}+.videos-header {display: grid;grid-template-columns: auto 1fr auto;diff --git a/client/src/app/shared/shared-video-miniature/videos-list.component.ts b/client/src/app/shared/shared-video-miniature/videos-list.component.tsindex 9d6b62dcfa..9c7f8a8fd3 100644--- a/client/src/app/shared/shared-video-miniature/videos-list.component.ts+++ b/client/src/app/shared/shared-video-miniature/videos-list.component.ts@@ -1,8 +1,7 @@import { NgClass, NgFor, NgIf } from '@angular/common'-import { Component, OnChanges, OnDestroy, OnInit, SimpleChanges, booleanAttribute, inject, input, output } from '@angular/core'+import { Component, OnDestroy, OnInit, booleanAttribute, inject, input, output } from '@angular/core'import { ActivatedRoute } from '@angular/router'import {- AuthService,ComponentPagination,ComponentPaginationLight,Notifier,@@ -15,7 +14,7 @@ import {} from '@app/core'import { GlobalIconComponent, GlobalIconName } from '@app/shared/shared-icons/global-icon.component'import { isLastMonth, isLastWeek, isThisMonth, isToday, isYesterday } from '@peertube/peertube-core-utils'-import { ResultList, UserRight, VideoSortField } from '@peertube/peertube-models'+import { ResultList, VideoSortField } from '@peertube/peertube-models'import { logger } from '@root-helpers/logger'import debug from 'debug'import { Observable, Subject, Subscription, forkJoin, fromEvent, of } from 'rxjs'@@ -62,9 +61,8 @@ enum GroupDate {GlobalIconComponent]})-export class VideosListComponent implements OnInit, OnChanges, OnDestroy {+export class VideosListComponent implements OnInit, OnDestroy {private notifier = inject(Notifier)- private authService = inject(AuthService)private userService = inject(UserService)private route = inject(ActivatedRoute)private screenService = inject(ScreenService)@@ -78,9 +76,8 @@ export class VideosListComponent implements OnInit, OnChanges, OnDestroy {readonly defaultSort = input<VideoSortField>(undefined)readonly defaultScope = input<VideoFilterScope>('federated')readonly displayFilters = input(false, { transform: booleanAttribute })-- readonly displayModerationBlock = input(false, { transform: booleanAttribute })- builtDisplayModerationBlock: boolean+ readonly displayBy = input(true, { transform: booleanAttribute })+ readonly hideScopeFilter = input(false, { transform: booleanAttribute })readonly loadUserVideoPreferences = input(false, { transform: booleanAttribute })@@ -91,11 +88,6 @@ export class VideosListComponent implements OnInit, OnChanges, OnDestroy {readonly headerActions = input<HeaderAction[]>([])- readonly hideScopeFilter = input(false, { transform: booleanAttribute })-- readonly displayOptions = input<MiniatureDisplayOptions>(undefined)- builtDisplayOptions: MiniatureDisplayOptions-readonly disabled = input(false, { transform: booleanAttribute })readonly filtersChanged = output<VideoFilters>()@@ -110,9 +102,9 @@ export class VideosListComponent implements OnInit, OnChanges, OnDestroy {onVideosDataSubject = new Subject<any[]>()hasDoneFirstQuery = false- userMiniature: User+ user: User- private defaultDisplayOptions: MiniatureDisplayOptions = {+ displayOptions: MiniatureDisplayOptions = {date: true,views: true,by: true,@@ -121,6 +113,8 @@ export class VideosListComponent implements OnInit, OnChanges, OnDestroy {privacyText: false,blacklistInfo: false}+ displayModerationBlock = false+private routeSub: Subscriptionprivate userSub: Subscriptionprivate resizeSub: Subscription@@ -131,7 +125,15 @@ export class VideosListComponent implements OnInit, OnChanges, OnDestroy {totalItems: null}- private groupedDateLabels: { [id in GroupDate]: string }+ private groupedDateLabels: { [id in GroupDate]: string } = {+ [GroupDate.UNKNOWN]: null,+ [GroupDate.TODAY]: $localize`Today's videos`,+ [GroupDate.YESTERDAY]: $localize`Yesterday's videos`,+ [GroupDate.THIS_WEEK]: $localize`This week's videos`,+ [GroupDate.THIS_MONTH]: $localize`This month's videos`,+ [GroupDate.LAST_MONTH]: $localize`Last month's videos`,+ [GroupDate.OLDER]: $localize`Older videos`+ }private groupedDates: { [id: number]: GroupDate } = {}private lastQueryLength: number@@ -145,6 +147,9 @@ export class VideosListComponent implements OnInit, OnChanges, OnDestroy {private alreadyDoneSearch = falsengOnInit () {+ this.displayOptions.by = this.displayBy()+ this.displayOptions.avatar = this.displayBy()+this.subscribeToVideoRequests()const hiddenFilters = this.hideScopeFilter()@@ -152,17 +157,6 @@ export class VideosListComponent implements OnInit, OnChanges, OnDestroy {: []this.filters = new VideoFilters(this.defaultSort(), this.defaultScope(), hiddenFilters)- this.filters.load({ scope: this.defaultScope(), ...this.route.snapshot.queryParams })-- this.groupedDateLabels = {- [GroupDate.UNKNOWN]: null,- [GroupDate.TODAY]: $localize`Today's videos`,- [GroupDate.YESTERDAY]: $localize`Yesterday's videos`,- [GroupDate.THIS_WEEK]: $localize`This week's videos`,- [GroupDate.THIS_MONTH]: $localize`This month's videos`,- [GroupDate.LAST_MONTH]: $localize`Last month's videos`,- [GroupDate.OLDER]: $localize`Older videos`- }this.resizeSub = fromEvent(window, 'resize').pipe(debounceTime(500))@@ -172,71 +166,41 @@ export class VideosListComponent implements OnInit, OnChanges, OnDestroy {this.userService.getAnonymousOrLoggedUser().subscribe(user => {- this.userMiniature = user+ this.user = userif (this.loadUserVideoPreferences()) {this.loadUserSettings(user)}- this.scheduleOnFiltersChanged(false)-this.subscribeToAnonymousUpdate()- this.subscribeToSearchChange()+ this.subscribeToQueryParamsChange()})- }-- ngOnDestroy () {- if (this.resizeSub) this.resizeSub.unsubscribe()- if (this.routeSub) this.routeSub.unsubscribe()- if (this.userSub) this.userSub.unsubscribe()- }-- ngOnChanges (changes: SimpleChanges) {- if (changes['displayModerationBlock'] !== undefined) {- this.builtDisplayModerationBlock = changes['displayModerationBlock'].currentValue- }-- if (changes['displayOptions'] || !this.builtDisplayOptions) {- this.builtDisplayOptions = {- ...this.defaultDisplayOptions,-- ...(changes['displayOptions']?.currentValue ?? {})- }- // Display avatar in mobile view- if (this.screenService.isInMobileView()) {- this.builtDisplayOptions.avatar = true- }- }+ this.filters.load(this.route.snapshot.queryParams)- if (!this.filters) return+ this.filters.onChange(() => {+ debugLogger('Filters changed', this.filters)- let updated = false-- if (changes['defaultScope']) {- updated = true- this.filters.setDefaultScope(this.defaultScope())- }-- if (changes['defaultSort']) {- updated = true- this.filters.setDefaultSort(this.defaultSort())- }+ // We'll reload videos, but avoid weird UI effect+ this.videos = []+ this.highlightedLives = []- if (!updated) return+ this.updateUrl()- const customizedByUser = this.hasBeenCustomizedByUser()+ this.reloadSyndicationItems()+ this.reloadVideos()- if (!customizedByUser) {- if (this.loadUserVideoPreferences()) {- this.loadUserSettings(this.userMiniature)- }+ this.filtersChanged.emit(this.filters)+ })- this.filters.reset('scope')- this.filters.reset('sort')- }+ this.reloadSyndicationItems()+ this.reloadVideos()+ }- this.scheduleOnFiltersChanged(customizedByUser)+ ngOnDestroy () {+ if (this.resizeSub) this.resizeSub.unsubscribe()+ if (this.routeSub) this.routeSub.unsubscribe()+ if (this.userSub) this.userSub.unsubscribe()}videoById (_index: number, video: Video) {@@ -297,96 +261,6 @@ export class VideosListComponent implements OnInit, OnChanges, OnDestroy {this.highlightedLives = this.highlightedLives.filter(v => v.id !== video.id)}- buildGroupedDateLabels () {- let currentGroupedDate: GroupDate = GroupDate.UNKNOWN-- const periods = [- {- value: GroupDate.TODAY,- validator: (d: Date) => isToday(d)- },- {- value: GroupDate.YESTERDAY,- validator: (d: Date) => isYesterday(d)- },- {- value: GroupDate.THIS_WEEK,- validator: (d: Date) => isLastWeek(d)- },- {- value: GroupDate.THIS_MONTH,- validator: (d: Date) => isThisMonth(d)- },- {- value: GroupDate.LAST_MONTH,- validator: (d: Date) => isLastMonth(d)- },- {- value: GroupDate.OLDER,- validator: () => true- }- ]-- let onlyOlderPeriod = true-- for (const video of this.videos) {- const publishedDate = video.publishedAt-- for (let i = 0; i < periods.length; i++) {- const period = periods[i]-- if (currentGroupedDate <= period.value && period.validator(publishedDate)) {- if (currentGroupedDate !== period.value) {- if (period.value !== GroupDate.OLDER) onlyOlderPeriod = false-- currentGroupedDate = period.value- this.groupedDates[video.id] = currentGroupedDate- }-- break- }- }- }-- // No need to group by date, there is only "Older" period available- if (onlyOlderPeriod) this.groupedDates = {}- }-- getCurrentGroupedDateLabel (video: Video) {- if (this.groupByDate() === false) return undefined-- return this.groupedDateLabels[this.groupedDates[video.id]]- }-- scheduleOnFiltersChanged (customizedByUser: boolean) {- // We'll reload videos, but avoid weird UI effect- this.videos = []- this.highlightedLives = []-- setTimeout(() => this.onFiltersChanged(customizedByUser))- }-- onFiltersChanged (customizedByUser: boolean) {- debugLogger('Running on filters changed')-- this.updateUrl(customizedByUser)-- this.filters.triggerChange()-- this.reloadSyndicationItems()- this.reloadVideos()- }-- protected enableAllFilterIfPossible () {- if (!this.authService.isLoggedIn()) return-- this.authService.userInformationLoaded- .subscribe(() => {- const user = this.authService.getUser()- this.builtDisplayModerationBlock = user.hasRight(UserRight.SEE_ALL_VIDEOS)- })- }-private calcPageSizes () {if (this.screenService.isInMobileView()) {this.pagination.itemsPerPage = 5@@ -394,12 +268,9 @@ export class VideosListComponent implements OnInit, OnChanges, OnDestroy {}private loadUserSettings (user: User) {- this.filters.setNSFWPolicy(user.nsfwPolicy)+ const nsfw = this.filters.setNSFWPolicy(user.nsfwPolicy)- // Don't reset language filter if we don't want to refresh the component- if (!this.hasBeenCustomizedByUser()) {- this.filters.load({ languageOneOf: user.videoLanguages })- }+ this.filters.load({ languageOneOf: user.videoLanguages, nsfw })}private reloadSyndicationItems () {@@ -411,31 +282,22 @@ export class VideosListComponent implements OnInit, OnChanges, OnDestroy {.catch(err => logger.error('Cannot get syndication items.', err))}- private updateUrl (customizedByUser: boolean) {- const baseQuery = this.filters.toUrlObject()-- // Set or reset customized by user query param- const queryParams = customizedByUser || this.hasBeenCustomizedByUser()- ? { ...baseQuery, c: customizedByUser }- : baseQuery+ private updateUrl () {+ const queryParams = this.filters.toUrlObject()- debugLogger('Will inject %O in URL query', queryParams)+ debugLogger('Will inject URL query', { queryParams })- if (Object.keys(baseQuery).length !== 0 || customizedByUser) {+ if (Object.keys(queryParams).length !== 0 || this.filters.hasBeenCustomizedByUser()) {this.peertubeRouter.silentNavigate([], queryParams)}-- this.filtersChanged.emit(this.filters)- }-- private hasBeenCustomizedByUser () {- return this.route.snapshot.queryParams['c'] === 'true'}private subscribeToAnonymousUpdate () {this.userSub = this.userService.listenAnonymousUpdate().pipe(switchMap(() => this.userService.getAnonymousOrLoggedUser())).subscribe(user => {+ debugLogger('User changed', { user })+if (this.loadUserVideoPreferences()) {this.loadUserSettings(user)}@@ -446,13 +308,21 @@ export class VideosListComponent implements OnInit, OnChanges, OnDestroy {})}- private subscribeToSearchChange () {- this.routeSub = this.route.queryParams.subscribe(param => {- if (!this.alreadyDoneSearch && !param['search']) return+ private subscribeToQueryParamsChange () {+ this.routeSub = this.route.queryParams.subscribe(params => {+ if (Object.keys(params).length === 0 && !this.filters.hasBeenCustomizedByUser()) return++ let search = params.search++ if (search) {+ this.alreadyDoneSearch = true+ } else if (this.alreadyDoneSearch) {+ search = ''+ }++ debugLogger('Query params changed', params)- this.alreadyDoneSearch = true- this.filters.load({ search: param['search'] })- this.onFiltersChanged(true)+ this.filters.load(params)})}@@ -492,4 +362,67 @@ export class VideosListComponent implements OnInit, OnChanges, OnDestroy {}})}++ // ---------------------------------------------------------------------------++ private buildGroupedDateLabels () {+ let currentGroupedDate: GroupDate = GroupDate.UNKNOWN++ const periods = [+ {+ value: GroupDate.TODAY,+ validator: (d: Date) => isToday(d)+ },+ {+ value: GroupDate.YESTERDAY,+ validator: (d: Date) => isYesterday(d)+ },+ {+ value: GroupDate.THIS_WEEK,+ validator: (d: Date) => isLastWeek(d)+ },+ {+ value: GroupDate.THIS_MONTH,+ validator: (d: Date) => isThisMonth(d)+ },+ {+ value: GroupDate.LAST_MONTH,+ validator: (d: Date) => isLastMonth(d)+ },+ {+ value: GroupDate.OLDER,+ validator: () => true+ }+ ]++ let onlyOlderPeriod = true++ for (const video of this.videos) {+ const publishedDate = video.publishedAt++ for (let i = 0; i < periods.length; i++) {+ const period = periods[i]++ if (currentGroupedDate <= period.value && period.validator(publishedDate)) {+ if (currentGroupedDate !== period.value) {+ if (period.value !== GroupDate.OLDER) onlyOlderPeriod = false++ currentGroupedDate = period.value+ this.groupedDates[video.id] = currentGroupedDate+ }++ break+ }+ }+ }++ // No need to group by date, there is only "Older" period available+ if (onlyOlderPeriod) this.groupedDates = {}+ }++ getCurrentGroupedDateLabel (video: Video) {+ if (this.groupByDate() === false) return undefined++ return this.groupedDateLabels[this.groupedDates[video.id]]+ }}diff --git a/packages/tests/src/api/check-params/videos.ts b/packages/tests/src/api/check-params/videos.tsindex b4513fae4e..ce86caa734 100644--- a/packages/tests/src/api/check-params/videos.ts+++ b/packages/tests/src/api/check-params/videos.ts@@ -17,7 +17,6 @@ import {import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@tests/shared/checks.js'import { checkUploadVideoParam } from '@tests/shared/videos.js'import { expect } from 'chai'-import { join } from 'path'describe('Test videos API validator', function () {const path = '/api/v1/videos/'