Migrate to new useLiveNowConfig
This commit is contained in:
@@ -2,9 +2,6 @@ import {createContext, useContext, useMemo} from 'react'
|
||||
|
||||
import {useLanguagePrefs} from '#/state/preferences/languages'
|
||||
import {useServiceConfigQuery} from '#/state/queries/service-config'
|
||||
import {useSession} from '#/state/session'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {IS_DEV} from '#/env'
|
||||
import {device} from '#/storage'
|
||||
|
||||
type TrendingContext = {
|
||||
@@ -81,55 +78,6 @@ export function useTrendingConfig() {
|
||||
return useContext(TrendingContext)
|
||||
}
|
||||
|
||||
const DEFAULT_LIVE_ALLOWED_DOMAINS = [
|
||||
'twitch.tv',
|
||||
'www.twitch.tv',
|
||||
'stream.place',
|
||||
'bluecast.app',
|
||||
'www.bluecast.app',
|
||||
]
|
||||
export type LiveNowConfig = {
|
||||
currentAccountAllowedHosts: Set<string>
|
||||
defaultAllowedHosts: Set<string>
|
||||
allowedHostsExceptionsByDid: Map<string, Set<string>>
|
||||
}
|
||||
export function useLiveNowConfig(): LiveNowConfig {
|
||||
const ctx = useContext(LiveNowContext)
|
||||
const canGoLive = useCanGoLive()
|
||||
const {currentAccount} = useSession()
|
||||
return useMemo(() => {
|
||||
const defaultAllowedHosts = new Set(DEFAULT_LIVE_ALLOWED_DOMAINS)
|
||||
const allowedHostsExceptionsByDid = new Map<string, Set<string>>()
|
||||
for (const live of ctx) {
|
||||
allowedHostsExceptionsByDid.set(
|
||||
live.did,
|
||||
new Set(DEFAULT_LIVE_ALLOWED_DOMAINS.concat(live.domains)),
|
||||
)
|
||||
}
|
||||
if (!currentAccount?.did || !canGoLive)
|
||||
return {
|
||||
currentAccountAllowedHosts: new Set(),
|
||||
defaultAllowedHosts,
|
||||
allowedHostsExceptionsByDid,
|
||||
}
|
||||
const vip = ctx.find(live => live.did === currentAccount.did)
|
||||
return {
|
||||
currentAccountAllowedHosts: new Set(
|
||||
DEFAULT_LIVE_ALLOWED_DOMAINS.concat(vip ? vip.domains : []),
|
||||
),
|
||||
defaultAllowedHosts,
|
||||
allowedHostsExceptionsByDid,
|
||||
}
|
||||
}, [ctx, currentAccount, canGoLive])
|
||||
}
|
||||
|
||||
export function useCanGoLive() {
|
||||
const ax = useAnalytics()
|
||||
const {hasSession} = useSession()
|
||||
if (!hasSession) return false
|
||||
return IS_DEV ? true : !ax.features.enabled(ax.features.LiveNowBetaDisable)
|
||||
}
|
||||
|
||||
export function useCheckEmailConfirmed() {
|
||||
const ctx = useContext(CheckEmailConfirmedContext)
|
||||
if (ctx === null) {
|
||||
|
||||
Reference in New Issue
Block a user