1 import { Component, OnInit } from '@angular/core'
2 import { ConfirmService, Notifier } from '@app/core'
3 import { SortMeta } from 'primeng/api'
4 import { ActorFollow } from '../../../../../../shared/models/actors/follow.model'
5 import { RestPagination, RestTable } from '../../../shared'
6 import { FollowService } from '@app/shared/instance/follow.service'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
10 selector: 'my-followers-list',
11 templateUrl: './followers-list.component.html',
12 styleUrls: [ '../follows.component.scss', './followers-list.component.scss' ]
14 export class FollowersListComponent extends RestTable implements OnInit {
15 followers: ActorFollow[] = []
17 sort: SortMeta = { field: 'createdAt', order: -1 }
18 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
21 private confirmService: ConfirmService,
22 private notifier: Notifier,
24 private followService: FollowService
34 return 'FollowersListComponent'
37 acceptFollower (follow: ActorFollow) {
38 follow.state = 'accepted'
40 this.followService.acceptFollower(follow)
43 const handle = follow.follower.name + '@' + follow.follower.host
44 this.notifier.success(this.i18n('{{handle}} accepted in instance followers', { handle }))
48 follow.state = 'pending'
49 this.notifier.error(err.message)
54 async rejectFollower (follow: ActorFollow) {
55 const message = this.i18n('Do you really want to reject this follower?')
56 const res = await this.confirmService.confirm(message, this.i18n('Reject'))
57 if (res === false) return
59 this.followService.rejectFollower(follow)
62 const handle = follow.follower.name + '@' + follow.follower.host
63 this.notifier.success(this.i18n('{{handle}} rejected from instance followers', { handle }))
69 follow.state = 'pending'
70 this.notifier.error(err.message)
75 async deleteFollower (follow: ActorFollow) {
76 const message = this.i18n('Do you really want to delete this follower?')
77 const res = await this.confirmService.confirm(message, this.i18n('Delete'))
78 if (res === false) return
80 this.followService.removeFollower(follow)
83 const handle = follow.follower.name + '@' + follow.follower.host
84 this.notifier.success(this.i18n('{{handle}} removed from instance followers', { handle }))
89 err => this.notifier.error(err.message)
93 protected loadData () {
94 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
97 this.followers = resultList.data
98 this.totalRecords = resultList.total
101 err => this.notifier.error(err.message)