]>
Commit | Line | Data |
---|---|---|
65b21c96 | 1 | import { Component, OnInit } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier } from '@app/core' |
65b21c96 C |
3 | import { I18n } from '@ngx-translate/i18n-polyfill' |
4 | import { RestPagination, RestTable } from '@app/shared' | |
f77eb73b | 5 | import { SortMeta } from 'primeng/api' |
f8b2c1b4 | 6 | import { AccountBlock, BlocklistService } from '@app/shared/blocklist' |
d3840613 | 7 | import { Actor } from '@app/shared/actor/actor.model' |
65b21c96 C |
8 | |
9 | @Component({ | |
10 | selector: 'my-instance-account-blocklist', | |
e0a92917 | 11 | styleUrls: [ '../moderation.component.scss', './instance-account-blocklist.component.scss' ], |
65b21c96 C |
12 | templateUrl: './instance-account-blocklist.component.html' |
13 | }) | |
14 | export class InstanceAccountBlocklistComponent extends RestTable implements OnInit { | |
15 | blockedAccounts: AccountBlock[] = [] | |
16 | totalRecords = 0 | |
e0a92917 RK |
17 | rowsPerPageOptions = [ 20, 50, 100 ] |
18 | rowsPerPage = this.rowsPerPageOptions[0] | |
65b21c96 C |
19 | sort: SortMeta = { field: 'createdAt', order: -1 } |
20 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
21 | ||
22 | constructor ( | |
f8b2c1b4 | 23 | private notifier: Notifier, |
65b21c96 C |
24 | private blocklistService: BlocklistService, |
25 | private i18n: I18n | |
26 | ) { | |
27 | super() | |
28 | } | |
29 | ||
30 | ngOnInit () { | |
31 | this.initialize() | |
32 | } | |
33 | ||
8e11a1b3 C |
34 | getIdentifier () { |
35 | return 'InstanceAccountBlocklistComponent' | |
36 | } | |
37 | ||
d3840613 RK |
38 | switchToDefaultAvatar ($event: Event) { |
39 | ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL() | |
40 | } | |
41 | ||
65b21c96 C |
42 | unblockAccount (accountBlock: AccountBlock) { |
43 | const blockedAccount = accountBlock.blockedAccount | |
44 | ||
45 | this.blocklistService.unblockAccountByInstance(blockedAccount) | |
46 | .subscribe( | |
47 | () => { | |
f8b2c1b4 | 48 | this.notifier.success( |
65b21c96 C |
49 | this.i18n('Account {{nameWithHost}} unmuted by your instance.', { nameWithHost: blockedAccount.nameWithHost }) |
50 | ) | |
51 | ||
52 | this.loadData() | |
53 | } | |
54 | ) | |
55 | } | |
56 | ||
57 | protected loadData () { | |
e0a92917 RK |
58 | return this.blocklistService.getInstanceAccountBlocklist({ |
59 | pagination: this.pagination, | |
60 | sort: this.sort, | |
61 | search: this.search | |
62 | }) | |
65b21c96 C |
63 | .subscribe( |
64 | resultList => { | |
65 | this.blockedAccounts = resultList.data | |
66 | this.totalRecords = resultList.total | |
67 | }, | |
68 | ||
f8b2c1b4 | 69 | err => this.notifier.error(err.message) |
65b21c96 C |
70 | ) |
71 | } | |
72 | } |