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