]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-moderation/account-blocklist.component.ts
Add bulk action on following/followers
[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'
22839330 4import { AccountBlock } from './account-block.model'
67ed6552 5import { BlocklistComponentType, BlocklistService } from './blocklist.service'
22839330 6
583eb04b 7@Directive()
9df52d66 8// eslint-disable-next-line @angular-eslint/directive-class-suffix
22839330 9export class GenericAccountBlocklistComponent extends RestTable implements OnInit {
9df52d66 10 // @ts-expect-error: "Abstract methods can only appear within an abstract class"
22839330
RK
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,
66357162 20 private blocklistService: BlocklistService
22839330
RK
21 ) {
22 super()
23 }
24
9df52d66 25 // @ts-expect-error: "Abstract methods can only appear within an abstract class"
22839330
RK
26 abstract getIdentifier (): string
27
28 ngOnInit () {
29 this.initialize()
30 }
31
22839330
RK
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
66357162
C
42 ? $localize`Account ${blockedAccount.nameWithHost} unmuted.`
43 : $localize`Account ${blockedAccount.nameWithHost} unmuted by your instance.`
22839330
RK
44 )
45
2e46eb97 46 this.reloadData()
22839330
RK
47 }
48 )
49 }
50
2e46eb97 51 protected reloadData () {
22839330
RK
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
1378c0d3
C
64 return operation.subscribe({
65 next: resultList => {
22839330
RK
66 this.blockedAccounts = resultList.data
67 this.totalRecords = resultList.total
68 },
69
1378c0d3
C
70 error: err => this.notifier.error(err.message)
71 })
22839330
RK
72 }
73}