]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-moderation/account-blocklist.component.ts
Fix client lint
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / account-blocklist.component.ts
CommitLineData
67ed6552 1import { SortMeta } from 'primeng/api'
66357162 2import { Directive, OnInit } from '@angular/core'
67ed6552 3import { Notifier, RestPagination, RestTable } from '@app/core'
c418d483 4import { Account } from '@app/shared/shared-main'
22839330 5import { AccountBlock } from './account-block.model'
67ed6552 6import { BlocklistComponentType, BlocklistService } from './blocklist.service'
22839330 7
583eb04b 8@Directive()
a02b93ce 9// tslint:disable-next-line: directive-class-suffix
22839330
RK
10export class GenericAccountBlocklistComponent extends RestTable implements OnInit {
11 // @ts-ignore: "Abstract methods can only appear within an abstract class"
12 abstract mode: BlocklistComponentType
13
14 blockedAccounts: AccountBlock[] = []
15 totalRecords = 0
16 sort: SortMeta = { field: 'createdAt', order: -1 }
17 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
18
19 constructor (
20 private notifier: Notifier,
66357162 21 private blocklistService: BlocklistService
22839330
RK
22 ) {
23 super()
24 }
25
26 // @ts-ignore: "Abstract methods can only appear within an abstract class"
27 abstract getIdentifier (): string
28
29 ngOnInit () {
30 this.initialize()
31 }
32
22839330
RK
33 unblockAccount (accountBlock: AccountBlock) {
34 const blockedAccount = accountBlock.blockedAccount
35 const operation = this.mode === BlocklistComponentType.Account
36 ? this.blocklistService.unblockAccountByUser(blockedAccount)
37 : this.blocklistService.unblockAccountByInstance(blockedAccount)
38
39 operation.subscribe(
40 () => {
41 this.notifier.success(
42 this.mode === BlocklistComponentType.Account
66357162
C
43 ? $localize`Account ${blockedAccount.nameWithHost} unmuted.`
44 : $localize`Account ${blockedAccount.nameWithHost} unmuted by your instance.`
22839330
RK
45 )
46
2e46eb97 47 this.reloadData()
22839330
RK
48 }
49 )
50 }
51
2e46eb97 52 protected reloadData () {
22839330
RK
53 const operation = this.mode === BlocklistComponentType.Account
54 ? this.blocklistService.getUserAccountBlocklist({
55 pagination: this.pagination,
56 sort: this.sort,
57 search: this.search
58 })
59 : this.blocklistService.getInstanceAccountBlocklist({
60 pagination: this.pagination,
61 sort: this.sort,
62 search: this.search
63 })
64
1378c0d3
C
65 return operation.subscribe({
66 next: resultList => {
22839330
RK
67 this.blockedAccounts = resultList.data
68 this.totalRecords = resultList.total
69 },
70
1378c0d3
C
71 error: err => this.notifier.error(err.message)
72 })
22839330
RK
73 }
74}