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