]>
Commit | Line | Data |
---|---|---|
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' | |
6 | ||
7 | function 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 | ||
34 | export { | |
35 | listUserChannelsForSelect | |
36 | } | |
37 | ||
38 | // --------------------------------------------------------------------------- | |
39 | ||
40 | function getAvatarPath (c: VideoChannel) { | |
41 | if (!c.avatars || c.avatars.length === 0) return undefined | |
42 | ||
43 | return minBy(c.avatars, 'width').path | |
44 | } |