03e3379e6d54873e7f89fa8ec5f04ae7c8349edb
[oweals/peertube.git] / client / src / app / +admin / moderation / instance-blocklist / instance-account-blocklist.component.ts
1 import { Component, OnInit } 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 { AccountBlock, BlocklistService } from '@app/shared/blocklist'
7
8 @Component({
9   selector: 'my-instance-account-blocklist',
10   styleUrls: [ './instance-account-blocklist.component.scss' ],
11   templateUrl: './instance-account-blocklist.component.html'
12 })
13 export class InstanceAccountBlocklistComponent extends RestTable implements OnInit {
14   blockedAccounts: AccountBlock[] = []
15   totalRecords = 0
16   rowsPerPage = 10
17   sort: SortMeta = { field: 'createdAt', order: -1 }
18   pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
19
20   constructor (
21     private notifier: Notifier,
22     private blocklistService: BlocklistService,
23     private i18n: I18n
24   ) {
25     super()
26   }
27
28   ngOnInit () {
29     this.initialize()
30   }
31
32   unblockAccount (accountBlock: AccountBlock) {
33     const blockedAccount = accountBlock.blockedAccount
34
35     this.blocklistService.unblockAccountByInstance(blockedAccount)
36         .subscribe(
37           () => {
38             this.notifier.success(
39               this.i18n('Account {{nameWithHost}} unmuted by your instance.', { nameWithHost: blockedAccount.nameWithHost })
40             )
41
42             this.loadData()
43           }
44         )
45   }
46
47   protected loadData () {
48     return this.blocklistService.getInstanceAccountBlocklist(this.pagination, this.sort)
49       .subscribe(
50         resultList => {
51           this.blockedAccounts = resultList.data
52           this.totalRecords = resultList.total
53         },
54
55         err => this.notifier.error(err.message)
56       )
57   }
58 }