]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+about/about-follows/about-follows.component.ts
Improve instance follow display
[github/Chocobozzz/PeerTube.git] / client / src / app / +about / about-follows / about-follows.component.ts
index a352726810eae74537f555c5fdd28a86dbd8cc48..35d8103888cb399fdc3d0fc02c32234b1f1bed88 100644 (file)
@@ -1,7 +1,8 @@
 import { SortMeta } from 'primeng/api'
 import { Component, OnInit } from '@angular/core'
-import { ComponentPagination, hasMoreItems, Notifier, RestService } from '@app/core'
+import { ComponentPagination, hasMoreItems, Notifier, RestService, ServerService } from '@app/core'
 import { InstanceFollowService } from '@app/shared/shared-instance'
+import { Actor } from '@shared/models/actors'
 
 @Component({
   selector: 'my-about-follows',
@@ -10,6 +11,8 @@ import { InstanceFollowService } from '@app/shared/shared-instance'
 })
 
 export class AboutFollowsComponent implements OnInit {
+  instanceName: string
+
   followers: string[] = []
   followings: string[] = []
 
@@ -34,6 +37,7 @@ export class AboutFollowsComponent implements OnInit {
   }
 
   constructor (
+    private server: ServerService,
     private restService: RestService,
     private notifier: Notifier,
     private followService: InstanceFollowService
@@ -43,6 +47,8 @@ export class AboutFollowsComponent implements OnInit {
     this.loadMoreFollowers()
 
     this.loadMoreFollowings()
+
+    this.instanceName = this.server.getHTMLConfig().instance.name
   }
 
   loadAllFollowings () {
@@ -88,14 +94,14 @@ export class AboutFollowsComponent implements OnInit {
   }
 
   private loadMoreFollowers (reset = false) {
-    const pagination = this.restService.componentPaginationToRestPagination(this.followersPagination)
+    const pagination = this.restService.componentToRestPagination(this.followersPagination)
 
     this.followService.getFollowers({ pagination, sort: this.sort, state: 'accepted' })
         .subscribe({
           next: resultList => {
             if (reset) this.followers = []
 
-            const newFollowers = resultList.data.map(r => r.follower.host)
+            const newFollowers = resultList.data.map(r => this.formatFollow(r.follower))
             this.followers = this.followers.concat(newFollowers)
 
             this.followersPagination.totalItems = resultList.total
@@ -106,14 +112,14 @@ export class AboutFollowsComponent implements OnInit {
   }
 
   private loadMoreFollowings (reset = false) {
-    const pagination = this.restService.componentPaginationToRestPagination(this.followingsPagination)
+    const pagination = this.restService.componentToRestPagination(this.followingsPagination)
 
     this.followService.getFollowing({ pagination, sort: this.sort, state: 'accepted' })
         .subscribe({
           next: resultList => {
             if (reset) this.followings = []
 
-            const newFollowings = resultList.data.map(r => r.following.host)
+            const newFollowings = resultList.data.map(r => this.formatFollow(r.following))
             this.followings = this.followings.concat(newFollowings)
 
             this.followingsPagination.totalItems = resultList.total
@@ -123,4 +129,11 @@ export class AboutFollowsComponent implements OnInit {
         })
   }
 
+  private formatFollow (actor: Actor) {
+    // Instance follow, only display host
+    if (actor.name === 'peertube') return actor.host
+
+    return actor.name + '@' + actor.host
+  }
+
 }