]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - 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
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 { AuthService } from '../../core/auth'
5
6 function listUserChannelsForSelect (authService: AuthService) {
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,
27 avatarPath: minBy(c.avatars, 'width')[0]?.path
28 }) as SelectChannelItem)
29 })
30 )
31 }
32
33 export {
34 listUserChannelsForSelect
35 }