aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/app.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/app.component.ts')
-rw-r--r--client/src/app/app.component.ts71
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 @@
1import { Hotkey, HotkeysService } from 'angular2-hotkeys' 1import { Hotkey, HotkeysService } from 'angular2-hotkeys'
2import { filter, map, switchMap } from 'rxjs/operators' 2import { forkJoin } from 'rxjs'
3import { filter, first, map } from 'rxjs/operators'
3import { DOCUMENT, getLocaleDirection, PlatformLocation } from '@angular/common' 4import { DOCUMENT, getLocaleDirection, PlatformLocation } from '@angular/common'
4import { AfterViewInit, Component, Inject, LOCALE_ID, OnInit, ViewChild } from '@angular/core' 5import { AfterViewInit, Component, Inject, LOCALE_ID, OnInit, ViewChild } from '@angular/core'
5import { DomSanitizer, SafeHtml } from '@angular/platform-browser' 6import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
@@ -17,15 +18,15 @@ import {
17} from '@app/core' 18} from '@app/core'
18import { HooksService } from '@app/core/plugins/hooks.service' 19import { HooksService } from '@app/core/plugins/hooks.service'
19import { PluginService } from '@app/core/plugins/plugin.service' 20import { PluginService } from '@app/core/plugins/plugin.service'
21import { AccountSetupWarningModalComponent } from '@app/modal/account-setup-warning-modal.component'
20import { CustomModalComponent } from '@app/modal/custom-modal.component' 22import { CustomModalComponent } from '@app/modal/custom-modal.component'
21import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component' 23import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component'
22import { WelcomeModalComponent } from '@app/modal/welcome-modal.component' 24import { AdminWelcomeModalComponent } from '@app/modal/admin-welcome-modal.component'
23import { AccountSetupModalComponent } from '@app/modal/account-setup-modal.component'
24import { NgbConfig, NgbModal } from '@ng-bootstrap/ng-bootstrap' 25import { NgbConfig, NgbModal } from '@ng-bootstrap/ng-bootstrap'
25import { LoadingBarService } from '@ngx-loading-bar/core' 26import { LoadingBarService } from '@ngx-loading-bar/core'
26import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' 27import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
27import { getShortLocale } from '@shared/core-utils/i18n' 28import { getShortLocale } from '@shared/core-utils/i18n'
28import { BroadcastMessageLevel, HTMLServerConfig, ServerConfig, UserRole } from '@shared/models' 29import { BroadcastMessageLevel, HTMLServerConfig, UserRole } from '@shared/models'
29import { MenuService } from './core/menu/menu.service' 30import { MenuService } from './core/menu/menu.service'
30import { POP_STATE_MODAL_DISMISS } from './helpers' 31import { POP_STATE_MODAL_DISMISS } from './helpers'
31import { InstanceService } from './shared/shared-instance' 32import { InstanceService } from './shared/shared-instance'
@@ -38,8 +39,8 @@ import { InstanceService } from './shared/shared-instance'
38export class AppComponent implements OnInit, AfterViewInit { 39export 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 () {