]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-moderation/server-blocklist.component.ts
Fix lint
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / server-blocklist.component.ts
CommitLineData
67ed6552 1import { SortMeta } from 'primeng/api'
a02b93ce 2import { Directive, OnInit, ViewChild } from '@angular/core'
67ed6552 3import { Notifier, RestPagination, RestTable } from '@app/core'
a02b93ce 4import { BatchDomainsModalComponent } from '@app/shared/shared-moderation/batch-domains-modal.component'
22839330 5import { I18n } from '@ngx-translate/i18n-polyfill'
67ed6552
C
6import { ServerBlock } from '@shared/models'
7import { BlocklistComponentType, BlocklistService } from './blocklist.service'
22839330 8
583eb04b 9@Directive()
a02b93ce 10// tslint:disable-next-line: directive-class-suffix
22839330
RK
11export class GenericServerBlocklistComponent extends RestTable implements OnInit {
12 @ViewChild('batchDomainsModal') batchDomainsModal: BatchDomainsModalComponent
13
14 // @ts-ignore: "Abstract methods can only appear within an abstract class"
15 public abstract mode: BlocklistComponentType
16
17 blockedServers: ServerBlock[] = []
18 totalRecords = 0
19 sort: SortMeta = { field: 'createdAt', order: -1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
21
22 constructor (
23 protected notifier: Notifier,
24 protected blocklistService: BlocklistService,
25 protected i18n: I18n
26 ) {
27 super()
28 }
29
67ed6552
C
30 // @ts-ignore: "Abstract methods can only appear within an abstract class"
31 public abstract getIdentifier (): string
32
22839330
RK
33 ngOnInit () {
34 this.initialize()
35 }
36
22839330
RK
37 unblockServer (serverBlock: ServerBlock) {
38 const operation = (host: string) => this.mode === BlocklistComponentType.Account
39 ? this.blocklistService.unblockServerByUser(host)
40 : this.blocklistService.unblockServerByInstance(host)
41 const host = serverBlock.blockedServer.host
42
43 operation(host).subscribe(
44 () => {
45 this.notifier.success(
46 this.mode === BlocklistComponentType.Account
47 ? this.i18n('Instance {{host}} unmuted.', { host })
48 : this.i18n('Instance {{host}} unmuted by your instance.', { host })
49 )
50
51 this.loadData()
52 }
53 )
54 }
55
56 addServersToBlock () {
57 this.batchDomainsModal.openModal()
58 }
59
60 onDomainsToBlock (domains: string[]) {
61 const operation = (domain: string) => this.mode === BlocklistComponentType.Account
62 ? this.blocklistService.blockServerByUser(domain)
63 : this.blocklistService.blockServerByInstance(domain)
64
65 domains.forEach(domain => {
66 operation(domain).subscribe(
67 () => {
68 this.notifier.success(
69 this.mode === BlocklistComponentType.Account
70 ? this.i18n('Instance {{domain}} muted.', { domain })
71 : this.i18n('Instance {{domain}} muted by your instance.', { domain })
72 )
73
74 this.loadData()
75 }
76 )
77 })
78 }
79
80 protected loadData () {
81 const operation = this.mode === BlocklistComponentType.Account
82 ? this.blocklistService.getUserServerBlocklist({
83 pagination: this.pagination,
84 sort: this.sort,
85 search: this.search
86 })
87 : this.blocklistService.getInstanceServerBlocklist({
88 pagination: this.pagination,
89 sort: this.sort,
90 search: this.search
91 })
92
93 return operation.subscribe(
94 resultList => {
95 this.blockedServers = resultList.data
96 this.totalRecords = resultList.total
97 },
98
99 err => this.notifier.error(err.message)
100 )
101 }
102}