]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-moderation/account-blocklist.component.ts
Update build steps for localization
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / account-blocklist.component.ts
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'
8
9 @Directive()
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
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 }