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: [ './followers-list.component.scss' ]
14 export class FollowersListComponent extends RestTable implements OnInit {
15 followers: ActorFollow[] = []
18 sort: SortMeta = { field: 'createdAt', order: 1 }
19 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
22 private confirmService: ConfirmService,
23 private notifier: Notifier,
25 private followService: FollowService
35 return 'FollowersListComponent'
38 acceptFollower (follow: ActorFollow) {
39 follow.state = 'accepted'
41 this.followService.acceptFollower(follow)
44 const handle = follow.follower.name + '@' + follow.follower.host
45 this.notifier.success(this.i18n('{{handle}} accepted in instance followers', { handle }))
49 follow.state = 'pending'
50 this.notifier.error(err.message)
55 async rejectFollower (follow: ActorFollow) {
56 const message = this.i18n('Do you really want to reject this follower?')
57 const res = await this.confirmService.confirm(message, this.i18n('Reject'))
58 if (res === false) return
60 this.followService.rejectFollower(follow)
63 const handle = follow.follower.name + '@' + follow.follower.host
64 this.notifier.success(this.i18n('{{handle}} rejected from instance followers', { handle }))
70 follow.state = 'pending'
71 this.notifier.error(err.message)
76 async deleteFollower (follow: ActorFollow) {
77 const message = this.i18n('Do you really want to delete this follower?')
78 const res = await this.confirmService.confirm(message, this.i18n('Delete'))
79 if (res === false) return
81 this.followService.removeFollower(follow)
84 const handle = follow.follower.name + '@' + follow.follower.host
85 this.notifier.success(this.i18n('{{handle}} removed from instance followers', { handle }))
90 err => this.notifier.error(err.message)
94 protected loadData () {
95 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
98 this.followers = resultList.data
99 this.totalRecords = resultList.total
102 err => this.notifier.error(err.message)