]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/helpers/utils/channel.ts
Continue user mute in ban modal PR
[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'
4import { AuthService } from '../../core/auth'
5
d0800f76 6function listUserChannelsForSelect (authService: AuthService) {
dd24f1bb
C
7 return authService.userInformationLoaded
8 .pipe(
9 first(),
10 map(() => {
11 const user = authService.getUser()
12 if (!user) return undefined
13
14 const videoChannels = user.videoChannels
15 if (Array.isArray(videoChannels) === false) return undefined
16
17 return videoChannels
18 .sort((a, b) => {
19 if (a.updatedAt < b.updatedAt) return 1
20 if (a.updatedAt > b.updatedAt) return -1
21 return 0
22 })
23 .map(c => ({
24 id: c.id,
25 label: c.displayName,
26 support: c.support,
d0800f76 27 avatarPath: minBy(c.avatars, 'width')[0]?.path
dd24f1bb
C
28 }) as SelectChannelItem)
29 })
30 )
31}
32
33export {
d0800f76 34 listUserChannelsForSelect
dd24f1bb 35}