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