2021-10-19 09:44:43 +02:00
|
|
|
import { Subject } from 'rxjs'
|
|
|
|
import { Component, OnInit } from '@angular/core'
|
|
|
|
import { ActivatedRoute } from '@angular/router'
|
|
|
|
import { AuthService, ComponentPagination, Notifier } from '@app/core'
|
2021-10-19 15:22:15 +02:00
|
|
|
import { AdvancedInputFilter } from '@app/shared/shared-forms'
|
2021-10-19 09:44:43 +02:00
|
|
|
import { UserSubscriptionService } from '@app/shared/shared-user-subscription'
|
2023-07-31 14:34:36 +02:00
|
|
|
import { ActorFollow } from '@peertube/peertube-models'
|
2021-10-19 09:44:43 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: './my-followers.component.html',
|
|
|
|
styleUrls: [ './my-followers.component.scss' ]
|
|
|
|
})
|
|
|
|
export class MyFollowersComponent implements OnInit {
|
|
|
|
follows: ActorFollow[] = []
|
|
|
|
|
|
|
|
pagination: ComponentPagination = {
|
|
|
|
currentPage: 1,
|
|
|
|
itemsPerPage: 10,
|
|
|
|
totalItems: null
|
|
|
|
}
|
|
|
|
|
|
|
|
onDataSubject = new Subject<any[]>()
|
|
|
|
search: string
|
|
|
|
|
2021-10-19 15:22:15 +02:00
|
|
|
inputFilters: AdvancedInputFilter[]
|
|
|
|
|
2021-10-19 09:44:43 +02:00
|
|
|
constructor (
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private auth: AuthService,
|
|
|
|
private userSubscriptionService: UserSubscriptionService,
|
|
|
|
private notifier: Notifier
|
|
|
|
) {}
|
|
|
|
|
|
|
|
ngOnInit () {
|
|
|
|
if (this.route.snapshot.queryParams['search']) {
|
|
|
|
this.search = this.route.snapshot.queryParams['search']
|
|
|
|
}
|
2021-10-19 15:22:15 +02:00
|
|
|
|
|
|
|
this.auth.userInformationLoaded.subscribe(() => {
|
2021-10-20 09:05:43 +02:00
|
|
|
const channelFilters = this.auth.getUser().videoChannels.map(c => {
|
2021-10-19 15:22:15 +02:00
|
|
|
return {
|
2021-11-03 14:23:55 +01:00
|
|
|
value: 'channel:' + c.name,
|
2021-10-20 09:05:43 +02:00
|
|
|
label: c.name
|
2021-10-19 15:22:15 +02:00
|
|
|
}
|
|
|
|
})
|
2021-10-20 09:05:43 +02:00
|
|
|
|
|
|
|
this.inputFilters = [
|
|
|
|
{
|
|
|
|
title: $localize`Channel filters`,
|
|
|
|
children: channelFilters
|
|
|
|
}
|
|
|
|
]
|
2021-10-19 15:22:15 +02:00
|
|
|
})
|
2021-10-19 09:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onNearOfBottom () {
|
|
|
|
// Last page
|
|
|
|
if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
|
|
|
|
|
|
|
|
this.pagination.currentPage += 1
|
|
|
|
this.loadFollowers()
|
|
|
|
}
|
|
|
|
|
|
|
|
onSearch (search: string) {
|
|
|
|
this.search = search
|
|
|
|
this.loadFollowers(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
isFollowingAccount (follow: ActorFollow) {
|
|
|
|
return follow.following.name === this.getUsername()
|
|
|
|
}
|
|
|
|
|
|
|
|
private loadFollowers (more = true) {
|
|
|
|
this.userSubscriptionService.listFollowers({
|
|
|
|
pagination: this.pagination,
|
|
|
|
nameWithHost: this.getUsername(),
|
|
|
|
search: this.search
|
|
|
|
}).subscribe({
|
|
|
|
next: res => {
|
|
|
|
this.follows = more
|
|
|
|
? this.follows.concat(res.data)
|
|
|
|
: res.data
|
|
|
|
this.pagination.totalItems = res.total
|
|
|
|
|
|
|
|
this.onDataSubject.next(res.data)
|
|
|
|
},
|
|
|
|
|
|
|
|
error: err => this.notifier.error(err.message)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
private getUsername () {
|
|
|
|
return this.auth.getUser().username
|
|
|
|
}
|
|
|
|
}
|