PeerTube/client/src/app/helpers/utils/channel.ts

45 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-03-27 14:00:40 +01:00
import { minBy } from '@peertube/peertube-core-utils'
import { VideoChannel } from '@peertube/peertube-models'
import { first, map } from 'rxjs/operators'
import { SelectChannelItem } from 'src/types/select-options-item.model'
import { AuthService } from '../../core/auth'
function listUserChannelsForSelect (authService: AuthService) {
return authService.userInformationLoaded
.pipe(
first(),
map(() => {
const user = authService.getUser()
if (!user) return undefined
const videoChannels = user.videoChannels
if (Array.isArray(videoChannels) === false) return undefined
return videoChannels
.sort((a, b) => {
if (a.updatedAt < b.updatedAt) return 1
if (a.updatedAt > b.updatedAt) return -1
return 0
})
.map(c => ({
id: c.id,
label: c.displayName,
support: c.support,
2022-03-02 15:47:04 +01:00
avatarPath: getAvatarPath(c)
}) as SelectChannelItem)
})
)
}
export {
listUserChannelsForSelect
}
2022-03-02 15:47:04 +01:00
// ---------------------------------------------------------------------------
function getAvatarPath (c: VideoChannel) {
if (!c.avatars || c.avatars.length === 0) return undefined
2024-02-16 10:24:02 +01:00
return minBy(c.avatars, 'width')?.path || c.avatars[0].path
2022-03-02 15:47:04 +01:00
}