1 import { SortMeta } from 'primeng/api'
2 import { Directive, OnInit } from '@angular/core'
3 import { Notifier, RestPagination, RestTable } from '@app/core'
4 import { Account } from '@app/shared/shared-main'
5 import { AccountBlock } from './account-block.model'
6 import { BlocklistComponentType, BlocklistService } from './blocklist.service'
9 // tslint:disable-next-line: directive-class-suffix
10 export class GenericAccountBlocklistComponent extends RestTable implements OnInit {
11 // @ts-ignore: "Abstract methods can only appear within an abstract class"
12 abstract mode: BlocklistComponentType
14 blockedAccounts: AccountBlock[] = []
16 sort: SortMeta = { field: 'createdAt', order: -1 }
17 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
20 private notifier: Notifier,
21 private blocklistService: BlocklistService
26 // @ts-ignore: "Abstract methods can only appear within an abstract class"
27 abstract getIdentifier (): string
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)
41 this.notifier.success(
42 this.mode === BlocklistComponentType.Account
43 ? $localize`Account ${blockedAccount.nameWithHost} unmuted.`
44 : $localize`Account ${blockedAccount.nameWithHost} unmuted by your instance.`
52 protected loadData () {
53 const operation = this.mode === BlocklistComponentType.Account
54 ? this.blocklistService.getUserAccountBlocklist({
55 pagination: this.pagination,
59 : this.blocklistService.getInstanceAccountBlocklist({
60 pagination: this.pagination,
65 return operation.subscribe(
67 this.blockedAccounts = resultList.data
68 this.totalRecords = resultList.total
71 err => this.notifier.error(err.message)