]>
Commit | Line | Data |
---|---|---|
d0800f76 | 1 | import { minBy } from 'lodash-es' |
dd24f1bb C |
2 | import { first, map } from 'rxjs/operators' |
3 | import { SelectChannelItem } from 'src/types/select-options-item.model' | |
4 | import { AuthService } from '../../core/auth' | |
5 | ||
d0800f76 | 6 | function 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 | ||
33 | export { | |
d0800f76 | 34 | listUserChannelsForSelect |
dd24f1bb | 35 | } |