1 import { SortMeta } from 'primeng/api'
2 import { OnInit, Directive } 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'
10 // tslint:disable-next-line: directive-class-suffix
11 export class GenericAccountBlocklistComponent extends RestTable implements OnInit {
12 // @ts-ignore: "Abstract methods can only appear within an abstract class"
13 abstract mode: BlocklistComponentType
15 blockedAccounts: AccountBlock[] = []
17 sort: SortMeta = { field: 'createdAt', order: -1 }
18 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
21 private notifier: Notifier,
22 private blocklistService: BlocklistService,
28 // @ts-ignore: "Abstract methods can only appear within an abstract class"
29 abstract getIdentifier (): string
35 switchToDefaultAvatar ($event: Event) {
36 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
39 unblockAccount (accountBlock: AccountBlock) {
40 const blockedAccount = accountBlock.blockedAccount
41 const operation = this.mode === BlocklistComponentType.Account
42 ? this.blocklistService.unblockAccountByUser(blockedAccount)
43 : this.blocklistService.unblockAccountByInstance(blockedAccount)
47 this.notifier.success(
48 this.mode === BlocklistComponentType.Account
49 ? this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: blockedAccount.nameWithHost })
50 : this.i18n('Account {{nameWithHost}} unmuted by your instance.', { nameWithHost: blockedAccount.nameWithHost })
58 protected loadData () {
59 const operation = this.mode === BlocklistComponentType.Account
60 ? this.blocklistService.getUserAccountBlocklist({
61 pagination: this.pagination,
65 : this.blocklistService.getInstanceAccountBlocklist({
66 pagination: this.pagination,
71 return operation.subscribe(
73 this.blockedAccounts = resultList.data
74 this.totalRecords = resultList.total
77 err => this.notifier.error(err.message)