]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/helpers/utils/channel.ts
Added filter to sort videos by name (alphabetical order)
[github/Chocobozzz/PeerTube.git] / client / src / app / helpers / utils / channel.ts
CommitLineData
d0800f76 1import { minBy } from 'lodash-es'
dd24f1bb
C
2import { first, map } from 'rxjs/operators'
3import { SelectChannelItem } from 'src/types/select-options-item.model'
77f811ce 4import { VideoChannel } from '@shared/models'
dd24f1bb
C
5import { AuthService } from '../../core/auth'
6
d0800f76 7function listUserChannelsForSelect (authService: AuthService) {
dd24f1bb
C
8 return authService.userInformationLoaded
9 .pipe(
10 first(),
11 map(() => {
12 const user = authService.getUser()
13 if (!user) return undefined
14
15 const videoChannels = user.videoChannels
16 if (Array.isArray(videoChannels) === false) return undefined
17
18 return videoChannels
19 .sort((a, b) => {
20 if (a.updatedAt < b.updatedAt) return 1
21 if (a.updatedAt > b.updatedAt) return -1
22 return 0
23 })
24 .map(c => ({
25 id: c.id,
26 label: c.displayName,
27 support: c.support,
77f811ce 28 avatarPath: getAvatarPath(c)
dd24f1bb
C
29 }) as SelectChannelItem)
30 })
31 )
32}
33
34export {
d0800f76 35 listUserChannelsForSelect
dd24f1bb 36}
77f811ce
C
37
38// ---------------------------------------------------------------------------
39
40function getAvatarPath (c: VideoChannel) {
41 if (!c.avatars || c.avatars.length === 0) return undefined
42
43 return minBy(c.avatars, 'width').path
44}