aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/helpers/utils/channel.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/helpers/utils/channel.ts')
-rw-r--r--client/src/app/helpers/utils/channel.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/client/src/app/helpers/utils/channel.ts b/client/src/app/helpers/utils/channel.ts
new file mode 100644
index 000000000..93863a8af
--- /dev/null
+++ b/client/src/app/helpers/utils/channel.ts
@@ -0,0 +1,34 @@
1import { first, map } from 'rxjs/operators'
2import { SelectChannelItem } from 'src/types/select-options-item.model'
3import { AuthService } from '../../core/auth'
4
5function listUserChannels (authService: AuthService) {
6 return authService.userInformationLoaded
7 .pipe(
8 first(),
9 map(() => {
10 const user = authService.getUser()
11 if (!user) return undefined
12
13 const videoChannels = user.videoChannels
14 if (Array.isArray(videoChannels) === false) return undefined
15
16 return videoChannels
17 .sort((a, b) => {
18 if (a.updatedAt < b.updatedAt) return 1
19 if (a.updatedAt > b.updatedAt) return -1
20 return 0
21 })
22 .map(c => ({
23 id: c.id,
24 label: c.displayName,
25 support: c.support,
26 avatarPath: c.avatar?.path
27 }) as SelectChannelItem)
28 })
29 )
30}
31
32export {
33 listUserChannels
34}