1 import { SortMeta } from 'primeng/api'
2 import { OnInit } from '@angular/core'
3 import { Notifier, RestPagination, RestTable } from '@app/core'
4 import { Actor } from '@app/shared/shared-main'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { AccountBlock } from './account-block.model'
7 import { BlocklistComponentType, BlocklistService } from './blocklist.service'
9 export class GenericAccountBlocklistComponent extends RestTable implements OnInit {
10 // @ts-ignore: "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,
26 // @ts-ignore: "Abstract methods can only appear within an abstract class"
27 abstract getIdentifier (): string
33 switchToDefaultAvatar ($event: Event) {
34 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
37 unblockAccount (accountBlock: AccountBlock) {
38 const blockedAccount = accountBlock.blockedAccount
39 const operation = this.mode === BlocklistComponentType.Account
40 ? this.blocklistService.unblockAccountByUser(blockedAccount)
41 : this.blocklistService.unblockAccountByInstance(blockedAccount)
45 this.notifier.success(
46 this.mode === BlocklistComponentType.Account
47 ? this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: blockedAccount.nameWithHost })
48 : this.i18n('Account {{nameWithHost}} unmuted by your instance.', { nameWithHost: blockedAccount.nameWithHost })
56 protected loadData () {
57 const operation = this.mode === BlocklistComponentType.Account
58 ? this.blocklistService.getUserAccountBlocklist({
59 pagination: this.pagination,
63 : this.blocklistService.getInstanceAccountBlocklist({
64 pagination: this.pagination,
69 return operation.subscribe(
71 this.blockedAccounts = resultList.data
72 this.totalRecords = resultList.total
75 err => this.notifier.error(err.message)