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
34 acceptFollower (follow: ActorFollow) {
35 follow.state = 'accepted'
37 this.followService.acceptFollower(follow)
40 const handle = follow.follower.name + '@' + follow.follower.host
41 this.notifier.success(this.i18n('{{handle}} accepted in instance followers', { handle }))
45 follow.state = 'pending'
46 this.notifier.error(err.message)
51 async rejectFollower (follow: ActorFollow) {
52 const message = this.i18n('Do you really want to reject this follower?')
53 const res = await this.confirmService.confirm(message, this.i18n('Reject'))
54 if (res === false) return
56 this.followService.rejectFollower(follow)
59 const handle = follow.follower.name + '@' + follow.follower.host
60 this.notifier.success(this.i18n('{{handle}} rejected from instance followers', { handle }))
66 follow.state = 'pending'
67 this.notifier.error(err.message)
72 async deleteFollower (follow: ActorFollow) {
73 const message = this.i18n('Do you really want to delete this follower?')
74 const res = await this.confirmService.confirm(message, this.i18n('Delete'))
75 if (res === false) return
77 this.followService.removeFollower(follow)
80 const handle = follow.follower.name + '@' + follow.follower.host
81 this.notifier.success(this.i18n('{{handle}} removed from instance followers', { handle }))
86 err => this.notifier.error(err.message)
90 protected loadData () {
91 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
94 this.followers = resultList.data
95 this.totalRecords = resultList.total
98 err => this.notifier.error(err.message)