diff options
Diffstat (limited to 'client/src/app/app.component.ts')
-rw-r--r-- | client/src/app/app.component.ts | 71 |
1 files changed, 40 insertions, 31 deletions
diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index ae6046cc1..86b687173 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { Hotkey, HotkeysService } from 'angular2-hotkeys' | 1 | import { Hotkey, HotkeysService } from 'angular2-hotkeys' |
2 | import { filter, map, switchMap } from 'rxjs/operators' | 2 | import { forkJoin } from 'rxjs' |
3 | import { filter, first, map } from 'rxjs/operators' | ||
3 | import { DOCUMENT, getLocaleDirection, PlatformLocation } from '@angular/common' | 4 | import { DOCUMENT, getLocaleDirection, PlatformLocation } from '@angular/common' |
4 | import { AfterViewInit, Component, Inject, LOCALE_ID, OnInit, ViewChild } from '@angular/core' | 5 | import { AfterViewInit, Component, Inject, LOCALE_ID, OnInit, ViewChild } from '@angular/core' |
5 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' | 6 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' |
@@ -17,15 +18,15 @@ import { | |||
17 | } from '@app/core' | 18 | } from '@app/core' |
18 | import { HooksService } from '@app/core/plugins/hooks.service' | 19 | import { HooksService } from '@app/core/plugins/hooks.service' |
19 | import { PluginService } from '@app/core/plugins/plugin.service' | 20 | import { PluginService } from '@app/core/plugins/plugin.service' |
21 | import { AccountSetupWarningModalComponent } from '@app/modal/account-setup-warning-modal.component' | ||
20 | import { CustomModalComponent } from '@app/modal/custom-modal.component' | 22 | import { CustomModalComponent } from '@app/modal/custom-modal.component' |
21 | import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component' | 23 | import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component' |
22 | import { WelcomeModalComponent } from '@app/modal/welcome-modal.component' | 24 | import { AdminWelcomeModalComponent } from '@app/modal/admin-welcome-modal.component' |
23 | import { AccountSetupModalComponent } from '@app/modal/account-setup-modal.component' | ||
24 | import { NgbConfig, NgbModal } from '@ng-bootstrap/ng-bootstrap' | 25 | import { NgbConfig, NgbModal } from '@ng-bootstrap/ng-bootstrap' |
25 | import { LoadingBarService } from '@ngx-loading-bar/core' | 26 | import { LoadingBarService } from '@ngx-loading-bar/core' |
26 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' | 27 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' |
27 | import { getShortLocale } from '@shared/core-utils/i18n' | 28 | import { getShortLocale } from '@shared/core-utils/i18n' |
28 | import { BroadcastMessageLevel, HTMLServerConfig, ServerConfig, UserRole } from '@shared/models' | 29 | import { BroadcastMessageLevel, HTMLServerConfig, UserRole } from '@shared/models' |
29 | import { MenuService } from './core/menu/menu.service' | 30 | import { MenuService } from './core/menu/menu.service' |
30 | import { POP_STATE_MODAL_DISMISS } from './helpers' | 31 | import { POP_STATE_MODAL_DISMISS } from './helpers' |
31 | import { InstanceService } from './shared/shared-instance' | 32 | import { InstanceService } from './shared/shared-instance' |
@@ -38,8 +39,8 @@ import { InstanceService } from './shared/shared-instance' | |||
38 | export class AppComponent implements OnInit, AfterViewInit { | 39 | export class AppComponent implements OnInit, AfterViewInit { |
39 | private static BROADCAST_MESSAGE_KEY = 'app-broadcast-message-dismissed' | 40 | private static BROADCAST_MESSAGE_KEY = 'app-broadcast-message-dismissed' |
40 | 41 | ||
41 | @ViewChild('accountSetupModal') accountSetupModal: AccountSetupModalComponent | 42 | @ViewChild('accountSetupWarningModal') accountSetupWarningModal: AccountSetupWarningModalComponent |
42 | @ViewChild('welcomeModal') welcomeModal: WelcomeModalComponent | 43 | @ViewChild('adminWelcomeModal') adminWelcomeModal: AdminWelcomeModalComponent |
43 | @ViewChild('instanceConfigWarningModal') instanceConfigWarningModal: InstanceConfigWarningModalComponent | 44 | @ViewChild('instanceConfigWarningModal') instanceConfigWarningModal: InstanceConfigWarningModalComponent |
44 | @ViewChild('customModal') customModal: CustomModalComponent | 45 | @ViewChild('customModal') customModal: CustomModalComponent |
45 | 46 | ||
@@ -221,33 +222,41 @@ export class AppComponent implements OnInit, AfterViewInit { | |||
221 | } | 222 | } |
222 | 223 | ||
223 | private openModalsIfNeeded () { | 224 | private openModalsIfNeeded () { |
224 | this.authService.userInformationLoaded | 225 | const userSub = this.authService.userInformationLoaded |
225 | .pipe( | 226 | .pipe(map(() => this.authService.getUser())) |
226 | map(() => this.authService.getUser()), | 227 | |
227 | filter(user => user.role === UserRole.ADMINISTRATOR), | 228 | // Admin modal |
228 | switchMap(user => { | 229 | userSub.pipe( |
229 | return this.serverService.getConfig() | 230 | filter(user => user.role === UserRole.ADMINISTRATOR) |
230 | .pipe(map(serverConfig => ({ serverConfig, user }))) | 231 | ).subscribe(user => this.openAdminModalsIfNeeded(user)) |
231 | }) | 232 | |
232 | ).subscribe(({ serverConfig, user }) => this._openAdminModalsIfNeeded(serverConfig, user)) | 233 | // Account modal |
234 | userSub.pipe( | ||
235 | filter(user => user.role !== UserRole.ADMINISTRATOR) | ||
236 | ).subscribe(user => this.openAccountModalsIfNeeded(user)) | ||
233 | } | 237 | } |
234 | 238 | ||
235 | private _openAdminModalsIfNeeded (serverConfig: ServerConfig, user: User) { | 239 | private openAdminModalsIfNeeded (user: User) { |
236 | if (user.noWelcomeModal !== true) return this.welcomeModal.show() | 240 | if (this.adminWelcomeModal.shouldOpen(user)) { |
237 | 241 | return this.adminWelcomeModal.show() | |
238 | if (user.noInstanceConfigWarningModal === true || !serverConfig.signup.allowed) return | 242 | } |
239 | 243 | ||
240 | this.instanceService.getAbout() | 244 | if (!this.instanceConfigWarningModal.shouldOpenByUser(user)) return |
241 | .subscribe(about => { | 245 | |
242 | if ( | 246 | forkJoin([ |
243 | this.serverConfig.instance.name.toLowerCase() === 'peertube' || | 247 | this.serverService.getConfig().pipe(first()), |
244 | !about.instance.terms || | 248 | this.instanceService.getAbout().pipe(first()) |
245 | !about.instance.administrator || | 249 | ]).subscribe(([ config, about ]) => { |
246 | !about.instance.maintenanceLifetime | 250 | if (this.instanceConfigWarningModal.shouldOpen(config, about)) { |
247 | ) { | 251 | this.instanceConfigWarningModal.show(about) |
248 | this.instanceConfigWarningModal.show(about) | 252 | } |
249 | } | 253 | }) |
250 | }) | 254 | } |
255 | |||
256 | private openAccountModalsIfNeeded (user: User) { | ||
257 | if (this.accountSetupWarningModal.shouldOpen(user)) { | ||
258 | this.accountSetupWarningModal.show(user) | ||
259 | } | ||
251 | } | 260 | } |
252 | 261 | ||
253 | private initHotkeys () { | 262 | private initHotkeys () { |