Create logged-out view for group chat invites (#10598)
Co-authored-by: Samuel Newman <mozzius@protonmail.com>
This commit is contained in:
+28
-4
@@ -1,22 +1,45 @@
|
||||
import {useEffect, useState} from 'react'
|
||||
import * as Linking from 'expo-linking'
|
||||
|
||||
import {parseLinkingUrl} from '#/lib/parseLinkingUrl'
|
||||
import {
|
||||
createStarterPackLinkFromAndroidReferrer,
|
||||
httpStarterPackUriToAtUri,
|
||||
} from '#/lib/strings/starter-pack'
|
||||
import {CHAT_INVITE_CODE_REGEX} from '#/lib/strings/url-helpers'
|
||||
import {useHasCheckedForStarterPack} from '#/state/preferences/used-starter-packs'
|
||||
import {useSetActiveStarterPack} from '#/state/shell/starter-pack'
|
||||
import {
|
||||
useSetActiveLanding,
|
||||
useSetActiveStarterPack,
|
||||
} from '#/state/shell/landing'
|
||||
import {IS_ANDROID} from '#/env'
|
||||
import {Referrer, SharedPrefs} from '../../../modules/expo-bluesky-swiss-army'
|
||||
|
||||
export function useStarterPackEntry() {
|
||||
export function useLandingEntry() {
|
||||
const [ready, setReady] = useState(false)
|
||||
const setActiveStarterPack = useSetActiveStarterPack()
|
||||
const setActiveLanding = useSetActiveLanding()
|
||||
const hasCheckedForStarterPack = useHasCheckedForStarterPack()
|
||||
|
||||
useEffect(() => {
|
||||
if (ready) return
|
||||
|
||||
// Check for group chat invite link from the initial deep link URL
|
||||
const linkingUrl = Linking.getLinkingURL()
|
||||
if (linkingUrl) {
|
||||
const urlp = parseLinkingUrl(linkingUrl)
|
||||
const chatInviteMatch = urlp.pathname.match(CHAT_INVITE_CODE_REGEX)
|
||||
if (chatInviteMatch) {
|
||||
setActiveLanding({
|
||||
type: 'groupchat',
|
||||
uri: linkingUrl,
|
||||
code: chatInviteMatch[1],
|
||||
})
|
||||
setReady(true)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// On Android, we cannot clear the referral link. It gets stored for 90 days and all we can do is query for it. So,
|
||||
// let's just ensure we never check again after the first time.
|
||||
if (hasCheckedForStarterPack) {
|
||||
@@ -29,7 +52,8 @@ export function useStarterPackEntry() {
|
||||
setReady(true)
|
||||
}, 500)
|
||||
|
||||
;(async () => {
|
||||
void (async () => {
|
||||
// Check for starter pack
|
||||
let uri: string | null | undefined
|
||||
|
||||
if (IS_ANDROID) {
|
||||
@@ -58,7 +82,7 @@ export function useStarterPackEntry() {
|
||||
return () => {
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
}, [ready, setActiveStarterPack, hasCheckedForStarterPack])
|
||||
}, [ready, setActiveStarterPack, setActiveLanding, hasCheckedForStarterPack])
|
||||
|
||||
return ready
|
||||
}
|
||||
+7
-5
@@ -1,25 +1,27 @@
|
||||
import {useEffect, useState} from 'react'
|
||||
|
||||
import {httpStarterPackUriToAtUri} from '#/lib/strings/starter-pack'
|
||||
import {useSetActiveStarterPack} from '#/state/shell/starter-pack'
|
||||
import {useSetActiveStarterPack} from '#/state/shell/landing'
|
||||
|
||||
export function useStarterPackEntry() {
|
||||
export function useLandingEntry() {
|
||||
const [ready, setReady] = useState(false)
|
||||
|
||||
const setActiveStarterPack = useSetActiveStarterPack()
|
||||
|
||||
useEffect(() => {
|
||||
const href = window.location.href
|
||||
const atUri = httpStarterPackUriToAtUri(href)
|
||||
const url = new URL(href)
|
||||
|
||||
// Check for starter pack
|
||||
const atUri = httpStarterPackUriToAtUri(href)
|
||||
if (atUri) {
|
||||
const url = new URL(href)
|
||||
// Determines if an App Clip is loading this landing page
|
||||
const isClip = url.searchParams.get('clip') === 'true'
|
||||
setActiveStarterPack({
|
||||
uri: atUri,
|
||||
isClip,
|
||||
})
|
||||
setReady(true)
|
||||
return
|
||||
}
|
||||
|
||||
setReady(true)
|
||||
Reference in New Issue
Block a user