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