]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/follows/followers-list/followers-list.component.ts
Handle rejected follows in client
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / followers-list / followers-list.component.ts
1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit } from '@angular/core'
3 import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
4 import { AdvancedInputFilter } from '@app/shared/shared-forms'
5 import { InstanceFollowService } from '@app/shared/shared-instance'
6 import { ActorFollow } from '@shared/models'
7
8 @Component({
9 selector: 'my-followers-list',
10 templateUrl: './followers-list.component.html',
11 styleUrls: [ './followers-list.component.scss' ]
12 })
13 export class FollowersListComponent extends RestTable implements OnInit {
14 followers: ActorFollow[] = []
15 totalRecords = 0
16 sort: SortMeta = { field: 'createdAt', order: -1 }
17 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
18
19 searchFilters: AdvancedInputFilter[]
20
21 constructor (
22 private confirmService: ConfirmService,
23 private notifier: Notifier,
24 private followService: InstanceFollowService
25 ) {
26 super()
27
28 this.searchFilters = this.followService.buildFollowsListFilters()
29 }
30
31 ngOnInit () {
32 this.initialize()
33 }
34
35 getIdentifier () {
36 return 'FollowersListComponent'
37 }
38
39 acceptFollower (follow: ActorFollow) {
40 follow.state = 'accepted'
41
42 this.followService.acceptFollower(follow)
43 .subscribe({
44 next: () => {
45 const handle = follow.follower.name + '@' + follow.follower.host
46 this.notifier.success($localize`${handle} accepted in instance followers`)
47 },
48
49 error: err => {
50 follow.state = 'pending'
51 this.notifier.error(err.message)
52 }
53 })
54 }
55
56 async rejectFollower (follow: ActorFollow) {
57 const message = $localize`Do you really want to reject this follower?`
58 const res = await this.confirmService.confirm(message, $localize`Reject`)
59 if (res === false) return
60
61 this.followService.rejectFollower(follow)
62 .subscribe({
63 next: () => {
64 const handle = follow.follower.name + '@' + follow.follower.host
65 this.notifier.success($localize`${handle} rejected from instance followers`)
66
67 this.reloadData()
68 },
69
70 error: err => {
71 follow.state = 'pending'
72 this.notifier.error(err.message)
73 }
74 })
75 }
76
77 async deleteFollower (follow: ActorFollow) {
78 const message = $localize`Do you really want to delete this follower? It will be able to send again another follow request.`
79 const res = await this.confirmService.confirm(message, $localize`Delete`)
80 if (res === false) return
81
82 this.followService.removeFollower(follow)
83 .subscribe({
84 next: () => {
85 const handle = follow.follower.name + '@' + follow.follower.host
86 this.notifier.success($localize`${handle} removed from instance followers`)
87
88 this.reloadData()
89 },
90
91 error: err => this.notifier.error(err.message)
92 })
93 }
94
95 protected reloadData () {
96 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
97 .subscribe({
98 next: resultList => {
99 this.followers = resultList.data
100 this.totalRecords = resultList.total
101 },
102
103 error: err => this.notifier.error(err.message)
104 })
105 }
106 }