1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit, ViewChild } from '@angular/core'
3 import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
4 import { InstanceFollowService } from '@app/shared/shared-instance'
5 import { BatchDomainsModalComponent } from '@app/shared/shared-moderation'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
7 import { ActorFollow } from '@shared/models'
10 selector: 'my-followers-list',
11 templateUrl: './following-list.component.html',
12 styleUrls: [ '../follows.component.scss', './following-list.component.scss' ]
14 export class FollowingListComponent extends RestTable implements OnInit {
15 @ViewChild('batchDomainsModal') batchDomainsModal: BatchDomainsModalComponent
17 following: ActorFollow[] = []
19 sort: SortMeta = { field: 'createdAt', order: -1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
23 private notifier: Notifier,
24 private confirmService: ConfirmService,
25 private followService: InstanceFollowService,
36 return 'FollowingListComponent'
39 addDomainsToFollow () {
40 this.batchDomainsModal.openModal()
44 return window.location.protocol === 'https:'
47 async addFollowing (hosts: string[]) {
48 this.followService.follow(hosts).subscribe(
50 this.notifier.success(this.i18n('Follow request(s) sent!'))
54 err => this.notifier.error(err.message)
58 async removeFollowing (follow: ActorFollow) {
59 const res = await this.confirmService.confirm(
60 this.i18n('Do you really want to unfollow {{host}}?', { host: follow.following.host }),
63 if (res === false) return
65 this.followService.unfollow(follow).subscribe(
67 this.notifier.success(this.i18n('You are not following {{host}} anymore.', { host: follow.following.host }))
71 err => this.notifier.error(err.message)
75 protected loadData () {
76 this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
79 this.following = resultList.data
80 this.totalRecords = resultList.total
83 err => this.notifier.error(err.message)