1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit } from '@angular/core'
3 import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
4 import { InstanceFollowService } from '@app/shared/shared-instance'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { ActorFollow } from '@shared/models'
9 selector: 'my-followers-list',
10 templateUrl: './followers-list.component.html',
11 styleUrls: [ '../follows.component.scss', './followers-list.component.scss' ]
13 export class FollowersListComponent extends RestTable implements OnInit {
14 followers: ActorFollow[] = []
16 sort: SortMeta = { field: 'createdAt', order: -1 }
17 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
20 private confirmService: ConfirmService,
21 private notifier: Notifier,
23 private followService: InstanceFollowService
33 return 'FollowersListComponent'
36 acceptFollower (follow: ActorFollow) {
37 follow.state = 'accepted'
39 this.followService.acceptFollower(follow)
42 const handle = follow.follower.name + '@' + follow.follower.host
43 this.notifier.success(this.i18n('{{handle}} accepted in instance followers', { handle }))
47 follow.state = 'pending'
48 this.notifier.error(err.message)
53 async rejectFollower (follow: ActorFollow) {
54 const message = this.i18n('Do you really want to reject this follower?')
55 const res = await this.confirmService.confirm(message, this.i18n('Reject'))
56 if (res === false) return
58 this.followService.rejectFollower(follow)
61 const handle = follow.follower.name + '@' + follow.follower.host
62 this.notifier.success(this.i18n('{{handle}} rejected from instance followers', { handle }))
68 follow.state = 'pending'
69 this.notifier.error(err.message)
74 async deleteFollower (follow: ActorFollow) {
75 const message = this.i18n('Do you really want to delete this follower?')
76 const res = await this.confirmService.confirm(message, this.i18n('Delete'))
77 if (res === false) return
79 this.followService.removeFollower(follow)
82 const handle = follow.follower.name + '@' + follow.follower.host
83 this.notifier.success(this.i18n('{{handle}} removed from instance followers', { handle }))
88 err => this.notifier.error(err.message)
92 protected loadData () {
93 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
96 this.followers = resultList.data
97 this.totalRecords = resultList.total
100 err => this.notifier.error(err.message)