]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/blocklist/account-blocklist.component.ts
provide specific engine boundaries for nodejs and yarn
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / blocklist / account-blocklist.component.ts
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'
9
10 export class GenericAccountBlocklistComponent extends RestTable implements OnInit {
11 // @ts-ignore: "Abstract methods can only appear within an abstract class"
12 abstract mode: BlocklistComponentType
13
14 blockedAccounts: AccountBlock[] = []
15 totalRecords = 0
16 sort: SortMeta = { field: 'createdAt', order: -1 }
17 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
18
19 constructor (
20 private notifier: Notifier,
21 private blocklistService: BlocklistService,
22 private i18n: I18n
23 ) {
24 super()
25 }
26
27 // @ts-ignore: "Abstract methods can only appear within an abstract class"
28 abstract getIdentifier (): string
29
30 ngOnInit () {
31 this.initialize()
32 }
33
34 switchToDefaultAvatar ($event: Event) {
35 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
36 }
37
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)
43
44 operation.subscribe(
45 () => {
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 })
50 )
51
52 this.loadData()
53 }
54 )
55 }
56
57 protected loadData () {
58 const operation = this.mode === BlocklistComponentType.Account
59 ? this.blocklistService.getUserAccountBlocklist({
60 pagination: this.pagination,
61 sort: this.sort,
62 search: this.search
63 })
64 : this.blocklistService.getInstanceAccountBlocklist({
65 pagination: this.pagination,
66 sort: this.sort,
67 search: this.search
68 })
69
70 return operation.subscribe(
71 resultList => {
72 this.blockedAccounts = resultList.data
73 this.totalRecords = resultList.total
74 },
75
76 err => this.notifier.error(err.message)
77 )
78 }
79 }