]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/modal/account-setup-modal.component.ts
4cb8de2c778dc53db1f5bdf1b415b5483f4f1b43
[github/Chocobozzz/PeerTube.git] / client / src / app / modal / account-setup-modal.component.ts
1 import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
2 import { AuthService, ServerService, User, UserService } from '@app/core'
3 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
4 import { HTMLServerConfig } from '@shared/models'
5
6 @Component({
7 selector: 'my-account-setup-modal',
8 templateUrl: './account-setup-modal.component.html',
9 styleUrls: [ './account-setup-modal.component.scss' ]
10 })
11 export class AccountSetupModalComponent implements OnInit {
12 @ViewChild('modal', { static: true }) modal: ElementRef
13
14 user: User = null
15 ref: NgbModalRef = null
16
17 private serverConfig: HTMLServerConfig
18
19 constructor (
20 private userService: UserService,
21 private authService: AuthService,
22 private modalService: NgbModal,
23 private serverService: ServerService
24 ) { }
25
26 get userInformationLoaded () {
27 return this.authService.userInformationLoaded
28 }
29
30 get instanceName () {
31 return this.serverConfig.instance.name
32 }
33
34 get isUserRoot () {
35 return this.user.username === 'root'
36 }
37
38 get hasAccountAvatar () {
39 return !!this.user.account.avatar
40 }
41
42 get hasAccountDescription () {
43 return !!this.user.account.description
44 }
45
46 ngOnInit () {
47 this.serverConfig = this.serverService.getHTMLConfig()
48
49 this.authService.userInformationLoaded
50 .subscribe(
51 () => {
52 this.user = this.authService.getUser()
53
54 if (this.isUserRoot) return
55 if (this.hasAccountAvatar && this.hasAccountDescription) return
56 if (this.userService.hasSignupInThisSession()) return
57
58 this.show()
59 }
60 )
61 }
62
63 show () {
64 if (this.ref) return
65
66 this.ref = this.modalService.open(this.modal, {
67 centered: true,
68 backdrop: 'static',
69 keyboard: false,
70 size: 'md'
71 })
72 }
73 }