1 import { Subject } from 'rxjs'
2 import { Component, OnInit } from '@angular/core'
3 import { ActivatedRoute } from '@angular/router'
4 import { AuthService, ComponentPagination, Notifier } from '@app/core'
5 import { AdvancedInputFilter } from '@app/shared/shared-forms'
6 import { UserSubscriptionService } from '@app/shared/shared-user-subscription'
7 import { ActorFollow } from '@shared/models'
10 templateUrl: './my-followers.component.html',
11 styleUrls: [ './my-followers.component.scss' ]
13 export class MyFollowersComponent implements OnInit {
14 follows: ActorFollow[] = []
16 pagination: ComponentPagination = {
22 onDataSubject = new Subject<any[]>()
25 inputFilters: AdvancedInputFilter[]
28 private route: ActivatedRoute,
29 private auth: AuthService,
30 private userSubscriptionService: UserSubscriptionService,
31 private notifier: Notifier
35 if (this.route.snapshot.queryParams['search']) {
36 this.search = this.route.snapshot.queryParams['search']
39 this.auth.userInformationLoaded.subscribe(() => {
40 const channelFilters = this.auth.getUser().videoChannels.map(c => {
42 value: 'channel:' + c.name,
49 title: $localize`Channel filters`,
50 children: channelFilters
58 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
60 this.pagination.currentPage += 1
64 onSearch (search: string) {
66 this.loadFollowers(false)
69 isFollowingAccount (follow: ActorFollow) {
70 return follow.following.name === this.getUsername()
73 private loadFollowers (more = true) {
74 this.userSubscriptionService.listFollowers({
75 pagination: this.pagination,
76 nameWithHost: this.getUsername(),
81 ? this.follows.concat(res.data)
83 this.pagination.totalItems = res.total
85 this.onDataSubject.next(res.data)
88 error: err => this.notifier.error(err.message)
92 private getUsername () {
93 return this.auth.getUser().username