1 import { minBy } from 'lodash-es'
2 import { first, map } from 'rxjs/operators'
3 import { SelectChannelItem } from 'src/types/select-options-item.model'
4 import { VideoChannel } from '@shared/models'
5 import { AuthService } from '../../core/auth'
7 function listUserChannelsForSelect (authService: AuthService) {
8 return authService.userInformationLoaded
12 const user = authService.getUser()
13 if (!user) return undefined
15 const videoChannels = user.videoChannels
16 if (Array.isArray(videoChannels) === false) return undefined
20 if (a.updatedAt < b.updatedAt) return 1
21 if (a.updatedAt > b.updatedAt) return -1
28 avatarPath: getAvatarPath(c)
29 }) as SelectChannelItem)
35 listUserChannelsForSelect
38 // ---------------------------------------------------------------------------
40 function getAvatarPath (c: VideoChannel) {
41 if (!c.avatars || c.avatars.length === 0) return undefined
43 return minBy(c.avatars, 'width').path