]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-moderation/account-blocklist.component.ts
Fix lint
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / account-blocklist.component.ts
CommitLineData
67ed6552 1import { SortMeta } from 'primeng/api'
583eb04b 2import { OnInit, Directive } from '@angular/core'
67ed6552
C
3import { Notifier, RestPagination, RestTable } from '@app/core'
4import { Actor } from '@app/shared/shared-main'
22839330 5import { I18n } from '@ngx-translate/i18n-polyfill'
22839330 6import { AccountBlock } from './account-block.model'
67ed6552 7import { BlocklistComponentType, BlocklistService } from './blocklist.service'
22839330 8
583eb04b 9@Directive()
a02b93ce 10// tslint:disable-next-line: directive-class-suffix
22839330
RK
11export class GenericAccountBlocklistComponent extends RestTable implements OnInit {
12 // @ts-ignore: "Abstract methods can only appear within an abstract class"
13 abstract mode: BlocklistComponentType
14
15 blockedAccounts: AccountBlock[] = []
16 totalRecords = 0
17 sort: SortMeta = { field: 'createdAt', order: -1 }
18 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
19
20 constructor (
21 private notifier: Notifier,
22 private blocklistService: BlocklistService,
23 private i18n: I18n
24 ) {
25 super()
26 }
27
28 // @ts-ignore: "Abstract methods can only appear within an abstract class"
29 abstract getIdentifier (): string
30
31 ngOnInit () {
32 this.initialize()
33 }
34
35 switchToDefaultAvatar ($event: Event) {
36 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
37 }
38
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)
44
45 operation.subscribe(
46 () => {
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 })
51 )
52
53 this.loadData()
54 }
55 )
56 }
57
58 protected loadData () {
59 const operation = this.mode === BlocklistComponentType.Account
60 ? this.blocklistService.getUserAccountBlocklist({
61 pagination: this.pagination,
62 sort: this.sort,
63 search: this.search
64 })
65 : this.blocklistService.getInstanceAccountBlocklist({
66 pagination: this.pagination,
67 sort: this.sort,
68 search: this.search
69 })
70
71 return operation.subscribe(
72 resultList => {
73 this.blockedAccounts = resultList.data
74 this.totalRecords = resultList.total
75 },
76
77 err => this.notifier.error(err.message)
78 )
79 }
80}