]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Sort channels by -updatedAt
authorChocobozzz <me@florianbigard.com>
Mon, 10 May 2021 07:31:33 +0000 (09:31 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 10 May 2021 07:38:11 +0000 (09:38 +0200)
client/src/app/+accounts/account-video-channels/account-video-channels.component.ts
client/src/app/+accounts/accounts.component.ts
client/src/app/+my-library/+my-video-channels/my-video-channels.component.ts
client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.html
client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.ts
client/src/app/+videos/+video-edit/video-update.resolver.ts
client/src/app/helpers/utils.ts
client/src/app/shared/shared-main/account/account.model.ts
client/src/app/shared/shared-main/account/actor.model.ts
client/src/app/shared/shared-main/video-channel/video-channel.model.ts
client/src/app/shared/shared-main/video-channel/video-channel.service.ts

index 0628c7a9633d0d9137a4aa43f80f5f02829ed812..7e916e12284c4fdf2799c05c9de716fabc3aa73c 100644 (file)
@@ -79,7 +79,13 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
   }
 
   loadMoreChannels () {
-    this.videoChannelService.listAccountVideoChannels(this.account, this.channelPagination)
+    const options = {
+      account: this.account,
+      componentPagination: this.channelPagination,
+      sort: '-updatedAt'
+    }
+
+    this.videoChannelService.listAccountVideoChannels(options)
       .pipe(
         tap(res => this.channelPagination.totalItems = res.total),
         switchMap(res => from(res.data)),
index fbd7380a9cf87e3db594e3dc80b10da7c0ee6d99..c69b04a01bd301ce27419e43e6aded4c12535bb0 100644 (file)
@@ -66,7 +66,7 @@ export class AccountsComponent implements OnInit, OnDestroy {
                           distinctUntilChanged(),
                           switchMap(accountId => this.accountService.getAccount(accountId)),
                           tap(account => this.onAccount(account)),
-                          switchMap(account => this.videoChannelService.listAccountVideoChannels(account)),
+                          switchMap(account => this.videoChannelService.listAccountVideoChannels({ account })),
                           catchError(err => this.restExtractor.redirectTo404IfNotFound(err, 'other', [
                             HttpStatusCode.BAD_REQUEST_400,
                             HttpStatusCode.NOT_FOUND_404
index 9e3bf35b4e3ba611e12464af3eebf06c83006006..67b3ee496a34d6b9164a053913c2628bc9a819f6 100644 (file)
@@ -68,8 +68,14 @@ channel with the same name (${videoChannel.name})!`,
     this.authService.userInformationLoaded
         .pipe(mergeMap(() => {
           const user = this.authService.getUser()
+          const options = {
+            account: user.account,
+            withStats: true,
+            search: this.search,
+            sort: '-updatedAt'
+          }
 
-          return this.videoChannelService.listAccountVideoChannels(user.account, null, true, this.search)
+          return this.videoChannelService.listAccountVideoChannels(options)
         })).subscribe(res => {
           this.videoChannels = res.data
           this.totalItems = res.total
index 088765b20b4e49813333fc96f05ddcaecfb2ee60..d0393a2a4f08d5799edb160d30e1857fa88eb269 100644 (file)
@@ -8,13 +8,8 @@
   <div class="modal-body" [formGroup]="form">
     <div class="form-group">
       <label i18n for="channel">Select a channel to receive the video</label>
-      <div class="peertube-select-container">
-        <select formControlName="channel" id="channel" class="form-control">
-          <option i18n value="undefined" disabled>Channel that will receive the video</option>
-          <option *ngFor="let channel of videoChannels" [value]="channel.id">{{ channel.displayName }}
-          </option>
-        </select>
-      </div>
+      <my-select-channel labelForId="channel" formControlName="channel" [items]="videoChannels"></my-select-channel>
+
       <div *ngIf="formErrors.channel" class="form-error">{{ formErrors.channel }}</div>
     </div>
   </div>
index 0e23957545b9edda60418fb7dab5a91077cd7423..7889d0985177eaa60076894a788f06bd30c83c9f 100644 (file)
@@ -1,11 +1,12 @@
-import { switchMap } from 'rxjs/operators'
+import { SelectChannelItem } from 'src/types/select-options-item.model'
 import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
 import { AuthService, Notifier } from '@app/core'
+import { listUserChannels } from '@app/helpers'
 import { OWNERSHIP_CHANGE_CHANNEL_VALIDATOR } from '@app/shared/form-validators/video-ownership-change-validators'
 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
-import { VideoChannelService, VideoOwnershipService } from '@app/shared/shared-main'
+import { VideoOwnershipService } from '@app/shared/shared-main'
 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
-import { VideoChangeOwnership, VideoChannel } from '@shared/models'
+import { VideoChangeOwnership } from '@shared/models'
 
 @Component({
   selector: 'my-accept-ownership',
@@ -18,8 +19,7 @@ export class MyAcceptOwnershipComponent extends FormReactive implements OnInit {
   @ViewChild('modal', { static: true }) modal: ElementRef
 
   videoChangeOwnership: VideoChangeOwnership | undefined = undefined
-
-  videoChannels: VideoChannel[]
+  videoChannels: SelectChannelItem[]
 
   error: string = null
 
@@ -28,7 +28,6 @@ export class MyAcceptOwnershipComponent extends FormReactive implements OnInit {
     private videoOwnershipService: VideoOwnershipService,
     private notifier: Notifier,
     private authService: AuthService,
-    private videoChannelService: VideoChannelService,
     private modalService: NgbModal
     ) {
     super()
@@ -37,9 +36,8 @@ export class MyAcceptOwnershipComponent extends FormReactive implements OnInit {
   ngOnInit () {
     this.videoChannels = []
 
-    this.authService.userInformationLoaded
-      .pipe(switchMap(() => this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account)))
-      .subscribe(videoChannels => this.videoChannels = videoChannels.data)
+    listUserChannels(this.authService)
+      .subscribe(channels => this.videoChannels = channels)
 
     this.buildForm({
       channel: OWNERSHIP_CHANGE_CHANNEL_VALIDATOR
index 276548b797a18cd202d6c7673e7d6520e30652b6..9172b78a88154a890b5711bb7de6cc0a4baf4b2f 100644 (file)
@@ -2,7 +2,9 @@ import { forkJoin, of } from 'rxjs'
 import { map, switchMap } from 'rxjs/operators'
 import { Injectable } from '@angular/core'
 import { ActivatedRouteSnapshot, Resolve } from '@angular/router'
-import { VideoCaptionService, VideoChannelService, VideoDetails, VideoService } from '@app/shared/shared-main'
+import { AuthService } from '@app/core'
+import { listUserChannels } from '@app/helpers'
+import { VideoCaptionService, VideoDetails, VideoService } from '@app/shared/shared-main'
 import { LiveVideoService } from '@app/shared/shared-video-live'
 
 @Injectable()
@@ -10,7 +12,7 @@ export class VideoUpdateResolver implements Resolve<any> {
   constructor (
     private videoService: VideoService,
     private liveVideoService: LiveVideoService,
-    private videoChannelService: VideoChannelService,
+    private authService: AuthService,
     private videoCaptionService: VideoCaptionService
   ) {
   }
@@ -31,17 +33,7 @@ export class VideoUpdateResolver implements Resolve<any> {
         .loadCompleteDescription(video.descriptionPath)
         .pipe(map(description => Object.assign(video, { description }))),
 
-      this.videoChannelService
-        .listAccountVideoChannels(video.account)
-        .pipe(
-          map(result => result.data),
-          map(videoChannels => videoChannels.map(c => ({
-            id: c.id,
-            label: c.displayName,
-            support: c.support,
-            avatarPath: c.avatar?.path
-          })))
-        ),
+      listUserChannels(this.authService),
 
       this.videoCaptionService
         .listCaptions(video.id)
index a1747af3cae1f17db516a00537b3ebfb1bbf80b7..17eb5effc1fbb50be730bc7d5782ab86a60cb1b2 100644 (file)
@@ -30,12 +30,18 @@ function listUserChannels (authService: AuthService) {
       const videoChannels = user.videoChannels
       if (Array.isArray(videoChannels) === false) return undefined
 
-      return videoChannels.map(c => ({
-        id: c.id,
-        label: c.displayName,
-        support: c.support,
-        avatarPath: c.avatar?.path
-      }) as SelectChannelItem)
+      return videoChannels
+        .sort((a, b) => {
+          if (a.updatedAt < b.updatedAt) return 1
+          if (a.updatedAt > b.updatedAt) return -1
+          return 0
+        })
+        .map(c => ({
+          id: c.id,
+          label: c.displayName,
+          support: c.support,
+          avatarPath: c.avatar?.path
+        }) as SelectChannelItem)
     }))
 }
 
index 6d9f0ee655eac7dc95b76849e5c73ebeb064d77d..7b5611f35a21e47654b880bcfd6a2bef1934209a 100644 (file)
@@ -4,8 +4,12 @@ import { Actor } from './actor.model'
 export class Account extends Actor implements ServerAccount {
   displayName: string
   description: string
+
+  updatedAt: Date | string
+
   nameWithHost: string
   nameWithHostForced: string
+
   mutedByUser: boolean
   mutedByInstance: boolean
   mutedServerByUser: boolean
@@ -30,6 +34,8 @@ export class Account extends Actor implements ServerAccount {
     this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
     this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
 
+    if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
+
     this.mutedByUser = false
     this.mutedByInstance = false
     this.mutedServerByUser = false
index 6ba0bb09ed7b741c18afc8df7ff437074100f4d7..2fccc472a64fe4e87bedf9ba14200f61c89005b3 100644 (file)
@@ -12,7 +12,6 @@ export abstract class Actor implements ServerActor {
   followersCount: number
 
   createdAt: Date | string
-  updatedAt: Date | string
 
   avatar: ActorImage
 
@@ -55,7 +54,6 @@ export abstract class Actor implements ServerActor {
     this.followersCount = hash.followersCount
 
     if (hash.createdAt) this.createdAt = new Date(hash.createdAt.toString())
-    if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
 
     this.avatar = hash.avatar
     this.isLocal = Actor.IS_LOCAL(this.host)
index c40dd53119e1278bf8f008bf15d772d0ddb9a8ec..a9dcf2fa29c352430d71f9aadf9de7771c73cc57 100644 (file)
@@ -16,6 +16,8 @@ export class VideoChannel extends Actor implements ServerVideoChannel {
   banner: ActorImage
   bannerUrl: string
 
+  updatedAt: Date | string
+
   ownerAccount?: ServerAccount
   ownerBy?: string
 
@@ -59,6 +61,8 @@ export class VideoChannel extends Actor implements ServerVideoChannel {
 
     this.videosCount = hash.videosCount
 
+    if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
+
     if (hash.viewsPerDay) {
       this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
     }
index e6526176313083d9188b8eca3fc89c689d0eb73c..a89f1065adbe8a06ad0e6545d023d6b7866a6b1e 100644 (file)
@@ -40,23 +40,24 @@ export class VideoChannelService {
                )
   }
 
-  listAccountVideoChannels (
-    account: Account,
-    componentPagination?: ComponentPaginationLight,
-    withStats = false,
+  listAccountVideoChannels (options: {
+    account: Account
+    componentPagination?: ComponentPaginationLight
+    withStats?: boolean
+    sort?: string
     search?: string
-  ): Observable<ResultList<VideoChannel>> {
+  }): Observable<ResultList<VideoChannel>> {
+    const { account, componentPagination, withStats = false, sort, search } = options
+
     const pagination = componentPagination
       ? this.restService.componentPaginationToRestPagination(componentPagination)
       : { start: 0, count: 20 }
 
     let params = new HttpParams()
-    params = this.restService.addRestGetParams(params, pagination)
+    params = this.restService.addRestGetParams(params, pagination, sort)
     params = params.set('withStats', withStats + '')
 
-    if (search) {
-      params = params.set('search', search)
-    }
+    if (search) params = params.set('search', search)
 
     const url = AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/video-channels'
     return this.authHttp.get<ResultList<VideoChannelServer>>(url, { params })