diff options
Diffstat (limited to 'client/src/app/shared/video/abstract-video-list.ts')
-rw-r--r-- | client/src/app/shared/video/abstract-video-list.ts | 69 |
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 @@ | |||
1 | import { debounceTime, first, tap, throttleTime } from 'rxjs/operators' | 1 | import { fromEvent, Observable, of, Subject, Subscription } from 'rxjs' |
2 | import { debounceTime, tap, throttleTime, switchMap } from 'rxjs/operators' | ||
2 | import { OnDestroy, OnInit } from '@angular/core' | 3 | import { OnDestroy, OnInit } from '@angular/core' |
3 | import { ActivatedRoute, Router } from '@angular/router' | 4 | import { ActivatedRoute, Router } from '@angular/router' |
4 | import { fromEvent, Observable, of, Subject, Subscription } from 'rxjs' | ||
5 | import { AuthService } from '../../core/auth' | ||
6 | import { ComponentPaginationLight } from '../rest/component-pagination.model' | ||
7 | import { VideoSortField } from './sort-field.type' | ||
8 | import { Video } from './video.model' | ||
9 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
10 | import { MiniatureDisplayOptions, OwnerDisplayType } from '@app/shared/video/video-miniature.component' | ||
11 | import { Syndication } from '@app/shared/video/syndication.model' | ||
12 | import { Notifier, ServerService } from '@app/core' | 5 | import { Notifier, ServerService } from '@app/core' |
13 | import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' | 6 | import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' |
7 | import { GlobalIconName } from '@app/shared/images/global-icon.component' | ||
8 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
9 | import { Syndication } from '@app/shared/video/syndication.model' | ||
10 | import { MiniatureDisplayOptions, OwnerDisplayType } from '@app/shared/video/video-miniature.component' | ||
14 | import { I18n } from '@ngx-translate/i18n-polyfill' | 11 | import { I18n } from '@ngx-translate/i18n-polyfill' |
15 | import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' | 12 | import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' |
16 | import { ServerConfig } from '@shared/models' | 13 | import { ServerConfig } from '@shared/models' |
17 | import { GlobalIconName } from '@app/shared/images/global-icon.component' | 14 | import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' |
18 | import { UserService, User } from '../users' | 15 | import { AuthService } from '../../core/auth' |
19 | import { LocalStorageService } from '../misc/storage.service' | 16 | import { LocalStorageService } from '../misc/storage.service' |
17 | import { ComponentPaginationLight } from '../rest/component-pagination.model' | ||
18 | import { User, UserService } from '../users' | ||
19 | import { VideoSortField } from './sort-field.type' | ||
20 | import { Video } from './video.model' | ||
20 | 21 | ||
21 | enum GroupDate { | 22 | enum 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 | } |