aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video/abstract-video-list.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/video/abstract-video-list.ts')
-rw-r--r--client/src/app/shared/video/abstract-video-list.ts69
1 files changed, 30 insertions, 39 deletions
diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts
index 76aa683fc..0bc339ff6 100644
--- a/client/src/app/shared/video/abstract-video-list.ts
+++ b/client/src/app/shared/video/abstract-video-list.ts
@@ -1,22 +1,23 @@
1import { debounceTime, first, tap, throttleTime } from 'rxjs/operators' 1import { fromEvent, Observable, of, Subject, Subscription } from 'rxjs'
2import { debounceTime, tap, throttleTime, switchMap } from 'rxjs/operators'
2import { OnDestroy, OnInit } from '@angular/core' 3import { OnDestroy, OnInit } from '@angular/core'
3import { ActivatedRoute, Router } from '@angular/router' 4import { ActivatedRoute, Router } from '@angular/router'
4import { fromEvent, Observable, of, Subject, Subscription } from 'rxjs'
5import { AuthService } from '../../core/auth'
6import { ComponentPaginationLight } from '../rest/component-pagination.model'
7import { VideoSortField } from './sort-field.type'
8import { Video } from './video.model'
9import { ScreenService } from '@app/shared/misc/screen.service'
10import { MiniatureDisplayOptions, OwnerDisplayType } from '@app/shared/video/video-miniature.component'
11import { Syndication } from '@app/shared/video/syndication.model'
12import { Notifier, ServerService } from '@app/core' 5import { Notifier, ServerService } from '@app/core'
13import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' 6import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook'
7import { GlobalIconName } from '@app/shared/images/global-icon.component'
8import { ScreenService } from '@app/shared/misc/screen.service'
9import { Syndication } from '@app/shared/video/syndication.model'
10import { MiniatureDisplayOptions, OwnerDisplayType } from '@app/shared/video/video-miniature.component'
14import { I18n } from '@ngx-translate/i18n-polyfill' 11import { I18n } from '@ngx-translate/i18n-polyfill'
15import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' 12import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date'
16import { ServerConfig } from '@shared/models' 13import { ServerConfig } from '@shared/models'
17import { GlobalIconName } from '@app/shared/images/global-icon.component' 14import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type'
18import { UserService, User } from '../users' 15import { AuthService } from '../../core/auth'
19import { LocalStorageService } from '../misc/storage.service' 16import { LocalStorageService } from '../misc/storage.service'
17import { ComponentPaginationLight } from '../rest/component-pagination.model'
18import { User, UserService } from '../users'
19import { VideoSortField } from './sort-field.type'
20import { Video } from './video.model'
20 21
21enum GroupDate { 22enum GroupDate {
22 UNKNOWN = 0, 23 UNKNOWN = 0,
@@ -34,14 +35,15 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor
34 } 35 }
35 sort: VideoSortField = '-publishedAt' 36 sort: VideoSortField = '-publishedAt'
36 37
37 categoryOneOf?: number 38 categoryOneOf?: number[]
38 languageOneOf?: string[] 39 languageOneOf?: string[]
40 nsfwPolicy?: NSFWPolicyType
39 defaultSort: VideoSortField = '-publishedAt' 41 defaultSort: VideoSortField = '-publishedAt'
40 42
41 syndicationItems: Syndication[] = [] 43 syndicationItems: Syndication[] = []
42 44
43 loadOnInit = true 45 loadOnInit = true
44 useUserVideoLanguagePreferences = false 46 useUserVideoPreferences = false
45 ownerDisplayType: OwnerDisplayType = 'account' 47 ownerDisplayType: OwnerDisplayType = 'account'
46 displayModerationBlock = false 48 displayModerationBlock = false
47 titleTooltip: string 49 titleTooltip: string
@@ -71,6 +73,8 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor
71 73
72 onDataSubject = new Subject<any[]>() 74 onDataSubject = new Subject<any[]>()
73 75
76 userMiniature: User
77
74 protected serverConfig: ServerConfig 78 protected serverConfig: ServerConfig
75 79
76 protected abstract notifier: Notifier 80 protected abstract notifier: Notifier
@@ -96,10 +100,6 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor
96 100
97 abstract generateSyndicationList (): void 101 abstract generateSyndicationList (): void
98 102
99 get user () {
100 return this.authService.getUser()
101 }
102
103 ngOnInit () { 103 ngOnInit () {
104 this.serverConfig = this.serverService.getTmpConfig() 104 this.serverConfig = this.serverService.getTmpConfig()
105 this.serverService.getConfig() 105 this.serverService.getConfig()
@@ -124,21 +124,17 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor
124 124
125 this.calcPageSizes() 125 this.calcPageSizes()
126 126
127 const loadUserObservable = this.loadUserVideoLanguagesIfNeeded() 127 const loadUserObservable = this.loadUserAndSettings()
128 128
129 if (this.loadOnInit === true) { 129 if (this.loadOnInit === true) {
130 loadUserObservable.subscribe(() => this.loadMoreVideos()) 130 loadUserObservable.subscribe(() => this.loadMoreVideos())
131 } 131 }
132 132
133 this.storageService.watch([ 133 this.userService.listenAnonymousUpdate()
134 User.KEYS.NSFW_POLICY, 134 .pipe(switchMap(() => this.loadUserAndSettings()))
135 User.KEYS.VIDEO_LANGUAGES 135 .subscribe(() => {
136 ]).pipe(throttleTime(200)).subscribe(
137 () => {
138 this.loadUserVideoLanguagesIfNeeded()
139 if (this.hasDoneFirstQuery) this.reloadVideos() 136 if (this.hasDoneFirstQuery) this.reloadVideos()
140 } 137 })
141 )
142 138
143 // Display avatar in mobile view 139 // Display avatar in mobile view
144 if (this.screenService.isInMobileView()) { 140 if (this.screenService.isInMobileView()) {
@@ -298,20 +294,15 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor
298 this.router.navigate([ path ], { queryParams, replaceUrl: true, queryParamsHandling: 'merge' }) 294 this.router.navigate([ path ], { queryParams, replaceUrl: true, queryParamsHandling: 'merge' })
299 } 295 }
300 296
301 private loadUserVideoLanguagesIfNeeded () { 297 private loadUserAndSettings () {
302 if (!this.useUserVideoLanguagePreferences) { 298 return this.userService.getAnonymousOrLoggedUser()
303 return of(true) 299 .pipe(tap(user => {
304 } 300 this.userMiniature = user
305 301
306 if (!this.authService.isLoggedIn()) { 302 if (!this.useUserVideoPreferences) return
307 this.languageOneOf = this.userService.getAnonymousUser().videoLanguages
308 return of(true)
309 }
310 303
311 return this.authService.userInformationLoaded 304 this.languageOneOf = user.videoLanguages
312 .pipe( 305 this.nsfwPolicy = user.nsfwPolicy
313 first(), 306 }))
314 tap(() => this.languageOneOf = this.user.videoLanguages)
315 )
316 } 307 }
317} 308}