]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/modal/account-setup-warning-modal.component.ts
Translated using Weblate (Persian)
[github/Chocobozzz/PeerTube.git] / client / src / app / modal / account-setup-warning-modal.component.ts
1 import { Component, ElementRef, ViewChild } from '@angular/core'
2 import { Notifier, ServerService, User, UserService } from '@app/core'
3 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
4 import { logger } from '@root-helpers/logger'
5 import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
6
7 @Component({
8 selector: 'my-account-setup-warning-modal',
9 templateUrl: './account-setup-warning-modal.component.html',
10 styleUrls: [ './account-setup-warning-modal.component.scss' ]
11 })
12 export class AccountSetupWarningModalComponent {
13 @ViewChild('modal', { static: true }) modal: ElementRef
14
15 stopDisplayModal = false
16 ref: NgbModalRef
17
18 user: User
19
20 private LOCAL_STORAGE_KEYS = {
21 NO_ACCOUNT_SETUP_WARNING_MODAL: 'no_account_setup_warning_modal'
22 }
23
24 constructor (
25 private userService: UserService,
26 private modalService: NgbModal,
27 private notifier: Notifier,
28 private serverService: ServerService
29 ) { }
30
31 get instanceName () {
32 return this.serverService.getHTMLConfig().instance.name
33 }
34
35 hasAccountAvatar (user: User) {
36 return user.account.avatars.length !== 0
37 }
38
39 hasAccountDescription (user: User) {
40 return !!user.account.description
41 }
42
43 shouldOpen (user: User) {
44 if (user.noAccountSetupWarningModal === true) return false
45 if (peertubeLocalStorage.getItem(this.LOCAL_STORAGE_KEYS.NO_ACCOUNT_SETUP_WARNING_MODAL) === 'true') return false
46
47 if (this.hasAccountAvatar(user) && this.hasAccountDescription(user)) return false
48 if (this.userService.hasSignupInThisSession()) return false
49
50 return true
51 }
52
53 show (user: User) {
54 this.user = user
55
56 if (this.ref) return
57
58 this.ref = this.modalService.open(this.modal, {
59 centered: true,
60 backdrop: 'static',
61 keyboard: false,
62 size: 'md'
63 })
64
65 this.ref.result.finally(() => {
66 if (this.stopDisplayModal === true) this.doNotOpenAgain()
67 })
68 }
69
70 private doNotOpenAgain () {
71 peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_ACCOUNT_SETUP_WARNING_MODAL, 'true')
72
73 this.userService.updateMyProfile({ noAccountSetupWarningModal: true })
74 .subscribe({
75 next: () => logger.info('We will not open the account setup modal again.'),
76
77 error: err => this.notifier.error(err.message)
78 })
79 }
80 }