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 this.inputFilters = this.auth.getUser().videoChannels.map(c => {
42 queryParams: { search: 'channel:' + c.name },
43 label: $localize`Followers of ${c.name}`
51 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
53 this.pagination.currentPage += 1
57 onSearch (search: string) {
59 this.loadFollowers(false)
62 isFollowingAccount (follow: ActorFollow) {
63 return follow.following.name === this.getUsername()
66 private loadFollowers (more = true) {
67 this.userSubscriptionService.listFollowers({
68 pagination: this.pagination,
69 nameWithHost: this.getUsername(),
74 ? this.follows.concat(res.data)
76 this.pagination.totalItems = res.total
78 this.onDataSubject.next(res.data)
81 error: err => this.notifier.error(err.message)
85 private getUsername () {
86 return this.auth.getUser().username