Bluesky app fork with some witchin' additions 💫

[APP-1784] Proper fix for Live Now status not showing (#9779)

* Be sure to validate if actor is allowed to be live on certain domain

* Rename for clarity

* Memoize

authored by

Eric Bailey and committed by
GitHub
39e7132f 26605ee7

+37 -20
+1 -1
src/components/live/GoLiveDialog.tsx
··· 55 55 const tick = useTickEveryMinute() 56 56 const liveNowConfig = useLiveNowConfig() 57 57 const {formatted: allowedServices} = getLiveServiceNames( 58 - liveNowConfig.allowedDomains, 58 + liveNowConfig.currentAccountAllowedHosts, 59 59 ) 60 60 61 61 const time = useCallback(
+4 -2
src/components/live/queries.ts
··· 31 31 queryFn: async () => { 32 32 if (!url) return undefined 33 33 const urlp = new URL(url) 34 - if (!liveNowConfig.allowedDomains.has(urlp.hostname)) { 35 - const {formatted} = getLiveServiceNames(liveNowConfig.allowedDomains) 34 + if (!liveNowConfig.currentAccountAllowedHosts.has(urlp.hostname)) { 35 + const {formatted} = getLiveServiceNames( 36 + liveNowConfig.currentAccountAllowedHosts, 37 + ) 36 38 throw new Error( 37 39 _( 38 40 msg`This service is not supported while the Live feature is in beta. Allowed services: ${formatted}.`,
+7 -1
src/lib/actor-status.ts
··· 3 3 type $Typed, 4 4 type AppBskyActorDefs, 5 5 AppBskyEmbedExternal, 6 + AtUri, 6 7 } from '@atproto/api' 7 8 import {isAfter, parseISO} from 'date-fns' 8 9 ··· 73 74 config: LiveNowConfig, 74 75 ) { 75 76 if (status.status !== 'app.bsky.actor.status#live') return false 77 + if (!status.uri) return false // should not happen, just backwards compat 76 78 try { 79 + const {host: liveDid} = new AtUri(status.uri) 77 80 if (AppBskyEmbedExternal.isView(status.embed)) { 78 81 const url = new URL(status.embed.external.uri) 79 - return config.allSupportedDomains.has(url.hostname) 82 + const exception = config.allowedHostsExceptionsByDid.get(liveDid) 83 + const isValidException = exception ? exception.has(url.hostname) : false 84 + const isValidForAnyone = config.defaultAllowedHosts.has(url.hostname) 85 + return isValidException || isValidForAnyone 80 86 } else { 81 87 return false 82 88 }
+25 -16
src/state/service-config.tsx
··· 89 89 'www.bluecast.app', 90 90 ] 91 91 export type LiveNowConfig = { 92 - allowedDomains: Set<string> 93 - allSupportedDomains: Set<string> 92 + currentAccountAllowedHosts: Set<string> 93 + defaultAllowedHosts: Set<string> 94 + allowedHostsExceptionsByDid: Map<string, Set<string>> 94 95 } 95 96 export function useLiveNowConfig(): LiveNowConfig { 96 97 const ctx = useContext(LiveNowContext) 97 98 const canGoLive = useCanGoLive() 98 99 const {currentAccount} = useSession() 99 - const allVipDomains = new Set(ctx.flatMap(live => live.domains)) 100 - const allSupportedDomains = new Set( 101 - DEFAULT_LIVE_ALLOWED_DOMAINS.concat(Array.from(allVipDomains)), 102 - ) 103 - if (!currentAccount?.did || !canGoLive) 100 + return useMemo(() => { 101 + const defaultAllowedHosts = new Set(DEFAULT_LIVE_ALLOWED_DOMAINS) 102 + const allowedHostsExceptionsByDid = new Map<string, Set<string>>() 103 + for (const live of ctx) { 104 + allowedHostsExceptionsByDid.set( 105 + live.did, 106 + new Set(DEFAULT_LIVE_ALLOWED_DOMAINS.concat(live.domains)), 107 + ) 108 + } 109 + if (!currentAccount?.did || !canGoLive) 110 + return { 111 + currentAccountAllowedHosts: new Set(), 112 + defaultAllowedHosts, 113 + allowedHostsExceptionsByDid, 114 + } 115 + const vip = ctx.find(live => live.did === currentAccount.did) 104 116 return { 105 - allowedDomains: new Set(), 106 - allSupportedDomains, 117 + currentAccountAllowedHosts: new Set( 118 + DEFAULT_LIVE_ALLOWED_DOMAINS.concat(vip ? vip.domains : []), 119 + ), 120 + defaultAllowedHosts, 121 + allowedHostsExceptionsByDid, 107 122 } 108 - const vip = ctx.find(live => live.did === currentAccount.did) 109 - return { 110 - allowedDomains: new Set( 111 - DEFAULT_LIVE_ALLOWED_DOMAINS.concat(vip ? vip.domains : []), 112 - ), 113 - allSupportedDomains, 114 - } 123 + }, [ctx, currentAccount, canGoLive]) 115 124 } 116 125 117 126 export function useCanGoLive() {