]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - 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
1import { minBy } from 'lodash-es'
2import { first, map } from 'rxjs/operators'
3import { SelectChannelItem } from 'src/types/select-options-item.model'
4import { VideoChannel } from '@shared/models'
5import { AuthService } from '../../core/auth'
6
7function listUserChannelsForSelect (authService: AuthService) {
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,
28 avatarPath: getAvatarPath(c)
29 }) as SelectChannelItem)
30 })
31 )
32}
33
34export {
35 listUserChannelsForSelect
36}
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}