]>
Commit | Line | Data |
---|---|---|
41b15c89 | 1 | import { SortMeta } from 'primeng/api' |
67ed6552 C |
2 | import { Component, OnInit, ViewChild } from '@angular/core' |
3 | import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core' | |
4 | import { InstanceFollowService } from '@app/shared/shared-instance' | |
5 | import { BatchDomainsModalComponent } from '@app/shared/shared-moderation' | |
67ed6552 | 6 | import { ActorFollow } from '@shared/models' |
4d029ef8 | 7 | import { FollowModalComponent } from './follow-modal.component' |
51548b31 C |
8 | |
9 | @Component({ | |
c48e82b5 | 10 | templateUrl: './following-list.component.html', |
d3840613 | 11 | styleUrls: [ '../follows.component.scss', './following-list.component.scss' ] |
51548b31 | 12 | }) |
ab998f7b | 13 | export class FollowingListComponent extends RestTable implements OnInit { |
4d029ef8 | 14 | @ViewChild('followModal') followModal: FollowModalComponent |
bb152476 | 15 | |
c48e82b5 | 16 | following: ActorFollow[] = [] |
51548b31 | 17 | totalRecords = 0 |
bb152476 | 18 | sort: SortMeta = { field: 'createdAt', order: -1 } |
51548b31 C |
19 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
20 | ||
21 | constructor ( | |
f8b2c1b4 | 22 | private notifier: Notifier, |
7e9334c3 | 23 | private confirmService: ConfirmService, |
66357162 C |
24 | private followService: InstanceFollowService |
25 | ) { | |
51548b31 C |
26 | super() |
27 | } | |
28 | ||
ab998f7b | 29 | ngOnInit () { |
24b9417c | 30 | this.initialize() |
ab998f7b C |
31 | } |
32 | ||
8e11a1b3 C |
33 | getIdentifier () { |
34 | return 'FollowingListComponent' | |
35 | } | |
36 | ||
4d029ef8 C |
37 | openFollowModal () { |
38 | this.followModal.openModal() | |
bb152476 RK |
39 | } |
40 | ||
4d029ef8 C |
41 | isInstanceFollowing (follow: ActorFollow) { |
42 | return follow.following.name === 'peertube' | |
bb152476 RK |
43 | } |
44 | ||
c48e82b5 | 45 | async removeFollowing (follow: ActorFollow) { |
b1d40cff | 46 | const res = await this.confirmService.confirm( |
66357162 C |
47 | $localize`Do you really want to unfollow ${follow.following.host}?`, |
48 | $localize`Unfollow` | |
b1d40cff | 49 | ) |
1f30a185 | 50 | if (res === false) return |
7e9334c3 | 51 | |
1f30a185 C |
52 | this.followService.unfollow(follow).subscribe( |
53 | () => { | |
66357162 | 54 | this.notifier.success($localize`You are not following ${follow.following.host} anymore.`) |
2e46eb97 | 55 | this.reloadData() |
1f30a185 | 56 | }, |
7e9334c3 | 57 | |
f8b2c1b4 | 58 | err => this.notifier.error(err.message) |
7e9334c3 C |
59 | ) |
60 | } | |
61 | ||
2e46eb97 | 62 | protected reloadData () { |
b8f4167f | 63 | this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search }) |
51548b31 C |
64 | .subscribe( |
65 | resultList => { | |
66 | this.following = resultList.data | |
67 | this.totalRecords = resultList.total | |
68 | }, | |
69 | ||
f8b2c1b4 | 70 | err => this.notifier.error(err.message) |
51548b31 C |
71 | ) |
72 | } | |
73 | } |