]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add follow tabs
authorChocobozzz <florian.bigard@gmail.com>
Wed, 15 Nov 2017 09:10:41 +0000 (10:10 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 27 Nov 2017 18:40:51 +0000 (19:40 +0100)
Following
Follow
Followers

44 files changed:
client/src/app/+admin/admin-routing.module.ts
client/src/app/+admin/admin.module.ts
client/src/app/+admin/follows/followers-list/followers-list.component.html [new file with mode: 0644]
client/src/app/+admin/follows/followers-list/followers-list.component.scss [moved from client/src/app/+admin/friends/friend-list/friend-list.component.scss with 100% similarity]
client/src/app/+admin/follows/followers-list/followers-list.component.ts [new file with mode: 0644]
client/src/app/+admin/follows/followers-list/index.ts [new file with mode: 0644]
client/src/app/+admin/follows/following-add/following-add.component.html [moved from client/src/app/+admin/friends/friend-add/friend-add.component.html with 82% similarity]
client/src/app/+admin/follows/following-add/following-add.component.scss [moved from client/src/app/+admin/friends/friend-add/friend-add.component.scss with 100% similarity]
client/src/app/+admin/follows/following-add/following-add.component.ts [moved from client/src/app/+admin/friends/friend-add/friend-add.component.ts with 84% similarity]
client/src/app/+admin/follows/following-add/index.ts [new file with mode: 0644]
client/src/app/+admin/follows/following-list/following-list.component.html [new file with mode: 0644]
client/src/app/+admin/follows/following-list/following-list.component.ts [new file with mode: 0644]
client/src/app/+admin/follows/following-list/index.ts [new file with mode: 0644]
client/src/app/+admin/follows/follows.component.html [new file with mode: 0644]
client/src/app/+admin/follows/follows.component.scss [new file with mode: 0644]
client/src/app/+admin/follows/follows.component.ts [new file with mode: 0644]
client/src/app/+admin/follows/follows.routes.ts [new file with mode: 0644]
client/src/app/+admin/follows/index.ts [new file with mode: 0644]
client/src/app/+admin/follows/shared/follow.service.ts [moved from client/src/app/+admin/friends/shared/friend.service.ts with 60% similarity]
client/src/app/+admin/follows/shared/index.ts [new file with mode: 0644]
client/src/app/+admin/friends/friend-add/index.ts [deleted file]
client/src/app/+admin/friends/friend-list/friend-list.component.html [deleted file]
client/src/app/+admin/friends/friend-list/friend-list.component.ts [deleted file]
client/src/app/+admin/friends/friend-list/index.ts [deleted file]
client/src/app/+admin/friends/friends.component.ts [deleted file]
client/src/app/+admin/friends/friends.routes.ts [deleted file]
client/src/app/+admin/friends/index.ts [deleted file]
client/src/app/+admin/friends/shared/index.ts [deleted file]
client/src/app/core/menu/menu-admin.component.html
client/src/app/core/menu/menu-admin.component.ts
client/src/app/core/menu/menu.component.ts
scripts/update-host.ts
server/controllers/activitypub/client.ts
server/controllers/activitypub/index.ts
server/controllers/api/application/follows.ts [moved from server/controllers/api/pods.ts with 68% similarity]
server/controllers/api/application/index.ts [new file with mode: 0644]
server/controllers/api/index.ts
server/controllers/webfinger.ts
server/lib/activitypub/send-request.ts
server/models/account/account-follow-interface.ts
server/models/account/account-follow.ts
server/models/account/account-interface.ts
server/models/account/account.ts
shared/models/users/user-right.enum.ts

index 88f44a81184d8e941234acf0aa82b7c557aa7916..cd8b9bdef9a084690cf066b78559f765756ebf3e 100644 (file)
@@ -4,7 +4,7 @@ import { RouterModule, Routes } from '@angular/router'
 import { MetaGuard } from '@ngx-meta/core'
 
 import { AdminComponent } from './admin.component'
-import { FriendsRoutes } from './friends'
+import { FollowsRoutes } from './follows'
 import { UsersRoutes } from './users'
 import { VideoAbusesRoutes } from './video-abuses'
 import { VideoBlacklistRoutes } from './video-blacklist'
@@ -21,7 +21,7 @@ const adminRoutes: Routes = [
         redirectTo: 'users',
         pathMatch: 'full'
       },
-      ...FriendsRoutes,
+      ...FollowsRoutes,
       ...UsersRoutes,
       ...VideoAbusesRoutes,
       ...VideoBlacklistRoutes
index 32f6c42a6f61df1f98b5a7ccac1bf0728e6ca2bc..3c6b7a79384335aeafbd479f79e1975167ed1cb8 100644 (file)
@@ -1,25 +1,28 @@
 import { NgModule } from '@angular/core'
-
-import { AdminComponent } from './admin.component'
+import { TabsModule } from 'ngx-bootstrap/tabs'
+import { SharedModule } from '../shared'
 import { AdminRoutingModule } from './admin-routing.module'
-import { FriendsComponent, FriendAddComponent, FriendListComponent, FriendService } from './friends'
-import { UsersComponent, UserAddComponent, UserUpdateComponent, UserListComponent, UserService } from './users'
-import { VideoAbusesComponent, VideoAbuseListComponent } from './video-abuses'
+import { AdminComponent } from './admin.component'
+import { FollowersListComponent, FollowingAddComponent, FollowsComponent, FollowService } from './follows'
+import { FollowingListComponent } from './follows/following-list/following-list.component'
+import { UserAddComponent, UserListComponent, UsersComponent, UserService, UserUpdateComponent } from './users'
+import { VideoAbuseListComponent, VideoAbusesComponent } from './video-abuses'
 import { VideoBlacklistComponent, VideoBlacklistListComponent } from './video-blacklist'
-import { SharedModule } from '../shared'
 
 @NgModule({
   imports: [
     AdminRoutingModule,
+    TabsModule.forRoot(),
     SharedModule
   ],
 
   declarations: [
     AdminComponent,
 
-    FriendsComponent,
-    FriendAddComponent,
-    FriendListComponent,
+    FollowsComponent,
+    FollowingAddComponent,
+    FollowersListComponent,
+    FollowingListComponent,
 
     UsersComponent,
     UserAddComponent,
@@ -38,7 +41,7 @@ import { SharedModule } from '../shared'
   ],
 
   providers: [
-    FriendService,
+    FollowService,
     UserService
   ]
 })
diff --git a/client/src/app/+admin/follows/followers-list/followers-list.component.html b/client/src/app/+admin/follows/followers-list/followers-list.component.html
new file mode 100644 (file)
index 0000000..24d75d2
--- /dev/null
@@ -0,0 +1,16 @@
+<div class="row">
+  <div class="content-padding">
+    <h3>Followers list</h3>
+
+    <p-dataTable
+        [value]="followers" [lazy]="true" [paginator]="true" [totalRecords]="totalRecords" [rows]="rowsPerPage"
+        sortField="createdAt" (onLazyLoad)="loadLazy($event)"
+    >
+      <p-column field="id" header="ID"></p-column>
+      <p-column field="host" header="Host"></p-column>
+      <p-column field="email" header="Email"></p-column>
+      <p-column field="score" header="Score"></p-column>
+      <p-column field="createdAt" header="Created date" [sortable]="true"></p-column>
+    </p-dataTable>
+  </div>
+</div>
diff --git a/client/src/app/+admin/follows/followers-list/followers-list.component.ts b/client/src/app/+admin/follows/followers-list/followers-list.component.ts
new file mode 100644 (file)
index 0000000..208a0c6
--- /dev/null
@@ -0,0 +1,41 @@
+import { Component, OnInit } from '@angular/core'
+
+import { NotificationsService } from 'angular2-notifications'
+import { SortMeta } from 'primeng/primeng'
+
+import { ConfirmService } from '../../../core'
+import { RestTable, RestPagination } from '../../../shared'
+import { Pod } from '../../../../../../shared'
+import { FollowService } from '../shared'
+
+@Component({
+  selector: 'my-followers-list',
+  templateUrl: './followers-list.component.html',
+  styleUrls: [ './followers-list.component.scss' ]
+})
+export class FollowersListComponent extends RestTable {
+  followers: Pod[] = []
+  totalRecords = 0
+  rowsPerPage = 10
+  sort: SortMeta = { field: 'createdAt', order: 1 }
+  pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
+
+  constructor (
+    private notificationsService: NotificationsService,
+    private followService: FollowService
+  ) {
+    super()
+  }
+
+  protected loadData () {
+    this.followService.getFollowers(this.pagination, this.sort)
+                      .subscribe(
+                        resultList => {
+                          this.followers = resultList.data
+                          this.totalRecords = resultList.total
+                        },
+
+                        err => this.notificationsService.error('Error', err.message)
+                      )
+  }
+}
diff --git a/client/src/app/+admin/follows/followers-list/index.ts b/client/src/app/+admin/follows/followers-list/index.ts
new file mode 100644 (file)
index 0000000..15390cf
--- /dev/null
@@ -0,0 +1 @@
+export * from './followers-list.component'
similarity index 82%
rename from client/src/app/+admin/friends/friend-add/friend-add.component.html
rename to client/src/app/+admin/follows/following-add/following-add.component.html
index 81d8291cdadb7124d1f3fcbeb50164b3697543e2..111f6a8dee62b590c5d94ca3c8ec6fbc7ba6b8b1 100644 (file)
@@ -1,11 +1,11 @@
 <div class="row">
   <div class="content-padding">
 
-    <h3>Make friends</h3>
+    <h3>Add following</h3>
 
     <div *ngIf="error" class="alert alert-danger">{{ error }}</div>
 
-    <form (ngSubmit)="makeFriends()" [formGroup]="form">
+    <form (ngSubmit)="addFollowing()" [formGroup]="form">
       <div class="form-group"  *ngFor="let host of hosts; let id = index; trackBy:customTrackBy">
         <label [for]="'host-' + id">Host (so without "http://")</label>
 
       </div>
 
       <div *ngIf="canMakeFriends() === false"  class="alert alert-warning">
-        It seems that you are not on a HTTPS pod. Your webserver need to have TLS activated in order to make friends.
+        It seems that you are not on a HTTPS pod. Your webserver need to have TLS activated in order to follow servers.
       </div>
 
-      <input type="submit" value="Make friends" class="btn btn-default" [disabled]="!isFormValid()">
+      <input type="submit" value="Add following" class="btn btn-default" [disabled]="!isFormValid()">
     </form>
   </div>
 </div>
similarity index 84%
rename from client/src/app/+admin/friends/friend-add/friend-add.component.ts
rename to client/src/app/+admin/follows/following-add/following-add.component.ts
index 29ed23e0c41a3011d235d94d82ab868abf15b356..d95d6afa9b8c28ccc5304d92c127e39181bf6825 100644 (file)
@@ -6,14 +6,14 @@ import { NotificationsService } from 'angular2-notifications'
 
 import { ConfirmService } from '../../../core'
 import { validateHost } from '../../../shared'
-import { FriendService } from '../shared'
+import { FollowService } from '../shared'
 
 @Component({
-  selector: 'my-friend-add',
-  templateUrl: './friend-add.component.html',
-  styleUrls: [ './friend-add.component.scss' ]
+  selector: 'my-following-add',
+  templateUrl: './following-add.component.html',
+  styleUrls: [ './following-add.component.scss' ]
 })
-export class FriendAddComponent implements OnInit {
+export class FollowingAddComponent implements OnInit {
   form: FormGroup
   hosts: string[] = [ ]
   error: string = null
@@ -22,7 +22,7 @@ export class FriendAddComponent implements OnInit {
     private router: Router,
     private notificationsService: NotificationsService,
     private confirmService: ConfirmService,
-    private friendService: FriendService
+    private followService: FollowService
   ) {}
 
   ngOnInit () {
@@ -72,7 +72,7 @@ export class FriendAddComponent implements OnInit {
     this.hosts.splice(index, 1)
   }
 
-  makeFriends () {
+  addFollowing () {
     this.error = ''
 
     const notEmptyHosts = this.getNotEmptyHosts()
@@ -87,13 +87,13 @@ export class FriendAddComponent implements OnInit {
     }
 
     const confirmMessage = 'Are you sure to make friends with:<br /> - ' + notEmptyHosts.join('<br /> - ')
-    this.confirmService.confirm(confirmMessage, 'Make friends').subscribe(
+    this.confirmService.confirm(confirmMessage, 'Follow new server(s)').subscribe(
       res => {
         if (res === false) return
 
-        this.friendService.follow(notEmptyHosts).subscribe(
+        this.followService.follow(notEmptyHosts).subscribe(
           status => {
-            this.notificationsService.success('Success', 'Make friends request sent!')
+            this.notificationsService.success('Success', 'Follow request(s) sent!')
             // Wait requests between pods
             setTimeout(() => this.router.navigate([ '/admin/friends/list' ]), 1000)
           },
diff --git a/client/src/app/+admin/follows/following-add/index.ts b/client/src/app/+admin/follows/following-add/index.ts
new file mode 100644 (file)
index 0000000..1b1897f
--- /dev/null
@@ -0,0 +1 @@
+export * from './following-add.component'
diff --git a/client/src/app/+admin/follows/following-list/following-list.component.html b/client/src/app/+admin/follows/following-list/following-list.component.html
new file mode 100644 (file)
index 0000000..fbcebfa
--- /dev/null
@@ -0,0 +1,16 @@
+<div class="row">
+  <div class="content-padding">
+    <h3>Following list</h3>
+
+    <p-dataTable
+        [value]="following" [lazy]="true" [paginator]="true" [totalRecords]="totalRecords" [rows]="rowsPerPage"
+        sortField="createdAt" (onLazyLoad)="loadLazy($event)"
+    >
+      <p-column field="id" header="ID"></p-column>
+      <p-column field="host" header="Host"></p-column>
+      <p-column field="email" header="Email"></p-column>
+      <p-column field="score" header="Score"></p-column>
+      <p-column field="createdAt" header="Created date" [sortable]="true"></p-column>
+    </p-dataTable>
+  </div>
+</div>
diff --git a/client/src/app/+admin/follows/following-list/following-list.component.ts b/client/src/app/+admin/follows/following-list/following-list.component.ts
new file mode 100644 (file)
index 0000000..7d2c508
--- /dev/null
@@ -0,0 +1,40 @@
+import { Component, OnInit } from '@angular/core'
+
+import { NotificationsService } from 'angular2-notifications'
+import { SortMeta } from 'primeng/primeng'
+
+import { ConfirmService } from '../../../core'
+import { RestTable, RestPagination } from '../../../shared'
+import { Pod } from '../../../../../../shared'
+import { FollowService } from '../shared'
+
+@Component({
+  selector: 'my-followers-list',
+  templateUrl: './following-list.component.html'
+})
+export class FollowingListComponent extends RestTable {
+  following: Pod[] = []
+  totalRecords = 0
+  rowsPerPage = 10
+  sort: SortMeta = { field: 'createdAt', order: 1 }
+  pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
+
+  constructor (
+    private notificationsService: NotificationsService,
+    private followService: FollowService
+  ) {
+    super()
+  }
+
+  protected loadData () {
+    this.followService.getFollowing(this.pagination, this.sort)
+                      .subscribe(
+                        resultList => {
+                          this.following = resultList.data
+                          this.totalRecords = resultList.total
+                        },
+
+                        err => this.notificationsService.error('Error', err.message)
+                      )
+  }
+}
diff --git a/client/src/app/+admin/follows/following-list/index.ts b/client/src/app/+admin/follows/following-list/index.ts
new file mode 100644 (file)
index 0000000..a70d46a
--- /dev/null
@@ -0,0 +1 @@
+export * from './following-list.component'
diff --git a/client/src/app/+admin/follows/follows.component.html b/client/src/app/+admin/follows/follows.component.html
new file mode 100644 (file)
index 0000000..b67bc97
--- /dev/null
@@ -0,0 +1,11 @@
+<div class="follows-menu">
+  <tabset #followsMenuTabs>
+    <tab *ngFor="let link of links">
+      <ng-template tabHeading>
+        <a class="tab-link" [routerLink]="link.path">{{ link.title }}</a>
+      </ng-template>
+    </tab>
+  </tabset>
+</div>
+
+<router-outlet></router-outlet>
diff --git a/client/src/app/+admin/follows/follows.component.scss b/client/src/app/+admin/follows/follows.component.scss
new file mode 100644 (file)
index 0000000..d8ab419
--- /dev/null
@@ -0,0 +1,21 @@
+.follows-menu {
+  margin-top: 20px;
+}
+
+tabset /deep/ {
+  .nav-link {
+    padding: 0;
+  }
+
+  .tab-link {
+    display: block;
+    text-align: center;
+    height: 40px;
+    width: 120px;
+    line-height: 40px;
+
+    &:hover, &:active, &:focus {
+      text-decoration: none !important;
+    }
+  }
+}
diff --git a/client/src/app/+admin/follows/follows.component.ts b/client/src/app/+admin/follows/follows.component.ts
new file mode 100644 (file)
index 0000000..97422a4
--- /dev/null
@@ -0,0 +1,43 @@
+import { AfterViewInit, Component, ViewChild } from '@angular/core'
+import { TabsetComponent } from 'ngx-bootstrap/tabs'
+
+@Component({
+  templateUrl: './follows.component.html',
+  styleUrls: [ './follows.component.scss' ]
+})
+export class FollowsComponent implements AfterViewInit {
+  @ViewChild('followsMenuTabs') followsMenuTabs: TabsetComponent
+
+  links = [
+    {
+      path: 'following-list',
+      title: 'Following'
+    },
+    {
+      path: 'following-add',
+      title: 'Follow'
+    },
+    {
+      path: 'followers-list',
+      title: 'Followers'
+    }
+  ]
+
+  ngAfterViewInit () {
+    // Avoid issue with change detector
+    setTimeout(() => this.updateActiveTab())
+  }
+
+  private updateActiveTab () {
+    const url = window.location.pathname
+
+    for (let i = 0; i < this.links.length; i++) {
+      const path = this.links[i].path
+
+      if (url.endsWith(path) === true) {
+        this.followsMenuTabs.tabs[i].active = true
+        return
+      }
+    }
+  }
+}
diff --git a/client/src/app/+admin/follows/follows.routes.ts b/client/src/app/+admin/follows/follows.routes.ts
new file mode 100644 (file)
index 0000000..b7d44f7
--- /dev/null
@@ -0,0 +1,53 @@
+import { Routes } from '@angular/router'
+
+import { UserRightGuard } from '../../core'
+import { FollowsComponent } from './follows.component'
+import { FollowingAddComponent } from './following-add'
+import { FollowersListComponent } from './followers-list'
+import { UserRight } from '../../../../../shared'
+import { FollowingListComponent } from './following-list/following-list.component'
+
+export const FollowsRoutes: Routes = [
+  {
+    path: 'follows',
+    component: FollowsComponent,
+    canActivate: [ UserRightGuard ],
+    data: {
+      userRight: UserRight.MANAGE_APPLICATION_FOLLOW
+    },
+    children: [
+      {
+        path: '',
+        redirectTo: 'following-list',
+        pathMatch: 'full'
+      },
+      {
+        path: 'following-list',
+        component: FollowingListComponent,
+        data: {
+          meta: {
+            title: 'Following list'
+          }
+        }
+      },
+      {
+        path: 'followers-list',
+        component: FollowersListComponent,
+        data: {
+          meta: {
+            title: 'Followers list'
+          }
+        }
+      },
+      {
+        path: 'following-add',
+        component: FollowingAddComponent,
+        data: {
+          meta: {
+            title: 'Add follow'
+          }
+        }
+      }
+    ]
+  }
+]
diff --git a/client/src/app/+admin/follows/index.ts b/client/src/app/+admin/follows/index.ts
new file mode 100644 (file)
index 0000000..7849a06
--- /dev/null
@@ -0,0 +1,6 @@
+export * from './following-add'
+export * from './followers-list'
+export * from './following-list'
+export * from './shared'
+export * from './follows.component'
+export * from './follows.routes'
similarity index 60%
rename from client/src/app/+admin/friends/shared/friend.service.ts
rename to client/src/app/+admin/follows/shared/follow.service.ts
index 867656a53a1e172d54aa333403886aff3cbe5d62..622c33cea439e6fca5e2df02281a8972936b7a51 100644 (file)
@@ -10,8 +10,8 @@ import { RestExtractor, RestPagination, RestService } from '../../../shared'
 import { Pod, ResultList } from '../../../../../../shared'
 
 @Injectable()
-export class FriendService {
-  private static BASE_FRIEND_URL = API_URL + '/api/v1/pods/'
+export class FollowService {
+  private static BASE_APPLICATION_URL = API_URL + '/api/v1/application'
 
   constructor (
     private authHttp: HttpClient,
@@ -23,29 +23,26 @@ export class FriendService {
     let params = new HttpParams()
     params = this.restService.addRestGetParams(params, pagination, sort)
 
-    return this.authHttp.get<ResultList<Account>>(API_URL + '/api/v1/pods/followers', { params })
+    return this.authHttp.get<ResultList<Account>>(FollowService.BASE_APPLICATION_URL + '/following', { params })
                         .map(res => this.restExtractor.convertResultListDateToHuman(res))
                         .catch(res => this.restExtractor.handleError(res))
   }
 
+  getFollowers (pagination: RestPagination, sort: SortMeta): Observable<ResultList<Pod>> {
+    let params = new HttpParams()
+    params = this.restService.addRestGetParams(params, pagination, sort)
+
+    return this.authHttp.get<ResultList<Account>>(FollowService.BASE_APPLICATION_URL + '/followers', { params })
+      .map(res => this.restExtractor.convertResultListDateToHuman(res))
+      .catch(res => this.restExtractor.handleError(res))
+  }
+
   follow (notEmptyHosts: String[]) {
     const body = {
       hosts: notEmptyHosts
     }
 
-    return this.authHttp.post(API_URL + '/api/v1/pods/follow', body)
-                        .map(this.restExtractor.extractDataBool)
-                        .catch(res => this.restExtractor.handleError(res))
-  }
-
-  quitFriends () {
-    return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quit-friends')
-                        .map(this.restExtractor.extractDataBool)
-                        .catch(res => this.restExtractor.handleError(res))
-  }
-
-  removeFriend (friend: Pod) {
-    return this.authHttp.delete(FriendService.BASE_FRIEND_URL + friend.id)
+    return this.authHttp.post(FollowService.BASE_APPLICATION_URL + '/follow', body)
                         .map(this.restExtractor.extractDataBool)
                         .catch(res => this.restExtractor.handleError(res))
   }
diff --git a/client/src/app/+admin/follows/shared/index.ts b/client/src/app/+admin/follows/shared/index.ts
new file mode 100644 (file)
index 0000000..78d456d
--- /dev/null
@@ -0,0 +1 @@
+export * from './follow.service'
diff --git a/client/src/app/+admin/friends/friend-add/index.ts b/client/src/app/+admin/friends/friend-add/index.ts
deleted file mode 100644 (file)
index 978ab3d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-export * from './friend-add.component'
diff --git a/client/src/app/+admin/friends/friend-list/friend-list.component.html b/client/src/app/+admin/friends/friend-list/friend-list.component.html
deleted file mode 100644 (file)
index df5a570..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<div class="row">
-  <div class="content-padding">
-    <h3>Friends list</h3>
-
-    <p-dataTable
-        [value]="friends" [lazy]="true" [paginator]="true" [totalRecords]="totalRecords" [rows]="rowsPerPage"
-        sortField="createdAt" (onLazyLoad)="loadLazy($event)"
-    >
-      <p-column field="id" header="ID"></p-column>
-      <p-column field="host" header="Host"></p-column>
-      <p-column field="email" header="Email"></p-column>
-      <p-column field="score" header="Score"></p-column>
-      <p-column field="createdAt" header="Created date" [sortable]="true"></p-column>
-      <p-column header="Delete" styleClass="action-cell">
-        <ng-template pTemplate="body" let-pod="rowData">
-          <span (click)="removeFriend(pod)" class="glyphicon glyphicon-remove glyphicon-black" title="Remove this pod"></span>
-        </ng-template>
-      </p-column>
-    </p-dataTable>
-
-    <a *ngIf="hasFriends()" class="btn btn-danger pull-left" (click)="quitFriends()">
-      Quit friends
-    </a>
-
-    <a *ngIf="!hasFriends()" class="btn btn-success pull-right" [routerLink]="[ '/admin/friends/add' ]">
-      Make friends
-    </a>
-  </div>
-</div>
diff --git a/client/src/app/+admin/friends/friend-list/friend-list.component.ts b/client/src/app/+admin/friends/friend-list/friend-list.component.ts
deleted file mode 100644 (file)
index 3fa8ef1..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-import { Component, OnInit } from '@angular/core'
-
-import { NotificationsService } from 'angular2-notifications'
-import { SortMeta } from 'primeng/primeng'
-
-import { ConfirmService } from '../../../core'
-import { RestTable, RestPagination } from '../../../shared'
-import { Pod } from '../../../../../../shared'
-import { FriendService } from '../shared'
-
-@Component({
-  selector: 'my-friend-list',
-  templateUrl: './friend-list.component.html',
-  styleUrls: ['./friend-list.component.scss']
-})
-export class FriendListComponent extends RestTable implements OnInit {
-  friends: Pod[] = []
-  totalRecords = 0
-  rowsPerPage = 10
-  sort: SortMeta = { field: 'createdAt', order: 1 }
-  pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
-
-  constructor (
-    private notificationsService: NotificationsService,
-    private confirmService: ConfirmService,
-    private friendService: FriendService
-  ) {
-    super()
-  }
-
-  ngOnInit () {
-    this.loadData()
-  }
-
-  hasFriends () {
-    return this.friends.length !== 0
-  }
-
-  quitFriends () {
-    const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.'
-    this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe(
-      res => {
-        if (res === false) return
-
-        this.friendService.quitFriends().subscribe(
-          status => {
-            this.notificationsService.success('Success', 'Friends left!')
-            this.loadData()
-          },
-
-          err => this.notificationsService.error('Error', err.message)
-        )
-      }
-    )
-  }
-
-  removeFriend (friend: Pod) {
-    const confirmMessage = 'Do you really want to remove this friend ? All its videos will be deleted.'
-
-    this.confirmService.confirm(confirmMessage, 'Remove').subscribe(
-      res => {
-        if (res === false) return
-
-        this.friendService.removeFriend(friend).subscribe(
-          status => {
-            this.notificationsService.success('Success', 'Friend removed')
-            this.loadData()
-          },
-
-          err => this.notificationsService.error('Error', err.message)
-        )
-      }
-    )
-  }
-
-  protected loadData () {
-    this.friendService.getFollowing(this.pagination, this.sort)
-                      .subscribe(
-                        resultList => {
-                          this.friends = resultList.data
-                          this.totalRecords = resultList.total
-                        },
-
-                        err => this.notificationsService.error('Error', err.message)
-                      )
-  }
-}
diff --git a/client/src/app/+admin/friends/friend-list/index.ts b/client/src/app/+admin/friends/friend-list/index.ts
deleted file mode 100644 (file)
index c9cbd28..0000000
+++ /dev/null
@@ -1 +0,0 @@
-export * from './friend-list.component'
diff --git a/client/src/app/+admin/friends/friends.component.ts b/client/src/app/+admin/friends/friends.component.ts
deleted file mode 100644 (file)
index 5ef0aaa..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-import { Component } from '@angular/core'
-
-@Component({
-  template: '<router-outlet></router-outlet>'
-})
-export class FriendsComponent {
-}
diff --git a/client/src/app/+admin/friends/friends.routes.ts b/client/src/app/+admin/friends/friends.routes.ts
deleted file mode 100644 (file)
index e2cb953..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-import { Routes } from '@angular/router'
-
-import { UserRightGuard } from '../../core'
-import { FriendsComponent } from './friends.component'
-import { FriendAddComponent } from './friend-add'
-import { FriendListComponent } from './friend-list'
-import { UserRight } from '../../../../../shared'
-
-export const FriendsRoutes: Routes = [
-  {
-    path: 'friends',
-    component: FriendsComponent,
-    canActivate: [ UserRightGuard ],
-    data: {
-      userRight: UserRight.MANAGE_PEERTUBE_FOLLOW
-    },
-    children: [
-      {
-        path: '',
-        redirectTo: 'list',
-        pathMatch: 'full'
-      },
-      {
-        path: 'list',
-        component: FriendListComponent,
-        data: {
-          meta: {
-            title: 'Friends list'
-          }
-        }
-      },
-      {
-        path: 'add',
-        component: FriendAddComponent,
-        data: {
-          meta: {
-            title: 'Add friends'
-          }
-        }
-      }
-    ]
-  }
-]
diff --git a/client/src/app/+admin/friends/index.ts b/client/src/app/+admin/friends/index.ts
deleted file mode 100644 (file)
index 356dee8..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-export * from './friend-add'
-export * from './friend-list'
-export * from './shared'
-export * from './friends.component'
-export * from './friends.routes'
diff --git a/client/src/app/+admin/friends/shared/index.ts b/client/src/app/+admin/friends/shared/index.ts
deleted file mode 100644 (file)
index 65ab9fb..0000000
+++ /dev/null
@@ -1 +0,0 @@
-export * from './friend.service'
index 1966a944c1c6de6182c7ad952ac024b11d1a589e..99ee287c52f91572acfa734134a25c03935043d8 100644 (file)
@@ -5,9 +5,9 @@
       List users
     </a>
 
-    <a *ngIf="hasFriendsRight()" routerLink="/admin/friends" routerLinkActive="active">
+    <a *ngIf="hasApplicationFollowRight()" routerLink="/admin/follows" routerLinkActive="active">
       <span class="hidden-xs glyphicon glyphicon-cloud"></span>
-      List friends
+      Manage follows
     </a>
 
     <a *ngIf="hasVideoAbusesRight()" routerLink="/admin/video-abuses" routerLinkActive="active">
index 92aab9a059b30eaab8e8149692fcd9f55893c2ae..88a654d1fd000ff533a6eaa7f7c26d3cea085050 100644 (file)
@@ -15,8 +15,8 @@ export class MenuAdminComponent {
     return this.auth.getUser().hasRight(UserRight.MANAGE_USERS)
   }
 
-  hasFriendsRight () {
-    return this.auth.getUser().hasRight(UserRight.MANAGE_PEERTUBE_FOLLOW)
+  hasApplicationFollowRight () {
+    return this.auth.getUser().hasRight(UserRight.MANAGE_APPLICATION_FOLLOW)
   }
 
   hasVideoAbusesRight () {
index 71295be86deb1c22b57d0c23e231b0eb7b64db36..872d29819bbbf343b889f6fdc897a5b85b7b7e65 100644 (file)
@@ -16,7 +16,7 @@ export class MenuComponent implements OnInit {
 
   private routesPerRight = {
     [UserRight.MANAGE_USERS]: '/admin/users',
-    [UserRight.MANAGE_PEERTUBE_FOLLOW]: '/admin/friends',
+    [UserRight.MANAGE_APPLICATION_FOLLOW]: '/admin/friends',
     [UserRight.MANAGE_VIDEO_ABUSES]: '/admin/video-abuses',
     [UserRight.MANAGE_VIDEO_BLACKLIST]: '/admin/video-blacklist'
   }
@@ -58,7 +58,7 @@ export class MenuComponent implements OnInit {
 
     const adminRights = [
       UserRight.MANAGE_USERS,
-      UserRight.MANAGE_PEERTUBE_FOLLOW,
+      UserRight.MANAGE_APPLICATION_FOLLOW,
       UserRight.MANAGE_VIDEO_ABUSES,
       UserRight.MANAGE_VIDEO_BLACKLIST
     ]
index 7c46dc52b17d0f3a6a76864262680fea6c6e6605..05f0ef96d5e67003eef1106d639f71ed7719e6da 100755 (executable)
@@ -3,7 +3,7 @@ import { database as db } from '../server/initializers/database'
 
 db.init(true)
   .then(() => {
-    // FIXME: check if has followers
+    // FIXME: check if has following
     // return hasFriends()
     return true
   })
index 56a4054fabdfd475144c4fe48eb31c4931c6b71b..49dd24e79e118346456755c9928d7450b54653bc 100644 (file)
@@ -46,7 +46,7 @@ async function accountFollowersController (req: express.Request, res: express.Re
   const page = req.params.page || 1
   const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
 
-  const result = await db.Account.listAcceptedFollowerUrlsForApi(account.id, start, count)
+  const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi(account.id, start, count)
   const activityPubResult = activityPubCollectionPagination(req.url, page, result)
 
   return res.json(activityPubResult)
@@ -58,7 +58,7 @@ async function accountFollowingController (req: express.Request, res: express.Re
   const page = req.params.page || 1
   const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
 
-  const result = await db.Account.listAcceptedFollowingUrlsForApi(account.id, start, count)
+  const result = await db.AccountFollow.listAcceptedFollowingUrlsForApi(account.id, start, count)
   const activityPubResult = activityPubCollectionPagination(req.url, page, result)
 
   return res.json(activityPubResult)
index 0c8574ef78d46c81aa38683bca6e87ff48741575..c5bec64487758a9a2adaff78647148fbe077b42a 100644 (file)
@@ -1,14 +1,11 @@
 import * as express from 'express'
-
-import { badRequest } from '../../helpers'
-import { inboxRouter } from './inbox'
 import { activityPubClientRouter } from './client'
+import { inboxRouter } from './inbox'
 
 const activityPubRouter = express.Router()
 
 activityPubRouter.use('/', inboxRouter)
 activityPubRouter.use('/', activityPubClientRouter)
-activityPubRouter.use('/*', badRequest)
 
 // ---------------------------------------------------------------------------
 
similarity index 68%
rename from server/controllers/api/pods.ts
rename to server/controllers/api/application/follows.ts
index 0bd6971bb65ce07ab8ef18f376c0ff2f56e51f67..000bbd23eb8b352f07c0612c41b4cf872f8d5e23 100644 (file)
@@ -1,23 +1,23 @@
 import * as express from 'express'
-import { UserRight } from '../../../shared/models/users/user-right.enum'
-import { getFormattedObjects } from '../../helpers'
-import { logger } from '../../helpers/logger'
-import { getApplicationAccount } from '../../helpers/utils'
-import { getAccountFromWebfinger } from '../../helpers/webfinger'
-import { SERVER_ACCOUNT_NAME } from '../../initializers/constants'
-import { database as db } from '../../initializers/database'
-import { sendFollow } from '../../lib/activitypub/send-request'
-import { asyncMiddleware, paginationValidator, setFollowersSort, setPagination } from '../../middlewares'
-import { authenticate } from '../../middlewares/oauth'
-import { setBodyHostsPort } from '../../middlewares/pods'
-import { setFollowingSort } from '../../middlewares/sort'
-import { ensureUserHasRight } from '../../middlewares/user-right'
-import { followValidator } from '../../middlewares/validators/pods'
-import { followersSortValidator, followingSortValidator } from '../../middlewares/validators/sort'
-
-const podsRouter = express.Router()
-
-podsRouter.get('/following',
+import { UserRight } from '../../../../shared/models/users/user-right.enum'
+import { getFormattedObjects } from '../../../helpers'
+import { logger } from '../../../helpers/logger'
+import { getApplicationAccount } from '../../../helpers/utils'
+import { getAccountFromWebfinger } from '../../../helpers/webfinger'
+import { SERVER_ACCOUNT_NAME } from '../../../initializers/constants'
+import { database as db } from '../../../initializers/database'
+import { sendFollow } from '../../../lib/activitypub/send-request'
+import { asyncMiddleware, paginationValidator, setFollowersSort, setPagination } from '../../../middlewares'
+import { authenticate } from '../../../middlewares/oauth'
+import { setBodyHostsPort } from '../../../middlewares/pods'
+import { setFollowingSort } from '../../../middlewares/sort'
+import { ensureUserHasRight } from '../../../middlewares/user-right'
+import { followValidator } from '../../../middlewares/validators/pods'
+import { followersSortValidator, followingSortValidator } from '../../../middlewares/validators/sort'
+
+const applicationFollowsRouter = express.Router()
+
+applicationFollowsRouter.get('/following',
   paginationValidator,
   followingSortValidator,
   setFollowingSort,
@@ -25,15 +25,15 @@ podsRouter.get('/following',
   asyncMiddleware(listFollowing)
 )
 
-podsRouter.post('/follow',
+applicationFollowsRouter.post('/follow',
   authenticate,
-  ensureUserHasRight(UserRight.MANAGE_PEERTUBE_FOLLOW),
+  ensureUserHasRight(UserRight.MANAGE_APPLICATION_FOLLOW),
   followValidator,
   setBodyHostsPort,
   asyncMiddleware(follow)
 )
 
-podsRouter.get('/followers',
+applicationFollowsRouter.get('/followers',
   paginationValidator,
   followersSortValidator,
   setFollowersSort,
@@ -44,21 +44,21 @@ podsRouter.get('/followers',
 // ---------------------------------------------------------------------------
 
 export {
-  podsRouter
+  applicationFollowsRouter
 }
 
 // ---------------------------------------------------------------------------
 
 async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) {
   const applicationAccount = await getApplicationAccount()
-  const resultList = await db.Account.listFollowingForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort)
+  const resultList = await db.AccountFollow.listFollowingForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort)
 
   return res.json(getFormattedObjects(resultList.data, resultList.total))
 }
 
 async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) {
   const applicationAccount = await getApplicationAccount()
-  const resultList = await db.Account.listFollowersForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort)
+  const resultList = await db.AccountFollow.listFollowersForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort)
 
   return res.json(getFormattedObjects(resultList.data, resultList.total))
 }
diff --git a/server/controllers/api/application/index.ts b/server/controllers/api/application/index.ts
new file mode 100644 (file)
index 0000000..011b971
--- /dev/null
@@ -0,0 +1,12 @@
+import * as express from 'express'
+import { applicationFollowsRouter } from './follows'
+
+const applicationRouter = express.Router()
+
+applicationRouter.use('/', applicationFollowsRouter)
+
+// ---------------------------------------------------------------------------
+
+export {
+  applicationRouter
+}
index 2e949d5319370de13a124196d41d49ae16bb7427..a22c78cceb079010cbfcc09d658e7a59b33659f8 100644 (file)
@@ -4,15 +4,15 @@ import { badRequest } from '../../helpers'
 
 import { oauthClientsRouter } from './oauth-clients'
 import { configRouter } from './config'
-import { podsRouter } from './pods'
+import { applicationRouter } from './application'
 import { usersRouter } from './users'
 import { videosRouter } from './videos'
 
 const apiRouter = express.Router()
 
+apiRouter.use('/application', applicationRouter)
 apiRouter.use('/oauth-clients', oauthClientsRouter)
 apiRouter.use('/config', configRouter)
-apiRouter.use('/pods', podsRouter)
 apiRouter.use('/users', usersRouter)
 apiRouter.use('/videos', videosRouter)
 apiRouter.use('/ping', pong)
index 1c726f0cbe549590122c762a415caf59feb3555b..102ac0937b884a35a38a33e2f4ed85af0e4f046d 100644 (file)
@@ -8,7 +8,7 @@ import { AccountInstance } from '../models/account/account-interface'
 
 const webfingerRouter = express.Router()
 
-webfingerRouter.use('/.well-known/webfinger',
+webfingerRouter.get('/.well-known/webfinger',
   webfingerValidator,
   webfingerController
 )
index d47040d6dd0cb2246f1ea479cdc12d3f585abe66..f942a2ebad3fbb6e27b13be89ec7210f89478414 100644 (file)
@@ -85,7 +85,7 @@ export {
 // ---------------------------------------------------------------------------
 
 async function broadcastToFollowers (data: any, fromAccount: AccountInstance, t: Sequelize.Transaction) {
-  const result = await db.Account.listAcceptedFollowerUrlsForApi(fromAccount.id, 0)
+  const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi(fromAccount.id, 0)
 
   const jobPayload = {
     uris: result.data,
index efdff915e1890da389bcff2d9807d62bee2516e1..413dad190f0afa9042fcc696f6c6c40484e5fffc 100644 (file)
@@ -1,13 +1,26 @@
 import * as Sequelize from 'sequelize'
 import * as Bluebird from 'bluebird'
 import { FollowState } from '../../../shared/models/accounts/follow.model'
+import { ResultList } from '../../../shared/models/result-list.model'
+import { AccountInstance } from './account-interface'
 
 export namespace AccountFollowMethods {
   export type LoadByAccountAndTarget = (accountId: number, targetAccountId: number) => Bluebird<AccountFollowInstance>
+
+  export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
+  export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
+
+  export type ListAcceptedFollowerUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> >
+  export type ListAcceptedFollowingUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> >
 }
 
 export interface AccountFollowClass {
   loadByAccountAndTarget: AccountFollowMethods.LoadByAccountAndTarget
+  listFollowersForApi: AccountFollowMethods.ListFollowersForApi
+  listFollowingForApi: AccountFollowMethods.ListFollowingForApi
+
+  listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi
+  listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi
 }
 
 export interface AccountFollowAttributes {
@@ -20,6 +33,9 @@ export interface AccountFollowInstance extends AccountFollowClass, AccountFollow
   id: number
   createdAt: Date
   updatedAt: Date
+
+  AccountFollower?: AccountInstance
+  AccountFollowing?: AccountInstance
 }
 
 export interface AccountFollowModel extends AccountFollowClass, Sequelize.Model<AccountFollowInstance, AccountFollowAttributes> {}
index 7c129ab9dabc5ef18bca9d17964e2ca8475af926..6d7592326d7ad3cb8fc8a6ff940ceeb352dbb9a5 100644 (file)
@@ -1,12 +1,16 @@
 import { values } from 'lodash'
 import * as Sequelize from 'sequelize'
 
-import { addMethodsToModel } from '../utils'
+import { addMethodsToModel, getSort } from '../utils'
 import { AccountFollowAttributes, AccountFollowInstance, AccountFollowMethods } from './account-follow-interface'
 import { FOLLOW_STATES } from '../../initializers/constants'
 
 let AccountFollow: Sequelize.Model<AccountFollowInstance, AccountFollowAttributes>
 let loadByAccountAndTarget: AccountFollowMethods.LoadByAccountAndTarget
+let listFollowingForApi: AccountFollowMethods.ListFollowingForApi
+let listFollowersForApi: AccountFollowMethods.ListFollowersForApi
+let listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi
+let listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi
 
 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
   AccountFollow = sequelize.define<AccountFollowInstance, AccountFollowAttributes>('AccountFollow',
@@ -34,7 +38,11 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
 
   const classMethods = [
     associate,
-    loadByAccountAndTarget
+    loadByAccountAndTarget,
+    listFollowingForApi,
+    listFollowersForApi,
+    listAcceptedFollowerUrlsForApi,
+    listAcceptedFollowingUrlsForApi
   ]
   addMethodsToModel(AccountFollow, classMethods)
 
@@ -49,7 +57,7 @@ function associate (models) {
       name: 'accountId',
       allowNull: false
     },
-    as: 'accountFollowers',
+    as: 'AccountFollower',
     onDelete: 'CASCADE'
   })
 
@@ -58,7 +66,7 @@ function associate (models) {
       name: 'targetAccountId',
       allowNull: false
     },
-    as: 'accountFollowing',
+    as: 'AccountFollowing',
     onDelete: 'CASCADE'
   })
 }
@@ -73,3 +81,117 @@ loadByAccountAndTarget = function (accountId: number, targetAccountId: number) {
 
   return AccountFollow.findOne(query)
 }
+
+listFollowingForApi = function (id: number, start: number, count: number, sort: string) {
+  const query = {
+    distinct: true,
+    offset: start,
+    limit: count,
+    order: [ getSort(sort) ],
+    include: [
+      {
+        model: AccountFollow[ 'sequelize' ].models.Account,
+        required: true,
+        as: 'AccountFollower',
+        where: {
+          id
+        }
+      },
+      {
+        model: AccountFollow['sequelize'].models.Account,
+        as: 'AccountFollowing',
+        required: true,
+        include: [ AccountFollow['sequelize'].models.Pod ]
+      }
+    ]
+  }
+
+  return AccountFollow.findAndCountAll(query).then(({ rows, count }) => {
+    return {
+      data: rows.map(r => r.AccountFollowing),
+      total: count
+    }
+  })
+}
+
+listFollowersForApi = function (id: number, start: number, count: number, sort: string) {
+  const query = {
+    distinct: true,
+    offset: start,
+    limit: count,
+    order: [ getSort(sort) ],
+    include: [
+      {
+        model: AccountFollow[ 'sequelize' ].models.Account,
+        required: true,
+        as: 'AccountFollower',
+        include: [ AccountFollow['sequelize'].models.Pod ]
+      },
+      {
+        model: AccountFollow['sequelize'].models.Account,
+        as: 'AccountFollowing',
+        required: true,
+        where: {
+          id
+        }
+      }
+    ]
+  }
+
+  return AccountFollow.findAndCountAll(query).then(({ rows, count }) => {
+    return {
+      data: rows.map(r => r.AccountFollower),
+      total: count
+    }
+  })
+}
+
+listAcceptedFollowerUrlsForApi = function (id: number, start: number, count?: number) {
+  return createListAcceptedFollowForApiQuery('followers', id, start, count)
+}
+
+listAcceptedFollowingUrlsForApi = function (id: number, start: number, count?: number) {
+  return createListAcceptedFollowForApiQuery('following', id, start, count)
+}
+
+// ------------------------------ UTILS ------------------------------
+
+async function createListAcceptedFollowForApiQuery (type: 'followers' | 'following', id: number, start: number, count?: number) {
+  let firstJoin: string
+  let secondJoin: string
+
+  if (type === 'followers') {
+    firstJoin = 'targetAccountId'
+    secondJoin = 'accountId'
+  } else {
+    firstJoin = 'accountId'
+    secondJoin = 'targetAccountId'
+  }
+
+  const selections = [ '"Followers"."url" AS "url"', 'COUNT(*) AS "total"' ]
+  const tasks: Promise<any>[] = []
+
+  for (const selection of selections) {
+    let query = 'SELECT ' + selection + ' FROM "Account" ' +
+      'INNER JOIN "AccountFollow" ON "AccountFollow"."' + firstJoin + '" = "Account"."id" ' +
+      'INNER JOIN "Account" AS "Follows" ON "Followers"."id" = "Follows"."' + secondJoin + '" ' +
+      'WHERE "Account"."id" = $id AND "AccountFollow"."state" = \'accepted\' ' +
+      'LIMIT ' + start
+
+    if (count !== undefined) query += ', ' + count
+
+    const options = {
+      bind: { id },
+      type: Sequelize.QueryTypes.SELECT
+    }
+    tasks.push(AccountFollow['sequelize'].query(query, options))
+  }
+
+  const [ followers, [ { total } ]] = await Promise.all(tasks)
+  const urls: string[] = followers.map(f => f.url)
+
+  return {
+    data: urls,
+    total: parseInt(total, 10)
+  }
+}
index 6fc36ae9d7fe447c47eee9e84c5b9e0e3b77de7d..ce1afec022b51be644167cf8da911f879e54f960 100644 (file)
@@ -15,10 +15,6 @@ export namespace AccountMethods {
   export type LoadLocalByName = (name: string) => Bluebird<AccountInstance>
   export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance>
   export type ListOwned = () => Bluebird<AccountInstance[]>
-  export type ListAcceptedFollowerUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> >
-  export type ListAcceptedFollowingUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> >
-  export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
-  export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
 
   export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor
   export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount
@@ -38,10 +34,6 @@ export interface AccountClass {
   loadLocalByName: AccountMethods.LoadLocalByName
   loadByNameAndHost: AccountMethods.LoadByNameAndHost
   listOwned: AccountMethods.ListOwned
-  listAcceptedFollowerUrlsForApi: AccountMethods.ListAcceptedFollowerUrlsForApi
-  listAcceptedFollowingUrlsForApi: AccountMethods.ListAcceptedFollowingUrlsForApi
-  listFollowingForApi: AccountMethods.ListFollowingForApi
-  listFollowersForApi: AccountMethods.ListFollowersForApi
 }
 
 export interface AccountAttributes {
index d2293a9392c48e0ffbeeebbb54a16b30a841a41b..e90eaae5e632109bcfe0ce14d32697316125545f 100644 (file)
@@ -23,7 +23,7 @@ import {
   AccountMethods
 } from './account-interface'
 import { sendDeleteAccount } from '../../lib/activitypub/send-request'
-import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
+import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants'
 
 let Account: Sequelize.Model<AccountInstance, AccountAttributes>
 let loadAccountByPodAndUUID: AccountMethods.LoadAccountByPodAndUUID
@@ -34,10 +34,6 @@ let loadByUrl: AccountMethods.LoadByUrl
 let loadLocalByName: AccountMethods.LoadLocalByName
 let loadByNameAndHost: AccountMethods.LoadByNameAndHost
 let listOwned: AccountMethods.ListOwned
-let listAcceptedFollowerUrlsForApi: AccountMethods.ListAcceptedFollowerUrlsForApi
-let listAcceptedFollowingUrlsForApi: AccountMethods.ListAcceptedFollowingUrlsForApi
-let listFollowingForApi: AccountMethods.ListFollowingForApi
-let listFollowersForApi: AccountMethods.ListFollowersForApi
 let isOwned: AccountMethods.IsOwned
 let toActivityPubObject: AccountMethods.ToActivityPubObject
 let toFormattedJSON: AccountMethods.ToFormattedJSON
@@ -185,7 +181,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
           unique: true
         },
         {
-          fields: [ 'name', 'podId' ],
+          fields: [ 'name', 'podId', 'applicationId' ],
           unique: true
         }
       ],
@@ -202,11 +198,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
     loadByUrl,
     loadLocalByName,
     loadByNameAndHost,
-    listOwned,
-    listAcceptedFollowerUrlsForApi,
-    listAcceptedFollowingUrlsForApi,
-    listFollowingForApi,
-    listFollowersForApi
+    listOwned
   ]
   const instanceMethods = [
     isOwned,
@@ -286,9 +278,11 @@ function afterDestroy (account: AccountInstance) {
 }
 
 toFormattedJSON = function (this: AccountInstance) {
+  let host = this.Pod ? this.Pod.host : CONFIG.WEBSERVER.HOST
+
   const json = {
     id: this.id,
-    host: this.Pod.host,
+    host,
     name: this.name
   }
 
@@ -346,7 +340,7 @@ getFollowerSharedInboxUrls = function (this: AccountInstance) {
 }
 
 getFollowingUrl = function (this: AccountInstance) {
-  return this.url + '/followers'
+  return this.url + '/following'
 }
 
 getFollowersUrl = function (this: AccountInstance) {
@@ -369,76 +363,6 @@ listOwned = function () {
   return Account.findAll(query)
 }
 
-listAcceptedFollowerUrlsForApi = function (id: number, start: number, count?: number) {
-  return createListAcceptedFollowForApiQuery('followers', id, start, count)
-}
-
-listAcceptedFollowingUrlsForApi = function (id: number, start: number, count?: number) {
-  return createListAcceptedFollowForApiQuery('following', id, start, count)
-}
-
-listFollowingForApi = function (id: number, start: number, count: number, sort: string) {
-  const query = {
-    distinct: true,
-    offset: start,
-    limit: count,
-    order: [ getSort(sort) ],
-    include: [
-      {
-        model: Account['sequelize'].models.AccountFollow,
-        required: true,
-        as: 'following',
-        include: [
-          {
-            model: Account['sequelize'].models.Account,
-            as: 'accountFollowing',
-            required: true,
-            include: [ Account['sequelize'].models.Pod ]
-          }
-        ]
-      }
-    ]
-  }
-
-  return Account.findAndCountAll(query).then(({ rows, count }) => {
-    return {
-      data: rows,
-      total: count
-    }
-  })
-}
-
-listFollowersForApi = function (id: number, start: number, count: number, sort: string) {
-  const query = {
-    distinct: true,
-    offset: start,
-    limit: count,
-    order: [ getSort(sort) ],
-    include: [
-      {
-        model: Account['sequelize'].models.AccountFollow,
-        required: true,
-        as: 'followers',
-        include: [
-          {
-            model: Account['sequelize'].models.Account,
-            as: 'accountFollowers',
-            required: true,
-            include: [ Account['sequelize'].models.Pod ]
-          }
-        ]
-      }
-    ]
-  }
-
-  return Account.findAndCountAll(query).then(({ rows, count }) => {
-    return {
-      data: rows,
-      total: count
-    }
-  })
-}
-
 loadApplication = function () {
   return Account.findOne({
     include: [
@@ -527,45 +451,3 @@ loadAccountByPodAndUUID = function (uuid: string, podId: number, transaction: Se
 
   return Account.find(query)
 }
-
-// ------------------------------ UTILS ------------------------------
-
-async function createListAcceptedFollowForApiQuery (type: 'followers' | 'following', id: number, start: number, count?: number) {
-  let firstJoin: string
-  let secondJoin: string
-
-  if (type === 'followers') {
-    firstJoin = 'targetAccountId'
-    secondJoin = 'accountId'
-  } else {
-    firstJoin = 'accountId'
-    secondJoin = 'targetAccountId'
-  }
-
-  const selections = [ '"Followers"."url" AS "url"', 'COUNT(*) AS "total"' ]
-  const tasks: Promise<any>[] = []
-
-  for (const selection of selections) {
-    let query = 'SELECT ' + selection + ' FROM "Account" ' +
-      'INNER JOIN "AccountFollow" ON "AccountFollow"."' + firstJoin + '" = "Account"."id" ' +
-      'INNER JOIN "Account" AS "Follows" ON "Followers"."id" = "Follows"."' + secondJoin + '" ' +
-      'WHERE "Account"."id" = $id AND "AccountFollow"."state" = \'accepted\' ' +
-      'LIMIT ' + start
-
-    if (count !== undefined) query += ', ' + count
-
-    const options = {
-      bind: { id },
-      type: Sequelize.QueryTypes.SELECT
-    }
-    tasks.push(Account['sequelize'].query(query, options))
-  }
-
-  const [ followers, [ { total } ]] = await Promise.all(tasks)
-  const urls: string[] = followers.map(f => f.url)
-
-  return {
-    data: urls,
-    total: parseInt(total, 10)
-  }
-}
index 9d5ebbb168e867f1b441920400bc8b38e41d7aab..ecad69d6f6c8ae8c943234d2c589d3b2acbda9f5 100644 (file)
@@ -1,9 +1,9 @@
 export enum UserRight {
   ALL,
   MANAGE_USERS,
-  MANAGE_PEERTUBE_FOLLOW,
+  MANAGE_APPLICATION_FOLLOW,
   MANAGE_VIDEO_ABUSES,
   MANAGE_VIDEO_BLACKLIST,
   REMOVE_ANY_VIDEO,
-  REMOVE_ANY_VIDEO_CHANNEL,
+  REMOVE_ANY_VIDEO_CHANNEL
 }