Fix Live Now not showing for non-streamer (#9773)
* Fix Live Now not showing for non-streamer * Rename for clarity * Logged out users too
This commit is contained in:
@@ -20,7 +20,7 @@ export function useActorStatus(actor?: bsky.profile.AnyProfileView) {
|
||||
void tick // revalidate every minute
|
||||
|
||||
if (shadowed && 'status' in shadowed && shadowed.status) {
|
||||
const isValid = validateStatus(shadowed.status, config)
|
||||
const isValid = isStatusValidForViewers(shadowed.status, config)
|
||||
const isDisabled = shadowed.status.isDisabled || false
|
||||
const isActive = isStatusStillActive(shadowed.status.expiresAt)
|
||||
if (isValid && !isDisabled && isActive) {
|
||||
@@ -64,7 +64,11 @@ export function isStatusStillActive(timeStr: string | undefined) {
|
||||
return isAfter(expiry, now)
|
||||
}
|
||||
|
||||
export function validateStatus(
|
||||
/**
|
||||
* Validates whether the live status is valid for display in the app. Does NOT
|
||||
* validate if the status is valid for the acting user e.g. as they go live.
|
||||
*/
|
||||
export function isStatusValidForViewers(
|
||||
status: AppBskyActorDefs.StatusView,
|
||||
config: LiveNowConfig,
|
||||
) {
|
||||
@@ -72,7 +76,7 @@ export function validateStatus(
|
||||
try {
|
||||
if (AppBskyEmbedExternal.isView(status.embed)) {
|
||||
const url = new URL(status.embed.external.uri)
|
||||
return config.allowedDomains.has(url.hostname)
|
||||
return config.allSupportedDomains.has(url.hostname)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -90,17 +90,27 @@ const DEFAULT_LIVE_ALLOWED_DOMAINS = [
|
||||
]
|
||||
export type LiveNowConfig = {
|
||||
allowedDomains: Set<string>
|
||||
allSupportedDomains: Set<string>
|
||||
}
|
||||
export function useLiveNowConfig(): LiveNowConfig {
|
||||
const ctx = useContext(LiveNowContext)
|
||||
const canGoLive = useCanGoLive()
|
||||
const {currentAccount} = useSession()
|
||||
if (!currentAccount?.did || !canGoLive) return {allowedDomains: new Set()}
|
||||
const allVipDomains = new Set(ctx.flatMap(live => live.domains))
|
||||
const allSupportedDomains = new Set(
|
||||
DEFAULT_LIVE_ALLOWED_DOMAINS.concat(Array.from(allVipDomains)),
|
||||
)
|
||||
if (!currentAccount?.did || !canGoLive)
|
||||
return {
|
||||
allowedDomains: new Set(),
|
||||
allSupportedDomains,
|
||||
}
|
||||
const vip = ctx.find(live => live.did === currentAccount.did)
|
||||
return {
|
||||
allowedDomains: new Set(
|
||||
DEFAULT_LIVE_ALLOWED_DOMAINS.concat(vip ? vip.domains : []),
|
||||
),
|
||||
allSupportedDomains,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import {msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {isStatusStillActive, validateStatus} from '#/lib/actor-status'
|
||||
import {isStatusStillActive, isStatusValidForViewers} from '#/lib/actor-status'
|
||||
import {DISCOVER_FEED_URI, KNOWN_SHUTDOWN_FEEDS} from '#/lib/constants'
|
||||
import {useInitialNumToRender} from '#/lib/hooks/useInitialNumToRender'
|
||||
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
||||
@@ -948,7 +948,7 @@ let PostFeed = ({
|
||||
const actor = post.author
|
||||
if (
|
||||
actor.status &&
|
||||
validateStatus(actor.status, liveNowConfig) &&
|
||||
isStatusValidForViewers(actor.status, liveNowConfig) &&
|
||||
isStatusStillActive(actor.status.expiresAt)
|
||||
) {
|
||||
if (!seenActorWithStatusRef.current.has(actor.did)) {
|
||||
|
||||
Reference in New Issue
Block a user