]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { SortMeta } from 'primeng/api' |
583eb04b | 2 | import { OnInit, Directive } from '@angular/core' |
67ed6552 C |
3 | import { Notifier, RestPagination, RestTable } from '@app/core' |
4 | import { Actor } from '@app/shared/shared-main' | |
22839330 | 5 | import { I18n } from '@ngx-translate/i18n-polyfill' |
22839330 | 6 | import { AccountBlock } from './account-block.model' |
67ed6552 | 7 | import { BlocklistComponentType, BlocklistService } from './blocklist.service' |
22839330 | 8 | |
583eb04b | 9 | @Directive() |
22839330 RK |
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 | } |