]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/moderation/instance-blocklist/instance-server-blocklist.component.ts
Add filter inputs for blacklisted videos and muted accounts/servers
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / moderation / instance-blocklist / instance-server-blocklist.component.ts
1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { I18n } from '@ngx-translate/i18n-polyfill'
4 import { RestPagination, RestTable } from '@app/shared'
5 import { SortMeta } from 'primeng/api'
6 import { BlocklistService } from '@app/shared/blocklist'
7 import { ServerBlock } from '../../../../../../shared'
8 import { BatchDomainsModalComponent } from '@app/+admin/config/shared/batch-domains-modal.component'
9
10 @Component({
11 selector: 'my-instance-server-blocklist',
12 styleUrls: [ '../moderation.component.scss', './instance-server-blocklist.component.scss' ],
13 templateUrl: './instance-server-blocklist.component.html'
14 })
15 export class InstanceServerBlocklistComponent extends RestTable implements OnInit {
16 @ViewChild('batchDomainsModal') batchDomainsModal: BatchDomainsModalComponent
17
18 blockedServers: ServerBlock[] = []
19 totalRecords = 0
20 rowsPerPageOptions = [ 20, 50, 100 ]
21 rowsPerPage = this.rowsPerPageOptions[0]
22 sort: SortMeta = { field: 'createdAt', order: -1 }
23 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
24
25 constructor (
26 private notifier: Notifier,
27 private blocklistService: BlocklistService,
28 private i18n: I18n
29 ) {
30 super()
31 }
32
33 ngOnInit () {
34 this.initialize()
35 }
36
37 getIdentifier () {
38 return 'InstanceServerBlocklistComponent'
39 }
40
41 unblockServer (serverBlock: ServerBlock) {
42 const host = serverBlock.blockedServer.host
43
44 this.blocklistService.unblockServerByInstance(host)
45 .subscribe(
46 () => {
47 this.notifier.success(this.i18n('Instance {{host}} unmuted by your instance.', { host }))
48
49 this.loadData()
50 }
51 )
52 }
53
54 httpEnabled () {
55 return window.location.protocol === 'https:'
56 }
57
58 addServersToBlock () {
59 this.batchDomainsModal.openModal()
60 }
61
62 onDomainsToBlock (domains: string[]) {
63 domains.forEach(domain => {
64 this.blocklistService.blockServerByInstance(domain)
65 .subscribe(
66 () => {
67 this.notifier.success(this.i18n('Instance {{domain}} muted by your instance.', { domain }))
68
69 this.loadData()
70 }
71 )
72 })
73 }
74
75 protected loadData () {
76 return this.blocklistService.getInstanceServerBlocklist({
77 pagination: this.pagination,
78 sort: this.sort,
79 search: this.search
80 })
81 .subscribe(
82 resultList => {
83 this.blockedServers = resultList.data
84 this.totalRecords = resultList.total
85 },
86
87 err => this.notifier.error(err.message)
88 )
89 }
90 }