1 import { SortMeta } from 'primeng/api'
2 import { OnInit, ViewChild } from '@angular/core'
3 import { BatchDomainsModalComponent } from '@app/shared/shared-moderation/batch-domains-modal.component'
4 import { Notifier, RestPagination, RestTable } from '@app/core'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { ServerBlock } from '@shared/models'
7 import { BlocklistComponentType, BlocklistService } from './blocklist.service'
9 export class GenericServerBlocklistComponent extends RestTable implements OnInit {
10 @ViewChild('batchDomainsModal') batchDomainsModal: BatchDomainsModalComponent
12 // @ts-ignore: "Abstract methods can only appear within an abstract class"
13 public abstract mode: BlocklistComponentType
15 blockedServers: ServerBlock[] = []
17 sort: SortMeta = { field: 'createdAt', order: -1 }
18 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
21 protected notifier: Notifier,
22 protected blocklistService: BlocklistService,
28 // @ts-ignore: "Abstract methods can only appear within an abstract class"
29 public abstract getIdentifier (): string
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
41 operation(host).subscribe(
43 this.notifier.success(
44 this.mode === BlocklistComponentType.Account
45 ? this.i18n('Instance {{host}} unmuted.', { host })
46 : this.i18n('Instance {{host}} unmuted by your instance.', { host })
54 addServersToBlock () {
55 this.batchDomainsModal.openModal()
58 onDomainsToBlock (domains: string[]) {
59 const operation = (domain: string) => this.mode === BlocklistComponentType.Account
60 ? this.blocklistService.blockServerByUser(domain)
61 : this.blocklistService.blockServerByInstance(domain)
63 domains.forEach(domain => {
64 operation(domain).subscribe(
66 this.notifier.success(
67 this.mode === BlocklistComponentType.Account
68 ? this.i18n('Instance {{domain}} muted.', { domain })
69 : this.i18n('Instance {{domain}} muted by your instance.', { domain })
78 protected loadData () {
79 const operation = this.mode === BlocklistComponentType.Account
80 ? this.blocklistService.getUserServerBlocklist({
81 pagination: this.pagination,
85 : this.blocklistService.getInstanceServerBlocklist({
86 pagination: this.pagination,
91 return operation.subscribe(
93 this.blockedServers = resultList.data
94 this.totalRecords = resultList.total
97 err => this.notifier.error(err.message)