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'
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
13 blockedAccounts: AccountBlock[] = []
15 sort: SortMeta = { field: 'createdAt', order: -1 }
16 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
19 private notifier: Notifier,
20 private blocklistService: BlocklistService
25 // @ts-expect-error: "Abstract methods can only appear within an abstract class"
26 abstract getIdentifier (): string
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)
40 this.notifier.success(
41 this.mode === BlocklistComponentType.Account
42 ? $localize`Account ${blockedAccount.nameWithHost} unmuted.`
43 : $localize`Account ${blockedAccount.nameWithHost} unmuted by your instance.`
51 protected reloadData () {
52 const operation = this.mode === BlocklistComponentType.Account
53 ? this.blocklistService.getUserAccountBlocklist({
54 pagination: this.pagination,
58 : this.blocklistService.getInstanceAccountBlocklist({
59 pagination: this.pagination,
64 return operation.subscribe({
66 this.blockedAccounts = resultList.data
67 this.totalRecords = resultList.total
70 error: err => this.notifier.error(err.message)