2019-07-25 10:44:21 +02:00
|
|
|
import { SortMeta } from 'primeng/api'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { Component, OnInit } from '@angular/core'
|
|
|
|
import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
|
2022-07-27 11:05:32 +02:00
|
|
|
import { AdvancedInputFilter } from '@app/shared/shared-forms'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { InstanceFollowService } from '@app/shared/shared-instance'
|
|
|
|
import { ActorFollow } from '@shared/models'
|
2017-11-15 10:10:41 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-followers-list',
|
|
|
|
templateUrl: './followers-list.component.html',
|
2021-10-29 11:33:28 +02:00
|
|
|
styleUrls: [ './followers-list.component.scss' ]
|
2017-11-15 10:10:41 +01:00
|
|
|
})
|
2018-02-23 14:36:16 +01:00
|
|
|
export class FollowersListComponent extends RestTable implements OnInit {
|
2018-09-11 16:27:07 +02:00
|
|
|
followers: ActorFollow[] = []
|
2017-11-15 10:10:41 +01:00
|
|
|
totalRecords = 0
|
2020-04-14 10:55:34 +02:00
|
|
|
sort: SortMeta = { field: 'createdAt', order: -1 }
|
2017-11-15 10:10:41 +01:00
|
|
|
pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
|
|
|
|
|
2022-07-27 11:05:32 +02:00
|
|
|
searchFilters: AdvancedInputFilter[]
|
|
|
|
|
2017-11-15 10:10:41 +01:00
|
|
|
constructor (
|
2019-04-08 15:47:44 +02:00
|
|
|
private confirmService: ConfirmService,
|
2018-12-19 16:04:34 +01:00
|
|
|
private notifier: Notifier,
|
2020-06-23 14:10:17 +02:00
|
|
|
private followService: InstanceFollowService
|
2017-11-15 10:10:41 +01:00
|
|
|
) {
|
|
|
|
super()
|
2022-07-27 11:05:32 +02:00
|
|
|
|
|
|
|
this.searchFilters = this.followService.buildFollowsListFilters()
|
2017-11-15 10:10:41 +01:00
|
|
|
}
|
|
|
|
|
2018-02-23 14:36:16 +01:00
|
|
|
ngOnInit () {
|
2018-10-08 15:51:38 +02:00
|
|
|
this.initialize()
|
2018-02-23 14:36:16 +01:00
|
|
|
}
|
|
|
|
|
2020-04-08 10:49:26 +02:00
|
|
|
getIdentifier () {
|
|
|
|
return 'FollowersListComponent'
|
|
|
|
}
|
|
|
|
|
2019-04-08 15:47:44 +02:00
|
|
|
acceptFollower (follow: ActorFollow) {
|
|
|
|
follow.state = 'accepted'
|
|
|
|
|
|
|
|
this.followService.acceptFollower(follow)
|
2021-08-17 11:27:47 +02:00
|
|
|
.subscribe({
|
|
|
|
next: () => {
|
2019-04-08 15:47:44 +02:00
|
|
|
const handle = follow.follower.name + '@' + follow.follower.host
|
2020-08-12 10:40:04 +02:00
|
|
|
this.notifier.success($localize`${handle} accepted in instance followers`)
|
2019-04-08 15:47:44 +02:00
|
|
|
},
|
|
|
|
|
2021-08-17 11:27:47 +02:00
|
|
|
error: err => {
|
2019-04-08 15:47:44 +02:00
|
|
|
follow.state = 'pending'
|
|
|
|
this.notifier.error(err.message)
|
|
|
|
}
|
2021-08-17 11:27:47 +02:00
|
|
|
})
|
2019-04-08 15:47:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async rejectFollower (follow: ActorFollow) {
|
2020-08-12 10:40:04 +02:00
|
|
|
const message = $localize`Do you really want to reject this follower?`
|
|
|
|
const res = await this.confirmService.confirm(message, $localize`Reject`)
|
2019-04-08 15:47:44 +02:00
|
|
|
if (res === false) return
|
|
|
|
|
|
|
|
this.followService.rejectFollower(follow)
|
2021-08-17 11:27:47 +02:00
|
|
|
.subscribe({
|
|
|
|
next: () => {
|
2019-04-08 15:47:44 +02:00
|
|
|
const handle = follow.follower.name + '@' + follow.follower.host
|
2020-08-12 10:40:04 +02:00
|
|
|
this.notifier.success($localize`${handle} rejected from instance followers`)
|
2019-04-08 15:47:44 +02:00
|
|
|
|
2021-05-03 14:33:34 +02:00
|
|
|
this.reloadData()
|
2019-04-08 15:47:44 +02:00
|
|
|
},
|
|
|
|
|
2021-08-17 11:27:47 +02:00
|
|
|
error: err => {
|
2019-04-08 15:47:44 +02:00
|
|
|
follow.state = 'pending'
|
|
|
|
this.notifier.error(err.message)
|
|
|
|
}
|
2021-08-17 11:27:47 +02:00
|
|
|
})
|
2019-04-08 15:47:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async deleteFollower (follow: ActorFollow) {
|
2022-07-27 11:05:32 +02:00
|
|
|
const message = $localize`Do you really want to delete this follower? It will be able to send again another follow request.`
|
2020-08-12 10:40:04 +02:00
|
|
|
const res = await this.confirmService.confirm(message, $localize`Delete`)
|
2019-04-08 15:47:44 +02:00
|
|
|
if (res === false) return
|
|
|
|
|
|
|
|
this.followService.removeFollower(follow)
|
2021-08-17 11:27:47 +02:00
|
|
|
.subscribe({
|
|
|
|
next: () => {
|
2019-04-08 15:47:44 +02:00
|
|
|
const handle = follow.follower.name + '@' + follow.follower.host
|
2020-08-12 10:40:04 +02:00
|
|
|
this.notifier.success($localize`${handle} removed from instance followers`)
|
2019-04-08 15:47:44 +02:00
|
|
|
|
2021-05-03 14:33:34 +02:00
|
|
|
this.reloadData()
|
2019-04-08 15:47:44 +02:00
|
|
|
},
|
|
|
|
|
2021-08-17 11:27:47 +02:00
|
|
|
error: err => this.notifier.error(err.message)
|
|
|
|
})
|
2019-04-08 15:47:44 +02:00
|
|
|
}
|
|
|
|
|
2021-05-03 14:33:34 +02:00
|
|
|
protected reloadData () {
|
2019-11-28 11:37:32 +01:00
|
|
|
this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
|
2021-08-17 11:27:47 +02:00
|
|
|
.subscribe({
|
|
|
|
next: resultList => {
|
2017-11-15 10:10:41 +01:00
|
|
|
this.followers = resultList.data
|
|
|
|
this.totalRecords = resultList.total
|
|
|
|
},
|
|
|
|
|
2021-08-17 11:27:47 +02:00
|
|
|
error: err => this.notifier.error(err.message)
|
|
|
|
})
|
2017-11-15 10:10:41 +01:00
|
|
|
}
|
|
|
|
}
|