diff --git a/jest/jestSetup.js b/jest/jestSetup.js index 50a33589ea..4653490f3c 100644 --- a/jest/jestSetup.js +++ b/jest/jestSetup.js @@ -54,21 +54,6 @@ jest.mock('expo-image-manipulator', () => ({ SaveFormat: jest.requireActual('expo-image-manipulator').SaveFormat, })) -jest.mock('@segment/analytics-react-native', () => ({ - createClient: () => ({ - add: jest.fn(), - }), - useAnalytics: () => ({ - track: jest.fn(), - identify: jest.fn(), - reset: jest.fn(), - group: jest.fn(), - screen: jest.fn(), - alias: jest.fn(), - flush: jest.fn(), - }), -})) - jest.mock('expo-camera', () => ({ Camera: { useCameraPermissions: jest.fn(() => [true]), diff --git a/modules/Share-with-Bluesky/ShareViewController.swift b/modules/Share-with-Bluesky/ShareViewController.swift index 46851a0d79..2acbb6187b 100644 --- a/modules/Share-with-Bluesky/ShareViewController.swift +++ b/modules/Share-with-Bluesky/ShareViewController.swift @@ -1,5 +1,14 @@ import UIKit +let IMAGE_EXTENSIONS: [String] = ["png", "jpg", "jpeg", "gif", "heic"] +let MOVIE_EXTENSIONS: [String] = ["mov", "mp4", "m4v"] + +enum URLType: String, CaseIterable { + case image + case movie + case other +} + class ShareViewController: UIViewController { // This allows other forks to use this extension while also changing their // scheme. @@ -43,9 +52,18 @@ class ShareViewController: UIViewController { private func handleUrl(item: NSItemProvider) async { if let data = try? await item.loadItem(forTypeIdentifier: "public.url") as? URL { - if let encoded = data.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed), - let url = URL(string: "\(self.appScheme)://intent/compose?text=\(encoded)") { - _ = self.openURL(url) + switch data.type { + case .image: + await handleImages(items: [item]) + return + case .movie: + await handleVideos(items: [item]) + return + case .other: + if let encoded = data.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed), + let url = URL(string: "\(self.appScheme)://intent/compose?text=\(encoded)") { + _ = self.openURL(url) + } } } self.completeRequest() @@ -158,3 +176,21 @@ class ShareViewController: UIViewController { return false } } + +extension URL { + var type: URLType { + get { + guard self.absoluteString.starts(with: "file://"), + let ext = self.pathComponents.last?.split(separator: ".").last?.lowercased() else { + return .other + } + + if IMAGE_EXTENSIONS.contains(ext) { + return .image + } else if MOVIE_EXTENSIONS.contains(ext) { + return .movie + } + return .other + } + } +} diff --git a/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt b/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt index 7ecea16314..c88442057c 100644 --- a/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt +++ b/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt @@ -12,6 +12,11 @@ import java.io.File import java.io.FileOutputStream import java.net.URLEncoder +enum class AttachmentType { + IMAGE, + VIDEO, +} + class ExpoReceiveAndroidIntentsModule : Module() { override fun definition() = ModuleDefinition { @@ -23,17 +28,26 @@ class ExpoReceiveAndroidIntentsModule : Module() { } private fun handleIntent(intent: Intent?) { - if (appContext.currentActivity == null || intent == null) return - - if (intent.action == Intent.ACTION_SEND) { - if (intent.type == "text/plain") { - handleTextIntent(intent) - } else if (intent.type.toString().startsWith("image/")) { - handleImageIntent(intent) + if (appContext.currentActivity == null) return + intent?.let { + if (it.action == Intent.ACTION_SEND && it.type == "text/plain") { + handleTextIntent(it) + return } - } else if (intent.action == Intent.ACTION_SEND_MULTIPLE) { - if (intent.type.toString().startsWith("image/")) { - handleImagesIntent(intent) + + val type = + if (it.type.toString().startsWith("image/")) { + AttachmentType.IMAGE + } else if (it.type.toString().startsWith("video/")) { + AttachmentType.VIDEO + } else { + return + } + + if (it.action == Intent.ACTION_SEND) { + handleAttachmentIntent(it, type) + } else if (it.action == Intent.ACTION_SEND_MULTIPLE) { + handleAttachmentsIntent(it, type) } } } @@ -48,26 +62,46 @@ class ExpoReceiveAndroidIntentsModule : Module() { } } - private fun handleImageIntent(intent: Intent) { + private fun handleAttachmentIntent( + intent: Intent, + type: AttachmentType, + ) { val uri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri::class.java) } else { intent.getParcelableExtra(Intent.EXTRA_STREAM) } - if (uri == null) return - handleImageIntents(listOf(uri)) + uri?.let { + when (type) { + AttachmentType.IMAGE -> handleImageIntents(listOf(it)) + AttachmentType.VIDEO -> handleVideoIntents(listOf(it)) + } + } } - private fun handleImagesIntent(intent: Intent) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM, Uri::class.java)?.let { - handleImageIntents(it.filterIsInstance().take(4)) + private fun handleAttachmentsIntent( + intent: Intent, + type: AttachmentType, + ) { + val uris = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + intent + .getParcelableArrayListExtra(Intent.EXTRA_STREAM, Uri::class.java) + ?.filterIsInstance() + ?.take(4) + } else { + intent + .getParcelableArrayListExtra(Intent.EXTRA_STREAM) + ?.filterIsInstance() + ?.take(4) } - } else { - intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM)?.let { - handleImageIntents(it.filterIsInstance().take(4)) + + uris?.let { + when (type) { + AttachmentType.IMAGE -> handleImageIntents(it) + else -> return } } } @@ -93,11 +127,33 @@ class ExpoReceiveAndroidIntentsModule : Module() { } } + private fun handleVideoIntents(uris: List) { + val uri = uris[0] + // If there is no extension for the file, substringAfterLast returns the original string - not + // null, so we check for that below + // It doesn't actually matter what the extension is, so defaulting to mp4 is fine, even if the + // video isn't actually an mp4 + var extension = uri.path?.substringAfterLast(".") + if (extension == null || extension == uri.path) { + extension = "mp4" + } + val file = createFile(extension) + + val out = FileOutputStream(file) + appContext.currentActivity?.contentResolver?.openInputStream(uri)?.use { + it.copyTo(out) + } + "bluesky://intent/compose?videoUri=${URLEncoder.encode(file.path, "UTF-8")}".toUri().let { + val newIntent = Intent(Intent.ACTION_VIEW, it) + appContext.currentActivity?.startActivity(newIntent) + } + } + private fun getImageInfo(uri: Uri): Map { val bitmap = MediaStore.Images.Media.getBitmap(appContext.currentActivity?.contentResolver, uri) // We have to save this so that we can access it later when uploading the image. // createTempFile will automatically place a unique string between "img" and "temp.jpeg" - val file = File.createTempFile("img", "temp.jpeg", appContext.currentActivity?.cacheDir) + val file = createFile("jpeg") val out = FileOutputStream(file) bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out) out.flush() @@ -110,6 +166,8 @@ class ExpoReceiveAndroidIntentsModule : Module() { ) } + private fun createFile(extension: String): File = File.createTempFile(extension, "temp.$extension", appContext.currentActivity?.cacheDir) + // We will pas the width and height to the app here, since getting measurements // on the RN side is a bit more involved, and we already have them here anyway. private fun buildUriData(info: Map): String { diff --git a/package.json b/package.json index 5e4d896cce..4ab196b6aa 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "icons:optimize": "svgo -f ./assets/icons" }, "dependencies": { - "@atproto/api": "^0.13.7", + "@atproto/api": "^0.13.8", "@braintree/sanitize-url": "^6.0.2", "@discord/bottom-sheet": "bluesky-social/react-native-bottom-sheet", "@emoji-mart/react": "^1.1.1", @@ -81,10 +81,6 @@ "@react-navigation/drawer": "^6.6.15", "@react-navigation/native": "^6.1.17", "@react-navigation/native-stack": "^6.9.26", - "@segment/analytics-next": "^1.51.3", - "@segment/analytics-react": "^1.0.0-rc1", - "@segment/analytics-react-native": "^2.10.1", - "@segment/sovran-react-native": "^0.4.5", "@sentry/react-native": "5.32.0", "@tamagui/focus-scope": "^1.84.1", "@tanstack/query-async-storage-persister": "^5.25.0", diff --git a/plugins/shareExtension/withIntentFilters.js b/plugins/shareExtension/withIntentFilters.js index 605fcfd052..16494893bb 100644 --- a/plugins/shareExtension/withIntentFilters.js +++ b/plugins/shareExtension/withIntentFilters.js @@ -27,6 +27,29 @@ const withIntentFilters = config => { }, ], }, + { + action: [ + { + $: { + 'android:name': 'android.intent.action.SEND', + }, + }, + ], + category: [ + { + $: { + 'android:name': 'android.intent.category.DEFAULT', + }, + }, + ], + data: [ + { + $: { + 'android:mimeType': 'video/*', + }, + }, + ], + }, { action: [ { diff --git a/src/Navigation.tsx b/src/Navigation.tsx index 2beba4f9dc..53e8274d54 100644 --- a/src/Navigation.tsx +++ b/src/Navigation.tsx @@ -15,7 +15,6 @@ import { StackActions, } from '@react-navigation/native' -import {init as initAnalytics} from '#/lib/analytics/analytics' import {timeout} from '#/lib/async/timeout' import {useColorSchemeStyle} from '#/lib/hooks/useColorSchemeStyle' import {usePalette} from '#/lib/hooks/usePalette' @@ -647,8 +646,6 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) { function onReady() { prevLoggedRouteName.current = getCurrentRouteName() - initAnalytics(currentAccount) - if (currentAccount && shouldRequestEmailConfirmation(currentAccount)) { openModal({name: 'verify-email', showReminder: true}) snoozeEmailConfirmationPrompt() diff --git a/src/components/StarterPack/QrCode.tsx b/src/components/StarterPack/QrCode.tsx index 8ce5cbbb13..c6408109bb 100644 --- a/src/components/StarterPack/QrCode.tsx +++ b/src/components/StarterPack/QrCode.tsx @@ -1,18 +1,23 @@ import React from 'react' import {View} from 'react-native' import QRCode from 'react-native-qrcode-styled' -import ViewShot from 'react-native-view-shot' +import type ViewShot from 'react-native-view-shot' import {AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api' import {Trans} from '@lingui/macro' -import {isWeb} from 'platform/detection' -import {Logo} from 'view/icons/Logo' -import {Logotype} from 'view/icons/Logotype' +import {isWeb} from '#/platform/detection' +import {Logo} from '#/view/icons/Logo' +import {Logotype} from '#/view/icons/Logotype' import {useTheme} from '#/alf' import {atoms as a} from '#/alf' import {LinearGradientBackground} from '#/components/LinearGradientBackground' import {Text} from '#/components/Typography' +const LazyViewShot = React.lazy( + // @ts-expect-error dynamic import + () => import('react-native-view-shot/src/index'), +) + interface Props { starterPack: AppBskyGraphDefs.StarterPackView link: string @@ -29,7 +34,7 @@ export const QrCode = React.forwardRef(function QrCode( } return ( - + (function QrCode( - + ) }) diff --git a/src/components/StarterPack/QrCodeDialog.tsx b/src/components/StarterPack/QrCodeDialog.tsx index a884390bf8..b2af8ff73a 100644 --- a/src/components/StarterPack/QrCodeDialog.tsx +++ b/src/components/StarterPack/QrCodeDialog.tsx @@ -1,6 +1,6 @@ import React from 'react' import {View} from 'react-native' -import ViewShot from 'react-native-view-shot' +import type ViewShot from 'react-native-view-shot' import {requestMediaLibraryPermissionsAsync} from 'expo-image-picker' import {createAssetAsync} from 'expo-media-library' import * as Sharing from 'expo-sharing' @@ -8,9 +8,9 @@ import {AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' +import {logEvent} from '#/lib/statsig/statsig' import {logger} from '#/logger' -import {logEvent} from 'lib/statsig/statsig' -import {isNative, isWeb} from 'platform/detection' +import {isNative, isWeb} from '#/platform/detection' import * as Toast from '#/view/com/util/Toast' import {atoms as a} from '#/alf' import {Button, ButtonText} from '#/components/Button' @@ -153,46 +153,54 @@ export function QrCodeDialog({ - {!link ? ( - - - - ) : ( - <> - - {isProcessing ? ( - - - - ) : ( - - - - - )} - - )} + }> + {!link ? ( + + ) : ( + <> + + {isProcessing ? ( + + + + ) : ( + + + + + )} + + )} + ) } + +function Loading() { + return ( + + + + ) +} diff --git a/src/lib/analytics/analytics.tsx b/src/lib/analytics/analytics.tsx deleted file mode 100644 index 5f93d982fd..0000000000 --- a/src/lib/analytics/analytics.tsx +++ /dev/null @@ -1,158 +0,0 @@ -import React from 'react' -import {AppState, AppStateStatus} from 'react-native' -import AsyncStorage from '@react-native-async-storage/async-storage' -import {createClient, SegmentClient} from '@segment/analytics-react-native' -import * as Sentry from '@sentry/react-native' -import {sha256} from 'js-sha256' - -import {logger} from '#/logger' -import {SessionAccount, useSession} from '#/state/session' -import {ScreenPropertiesMap, TrackPropertiesMap} from './types' - -type AppInfo = { - build?: string | undefined - name?: string | undefined - namespace?: string | undefined - version?: string | undefined -} - -// Delay creating until first actual use. -let segmentClient: SegmentClient | null = null -function getClient(): SegmentClient { - if (!segmentClient) { - segmentClient = createClient({ - writeKey: '8I6DsgfiSLuoONyaunGoiQM7A6y2ybdI', - trackAppLifecycleEvents: false, - proxy: 'https://api.events.bsky.app/v1', - }) - } - return segmentClient -} - -export const track = async ( - event: E, - properties?: TrackPropertiesMap[E], -) => { - await getClient().track(event, properties) -} - -export function useAnalytics() { - const {hasSession} = useSession() - - return React.useMemo(() => { - if (hasSession) { - return { - async screen( - event: E, - properties?: ScreenPropertiesMap[E], - ) { - await getClient().screen(event, properties) - }, - async track( - event: E, - properties?: TrackPropertiesMap[E], - ) { - await getClient().track(event, properties) - }, - } - } - // dont send analytics pings for anonymous users - return { - screen: async () => {}, - track: async () => {}, - } - }, [hasSession]) -} - -export function init(account: SessionAccount | undefined) { - setupListenersOnce() - - if (account) { - const client = getClient() - if (account.did) { - const did_hashed = sha256(account.did) - client.identify(did_hashed, {did_hashed}) - Sentry.setUser({id: did_hashed}) - logger.debug('Ping w/hash') - } else { - logger.debug('Ping w/o hash') - client.identify() - } - } -} - -let didSetupListeners = false -function setupListenersOnce() { - if (didSetupListeners) { - return - } - didSetupListeners = true - // NOTE - // this is a copy of segment's own lifecycle event tracking - // we handle it manually to ensure that it never fires while the app is backgrounded - // -prf - const client = getClient() - client.isReady.onChange(async () => { - if (AppState.currentState !== 'active') { - logger.debug('Prevented a metrics ping while the app was backgrounded') - return - } - const context = client.context.get() - if (typeof context?.app === 'undefined') { - logger.debug('Aborted metrics ping due to unavailable context') - return - } - - const oldAppInfo = await readAppInfo() - const newAppInfo = context.app as AppInfo - writeAppInfo(newAppInfo) - logger.debug('Recording app info', {new: newAppInfo, old: oldAppInfo}) - - if (typeof oldAppInfo === 'undefined') { - client.track('Application Installed', { - version: newAppInfo.version, - build: newAppInfo.build, - }) - } else if (newAppInfo.version !== oldAppInfo.version) { - client.track('Application Updated', { - version: newAppInfo.version, - build: newAppInfo.build, - previous_version: oldAppInfo.version, - previous_build: oldAppInfo.build, - }) - } - client.track('Application Opened', { - from_background: false, - version: newAppInfo.version, - build: newAppInfo.build, - }) - }) - - let lastState: AppStateStatus = AppState.currentState - AppState.addEventListener('change', (state: AppStateStatus) => { - if (state === 'active' && lastState !== 'active') { - const context = client.context.get() - client.track('Application Opened', { - from_background: true, - version: context?.app?.version, - build: context?.app?.build, - }) - } else if (state !== 'active' && lastState === 'active') { - client.track('Application Backgrounded') - } - lastState = state - }) -} - -async function writeAppInfo(value: AppInfo) { - await AsyncStorage.setItem('BSKY_APP_INFO', JSON.stringify(value)) -} - -async function readAppInfo(): Promise { - const rawData = await AsyncStorage.getItem('BSKY_APP_INFO') - const obj = rawData ? JSON.parse(rawData) : undefined - if (!obj || typeof obj !== 'object') { - return undefined - } - return obj -} diff --git a/src/lib/analytics/analytics.web.tsx b/src/lib/analytics/analytics.web.tsx deleted file mode 100644 index c7f0ed3b14..0000000000 --- a/src/lib/analytics/analytics.web.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import React from 'react' -import {createClient} from '@segment/analytics-react' -import * as Sentry from '@sentry/react-native' -import {sha256} from 'js-sha256' - -import {logger} from '#/logger' -import {SessionAccount, useSession} from '#/state/session' -import {ScreenPropertiesMap, TrackPropertiesMap} from './types' - -type SegmentClient = ReturnType - -// Delay creating until first actual use. -let segmentClient: SegmentClient | null = null -function getClient(): SegmentClient { - if (!segmentClient) { - segmentClient = createClient( - { - writeKey: '8I6DsgfiSLuoONyaunGoiQM7A6y2ybdI', - }, - { - integrations: { - 'Segment.io': { - apiHost: 'api.events.bsky.app/v1', - }, - }, - }, - ) - } - return segmentClient -} - -export const track = async ( - event: E, - properties?: TrackPropertiesMap[E], -) => { - await getClient().track(event, properties) -} - -export function useAnalytics() { - const {hasSession} = useSession() - - return React.useMemo(() => { - if (hasSession) { - return { - async screen( - event: E, - properties?: ScreenPropertiesMap[E], - ) { - await getClient().screen(event, properties) - }, - async track( - event: E, - properties?: TrackPropertiesMap[E], - ) { - await getClient().track(event, properties) - }, - } - } - // dont send analytics pings for anonymous users - return { - screen: async () => {}, - track: async () => {}, - } - }, [hasSession]) -} - -export function init(account: SessionAccount | undefined) { - if (account) { - const client = getClient() - if (account.did) { - const did_hashed = sha256(account.did) - client.identify(did_hashed, {did_hashed}) - Sentry.setUser({id: did_hashed}) - logger.debug('Ping w/hash') - } else { - logger.debug('Ping w/o hash') - client.identify() - } - } -} diff --git a/src/lib/analytics/types.ts b/src/lib/analytics/types.ts deleted file mode 100644 index 720495ea1d..0000000000 --- a/src/lib/analytics/types.ts +++ /dev/null @@ -1,181 +0,0 @@ -export type TrackPropertiesMap = { - // LOGIN / SIGN UP events - 'Sign In': {resumedSession: boolean} // CAN BE SERVER - 'Create Account': {} // CAN BE SERVER - 'Try Create Account': {} - 'Signin:PressedForgotPassword': {} - 'Signin:PressedSelectService': {} - // COMPOSER / CREATE POST events - 'Create Post': {imageCount: string | number} // CAN BE SERVER - 'Composer:PastedPhotos': {} - 'Composer:CameraOpened': {} - 'Composer:GalleryOpened': {} - 'Composer:ThreadgateOpened': {} - 'HomeScreen:PressCompose': {} - 'ProfileScreen:PressCompose': {} - // EDIT PROFILE events - 'EditHandle:ViewCustomForm': {} - 'EditHandle:ViewProvidedForm': {} - 'EditHandle:SetNewHandle': {} - 'EditProfile:AvatarSelected': {} - 'EditProfile:BannerSelected': {} - 'EditProfile:Save': {} // CAN BE SERVER - // FEED events - 'Feed:onRefresh': {} - 'Feed:onEndReached': {} - // POST events - 'Post:Like': {} // CAN BE SERVER - 'Post:Unlike': {} // CAN BE SERVER - 'Post:Repost': {} // CAN BE SERVER - 'Post:Unrepost': {} // CAN BE SERVER - 'Post:Delete': {} // CAN BE SERVER - 'Post:ThreadMute': {} // CAN BE SERVER - 'Post:ThreadUnmute': {} // CAN BE SERVER - 'Post:Reply': {} // CAN BE SERVER - 'Post:EditThreadgateOpened': {} - 'Post:ThreadgateEdited': {} - // PROFILE events - 'Profile:Follow': { - username: string - } - 'Profile:Unfollow': { - username: string - } - // PROFILE HEADER events - 'ProfileHeader:EditProfileButtonClicked': {} - 'ProfileHeader:FollowersButtonClicked': { - handle: string - } - 'ProfileHeader:FollowsButtonClicked': { - handle: string - } - 'ProfileHeader:ShareButtonClicked': {} - 'ProfileHeader:MuteAccountButtonClicked': {} - 'ProfileHeader:UnmuteAccountButtonClicked': {} - 'ProfileHeader:ReportAccountButtonClicked': {} - 'ProfileHeader:AddToListsButtonClicked': {} - 'ProfileHeader:BlockAccountButtonClicked': {} - 'ProfileHeader:UnblockAccountButtonClicked': {} - 'ProfileHeader:FollowButtonClicked': {} - 'ProfileHeader:UnfollowButtonClicked': {} - 'ProfileHeader:SuggestedFollowsOpened': {} - 'ProfileHeader:SuggestedFollowFollowed': {} - 'ViewHeader:MenuButtonClicked': {} - // SETTINGS events - 'Settings:SwitchAccountButtonClicked': {} - 'Settings:AddAccountButtonClicked': {} - 'Settings:ChangeHandleButtonClicked': {} - 'Settings:InvitecodesButtonClicked': {} - 'Settings:SignOutButtonClicked': {} - 'Settings:ContentlanguagesButtonClicked': {} - // MENU events - 'Menu:ItemClicked': {url: string} - 'Menu:FeedbackClicked': {} - 'Menu:HelpClicked': {} - // MOBILE SHELL events - 'MobileShell:MyProfileButtonPressed': {} - 'MobileShell:HomeButtonPressed': {} - 'MobileShell:SearchButtonPressed': {} - 'MobileShell:NotificationsButtonPressed': {} - 'MobileShell:FeedsButtonPressed': {} - 'MobileShell:MessagesButtonPressed': {} - // NOTIFICATIONS events - 'Notificatons:OpenApp': {} - // LISTS events - 'Lists:onRefresh': {} - 'Lists:onEndReached': {} - 'CreateList:AvatarSelected': {} - 'CreateList:SaveCurateList': {} // CAN BE SERVER - 'CreateList:SaveModList': {} // CAN BE SERVER - 'Lists:Mute': {} // CAN BE SERVER - 'Lists:Unmute': {} // CAN BE SERVER - 'Lists:Block': {} // CAN BE SERVER - 'Lists:Unblock': {} // CAN BE SERVER - 'Lists:Delete': {} // CAN BE SERVER - 'Lists:Share': {} // CAN BE SERVER - // CUSTOM FEED events - 'CustomFeed:Save': {} - 'CustomFeed:Unsave': {} - 'CustomFeed:Like': {} - 'CustomFeed:Unlike': {} - 'CustomFeed:Share': {} - 'CustomFeed:Pin': { - uri: string - name?: string - } - 'CustomFeed:Unpin': { - uri: string - name?: string - } - 'CustomFeed:Reorder': { - uri: string - name?: string - index: number - } - 'CustomFeed:LoadMore': {} - 'MultiFeed:onEndReached': {} - 'MultiFeed:onRefresh': {} - // MODERATION events - 'Moderation:ContentfilteringButtonClicked': {} - // ONBOARDING events - 'Onboarding:Begin': {} - 'Onboarding:Complete': {} - 'Onboarding:Skipped': {} - 'Onboarding:Reset': {} - 'Onboarding:SuggestedFollowFollowed': {} - 'Onboarding:CustomFeedAdded': {} - // Onboarding v2 - 'OnboardingV2:Begin': {} - 'OnboardingV2:StepInterests:Start': {} - 'OnboardingV2:StepInterests:End': { - selectedInterests: string[] - selectedInterestsLength: number - } - 'OnboardingV2:StepInterests:Error': {} - 'OnboardingV2:StepSuggestedAccounts:Start': {} - 'OnboardingV2:StepSuggestedAccounts:End': { - selectedAccountsLength: number - } - 'OnboardingV2:StepFollowingFeed:Start': {} - 'OnboardingV2:StepFollowingFeed:End': {} - 'OnboardingV2:StepAlgoFeeds:Start': {} - 'OnboardingV2:StepAlgoFeeds:End': { - selectedPrimaryFeeds: string[] - selectedPrimaryFeedsLength: number - selectedSecondaryFeeds: string[] - selectedSecondaryFeedsLength: number - } - 'OnboardingV2:StepTopicalFeeds:Start': {} - 'OnboardingV2:StepTopicalFeeds:End': { - selectedFeeds: string[] - selectedFeedsLength: number - } - 'OnboardingV2:StepModeration:Start': {} - 'OnboardingV2:StepModeration:End': {} - 'OnboardingV2:StepProfile:Start': {} - 'OnboardingV2:StepProfile:End': {} - 'OnboardingV2:StepFinished:Start': {} - 'OnboardingV2:StepFinished:End': {} - 'OnboardingV2:Complete': {} - 'OnboardingV2:Skip': {} -} - -export type ScreenPropertiesMap = { - Login: {} - CreateAccount: {} - 'Choose Account': {} - 'Signin:ForgotPassword': {} - 'Signin:SetNewPasswordForm': {} - 'Signin:PasswordUpdatedForm': {} - Feed: {} - Notifications: {} - Profile: {} - 'Profile:Preview': {} - Settings: {} - AppPasswords: {} - Moderation: {} - PreferencesExternalEmbeds: {} - BlockedAccounts: {} - MutedAccounts: {} - SavedFeeds: {} -} diff --git a/src/lib/api/feed/author.ts b/src/lib/api/feed/author.ts index 56eff18816..50e6a447e7 100644 --- a/src/lib/api/feed/author.ts +++ b/src/lib/api/feed/author.ts @@ -8,7 +8,7 @@ import {FeedAPI, FeedAPIResponse} from './types' export class AuthorFeedAPI implements FeedAPI { agent: BskyAgent - params: GetAuthorFeed.QueryParams + _params: GetAuthorFeed.QueryParams constructor({ agent, @@ -18,7 +18,13 @@ export class AuthorFeedAPI implements FeedAPI { feedParams: GetAuthorFeed.QueryParams }) { this.agent = agent - this.params = feedParams + this._params = feedParams + } + + get params() { + const params = {...this._params} + params.includePins = params.filter !== 'posts_with_media' + return params } async peekLatest(): Promise { @@ -57,8 +63,9 @@ export class AuthorFeedAPI implements FeedAPI { return feed.filter(post => { const isReply = post.reply const isRepost = AppBskyFeedDefs.isReasonRepost(post.reason) + const isPin = AppBskyFeedDefs.isReasonPin(post.reason) if (!isReply) return true - if (isRepost) return true + if (isRepost || isPin) return true return isReply && isAuthorReplyChain(this.params.actor, post, feed) }) } diff --git a/src/lib/custom-animations/PressableScale.tsx b/src/lib/custom-animations/PressableScale.tsx index d6eabf8b22..ca080dc8ae 100644 --- a/src/lib/custom-animations/PressableScale.tsx +++ b/src/lib/custom-animations/PressableScale.tsx @@ -13,17 +13,19 @@ import {isNative} from '#/platform/detection' const DEFAULT_TARGET_SCALE = isNative || isTouchDevice ? 0.98 : 1 +const AnimatedPressable = Animated.createAnimatedComponent(Pressable) + export function PressableScale({ targetScale = DEFAULT_TARGET_SCALE, children, - contentContainerStyle, + style, onPressIn, onPressOut, ...rest }: { targetScale?: number - contentContainerStyle?: StyleProp -} & Exclude) { + style?: StyleProp +} & Exclude) { const scale = useSharedValue(1) const animatedStyle = useAnimatedStyle(() => ({ @@ -31,7 +33,7 @@ export function PressableScale({ })) return ( - { 'worklet' @@ -49,10 +51,9 @@ export function PressableScale({ cancelAnimation(scale) scale.value = withTiming(1, {duration: 100}) }} + style={[animatedStyle, style]} {...rest}> - - {children as React.ReactNode} - - + {children} + ) } diff --git a/src/lib/hooks/useAccountSwitcher.ts b/src/lib/hooks/useAccountSwitcher.ts index 09ff30277f..22eb348f2e 100644 --- a/src/lib/hooks/useAccountSwitcher.ts +++ b/src/lib/hooks/useAccountSwitcher.ts @@ -2,7 +2,6 @@ import {useCallback, useState} from 'react' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useAnalytics} from '#/lib/analytics/analytics' import {logger} from '#/logger' import {isWeb} from '#/platform/detection' import {SessionAccount, useSessionApi} from '#/state/session' @@ -14,7 +13,6 @@ import {LogEvents} from '../statsig/statsig' export function useAccountSwitcher() { const [pendingDid, setPendingDid] = useState(null) const {_} = useLingui() - const {track} = useAnalytics() const {resumeSession} = useSessionApi() const {requestSwitchToAccount} = useLoggedOutViewControls() @@ -23,7 +21,6 @@ export function useAccountSwitcher() { account: SessionAccount, logContext: LogEvents['account:loggedIn']['logContext'], ) => { - track('Settings:SwitchAccountButtonClicked') if (pendingDid) { // The session API isn't resilient to race conditions so let's just ignore this. return @@ -62,7 +59,7 @@ export function useAccountSwitcher() { setPendingDid(null) } }, - [_, track, resumeSession, requestSwitchToAccount, pendingDid], + [_, resumeSession, requestSwitchToAccount, pendingDid], ) return {onPressSwitchAccount, pendingDid} diff --git a/src/lib/hooks/useNotificationHandler.ts b/src/lib/hooks/useNotificationHandler.ts index e4e7e14744..625ec9e6a9 100644 --- a/src/lib/hooks/useNotificationHandler.ts +++ b/src/lib/hooks/useNotificationHandler.ts @@ -3,19 +3,18 @@ import * as Notifications from 'expo-notifications' import {CommonActions, useNavigation} from '@react-navigation/native' import {useQueryClient} from '@tanstack/react-query' +import {useAccountSwitcher} from '#/lib/hooks/useAccountSwitcher' +import {NavigationProp} from '#/lib/routes/types' +import {logEvent} from '#/lib/statsig/statsig' import {logger} from '#/logger' -import {track} from 'lib/analytics/analytics' -import {useAccountSwitcher} from 'lib/hooks/useAccountSwitcher' -import {NavigationProp} from 'lib/routes/types' -import {logEvent} from 'lib/statsig/statsig' -import {isAndroid} from 'platform/detection' -import {useCurrentConvoId} from 'state/messages/current-convo-id' -import {RQKEY as RQKEY_NOTIFS} from 'state/queries/notifications/feed' -import {invalidateCachedUnreadPage} from 'state/queries/notifications/unread' -import {truncateAndInvalidate} from 'state/queries/util' -import {useSession} from 'state/session' -import {useLoggedOutViewControls} from 'state/shell/logged-out' -import {useCloseAllActiveElements} from 'state/util' +import {isAndroid} from '#/platform/detection' +import {useCurrentConvoId} from '#/state/messages/current-convo-id' +import {RQKEY as RQKEY_NOTIFS} from '#/state/queries/notifications/feed' +import {invalidateCachedUnreadPage} from '#/state/queries/notifications/unread' +import {truncateAndInvalidate} from '#/state/queries/util' +import {useSession} from '#/state/session' +import {useLoggedOutViewControls} from '#/state/shell/logged-out' +import {useCloseAllActiveElements} from '#/state/util' import {resetToTab} from '#/Navigation' type NotificationReason = @@ -228,7 +227,6 @@ export function useNotificationsHandler() { {}, logger.DebugContext.notifications, ) - track('Notificatons:OpenApp') logEvent('notifications:openApp', {}) invalidateCachedUnreadPage() truncateAndInvalidate(queryClient, RQKEY_NOTIFS()) diff --git a/src/lib/strings/embed-player.ts b/src/lib/strings/embed-player.ts index 3bae771c0a..d0d8277c86 100644 --- a/src/lib/strings/embed-player.ts +++ b/src/lib/strings/embed-player.ts @@ -1,7 +1,7 @@ import {Dimensions} from 'react-native' -import {isSafari} from 'lib/browser' -import {isWeb} from 'platform/detection' +import {isSafari} from '#/lib/browser' +import {isWeb} from '#/platform/detection' const {height: SCREEN_HEIGHT} = Dimensions.get('window') @@ -185,6 +185,20 @@ export function parseEmbedPlayerFromUrl( playerUri: `https://open.spotify.com/embed/track/${id ?? idOrType}`, } } + if (typeOrLocale === 'episode' || idOrType === 'episode') { + return { + type: 'spotify_song', + source: 'spotify', + playerUri: `https://open.spotify.com/embed/episode/${id ?? idOrType}`, + } + } + if (typeOrLocale === 'show' || idOrType === 'show') { + return { + type: 'spotify_song', + source: 'spotify', + playerUri: `https://open.spotify.com/embed/show/${id ?? idOrType}`, + } + } } } diff --git a/src/screens/Login/ChooseAccountForm.tsx b/src/screens/Login/ChooseAccountForm.tsx index 678ba51237..9765786ecf 100644 --- a/src/screens/Login/ChooseAccountForm.tsx +++ b/src/screens/Login/ChooseAccountForm.tsx @@ -3,7 +3,6 @@ import {View} from 'react-native' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useAnalytics} from '#/lib/analytics/analytics' import {logEvent} from '#/lib/statsig/statsig' import {logger} from '#/logger' import {SessionAccount, useSession, useSessionApi} from '#/state/session' @@ -23,16 +22,11 @@ export const ChooseAccountForm = ({ onPressBack: () => void }) => { const [pendingDid, setPendingDid] = React.useState(null) - const {track, screen} = useAnalytics() const {_} = useLingui() const {currentAccount} = useSession() const {resumeSession} = useSessionApi() const {setShowLoggedOut} = useLoggedOutViewControls() - React.useEffect(() => { - screen('Choose Account') - }, [screen]) - const onSelect = React.useCallback( async (account: SessionAccount) => { if (pendingDid) { @@ -56,7 +50,6 @@ export const ChooseAccountForm = ({ logContext: 'ChooseAccountForm', withPassword: false, }) - track('Sign In', {resumedSession: true}) Toast.show(_(msg`Signed in as @${account.handle}`)) } catch (e: any) { logger.error('choose account: initSession failed', { @@ -70,7 +63,6 @@ export const ChooseAccountForm = ({ }, [ currentAccount, - track, resumeSession, pendingDid, onSelectAccount, diff --git a/src/screens/Login/ForgotPasswordForm.tsx b/src/screens/Login/ForgotPasswordForm.tsx index 7acaae5101..e8582f46f5 100644 --- a/src/screens/Login/ForgotPasswordForm.tsx +++ b/src/screens/Login/ForgotPasswordForm.tsx @@ -1,4 +1,4 @@ -import React, {useEffect, useState} from 'react' +import React, {useState} from 'react' import {ActivityIndicator, Keyboard, View} from 'react-native' import {ComAtprotoServerDescribeServer} from '@atproto/api' import {BskyAgent} from '@atproto/api' @@ -6,7 +6,6 @@ import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import * as EmailValidator from 'email-validator' -import {useAnalytics} from '#/lib/analytics/analytics' import {isNetworkError} from '#/lib/strings/errors' import {cleanError} from '#/lib/strings/errors' import {logger} from '#/logger' @@ -41,13 +40,8 @@ export const ForgotPasswordForm = ({ const t = useTheme() const [isProcessing, setIsProcessing] = useState(false) const [email, setEmail] = useState('') - const {screen} = useAnalytics() const {_} = useLingui() - useEffect(() => { - screen('Signin:ForgotPassword') - }, [screen]) - const onPressSelectService = React.useCallback(() => { Keyboard.dismiss() }, []) diff --git a/src/screens/Login/LoginForm.tsx b/src/screens/Login/LoginForm.tsx index 9c2237214b..f3661ac92c 100644 --- a/src/screens/Login/LoginForm.tsx +++ b/src/screens/Login/LoginForm.tsx @@ -13,7 +13,6 @@ import { import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useAnalytics} from '#/lib/analytics/analytics' import {useRequestNotificationsPermission} from '#/lib/notifications/notifications' import {isNetworkError} from '#/lib/strings/errors' import {cleanError} from '#/lib/strings/errors' @@ -57,7 +56,6 @@ export const LoginForm = ({ onPressBack: () => void onPressForgotPassword: () => void }) => { - const {track} = useAnalytics() const t = useTheme() const [isProcessing, setIsProcessing] = useState(false) const [isAuthFactorTokenNeeded, setIsAuthFactorTokenNeeded] = @@ -74,8 +72,7 @@ export const LoginForm = ({ const onPressSelectService = React.useCallback(() => { Keyboard.dismiss() - track('Signin:PressedSelectService') - }, [track]) + }, []) const onPressNext = async () => { if (isProcessing) return diff --git a/src/screens/Login/PasswordUpdatedForm.tsx b/src/screens/Login/PasswordUpdatedForm.tsx index 03e7d86696..9c12a47e3f 100644 --- a/src/screens/Login/PasswordUpdatedForm.tsx +++ b/src/screens/Login/PasswordUpdatedForm.tsx @@ -1,9 +1,8 @@ -import React, {useEffect} from 'react' +import React from 'react' import {View} from 'react-native' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useAnalytics} from '#/lib/analytics/analytics' import {atoms as a, useBreakpoints} from '#/alf' import {Button, ButtonText} from '#/components/Button' import {Text} from '#/components/Typography' @@ -14,14 +13,9 @@ export const PasswordUpdatedForm = ({ }: { onPressNext: () => void }) => { - const {screen} = useAnalytics() const {_} = useLingui() const {gtMobile} = useBreakpoints() - useEffect(() => { - screen('Signin:PasswordUpdatedForm') - }, [screen]) - return ( void onPasswordSet: () => void }) => { - const {screen} = useAnalytics() const {_} = useLingui() const t = useTheme() - useEffect(() => { - screen('Signin:SetNewPasswordForm') - }, [screen]) - const [isProcessing, setIsProcessing] = useState(false) const [resetCode, setResetCode] = useState('') const [password, setPassword] = useState('') diff --git a/src/screens/Login/index.tsx b/src/screens/Login/index.tsx index 1fce63d298..b46f8d26bf 100644 --- a/src/screens/Login/index.tsx +++ b/src/screens/Login/index.tsx @@ -4,7 +4,6 @@ import {LayoutAnimationConfig} from 'react-native-reanimated' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useAnalytics} from '#/lib/analytics/analytics' import {DEFAULT_SERVICE} from '#/lib/constants' import {logger} from '#/logger' import {useServiceQuery} from '#/state/queries/service' @@ -31,7 +30,6 @@ export const Login = ({onPressBack}: {onPressBack: () => void}) => { const {_} = useLingui() const {accounts} = useSession() - const {track} = useAnalytics() const {requestedAccountSwitchTo} = useLoggedOutView() const requestedAccount = accounts.find( acc => acc.did === requestedAccountSwitchTo, @@ -87,7 +85,6 @@ export const Login = ({onPressBack}: {onPressBack: () => void}) => { }, [serviceError, serviceUrl, _]) const onPressForgotPassword = () => { - track('Signin:PressedForgotPassword') setCurrentForm(Forms.ForgotPassword) } diff --git a/src/screens/Moderation/index.tsx b/src/screens/Moderation/index.tsx index 9bfe6c3fac..070b879508 100644 --- a/src/screens/Moderation/index.tsx +++ b/src/screens/Moderation/index.tsx @@ -7,7 +7,6 @@ import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useFocusEffect} from '@react-navigation/native' -import {useAnalytics} from '#/lib/analytics/analytics' import {getLabelingServiceTitle} from '#/lib/moderation' import {CommonNavigatorParams, NativeStackScreenProps} from '#/lib/routes/types' import {logger} from '#/logger' @@ -163,7 +162,6 @@ export function ModerationScreenInner({ const {_} = useLingui() const t = useTheme() const setMinimalShellMode = useSetMinimalShellMode() - const {screen} = useAnalytics() const {gtMobile} = useBreakpoints() const {mutedWordsDialogControl} = useGlobalDialogsControlContext() const birthdateDialogControl = Dialog.useDialogControl() @@ -175,9 +173,8 @@ export function ModerationScreenInner({ useFocusEffect( React.useCallback(() => { - screen('Moderation') setMinimalShellMode(false) - }, [screen, setMinimalShellMode]), + }, [setMinimalShellMode]), ) const {mutateAsync: setAdultContentPref, variables: optimisticAdultContent} = diff --git a/src/screens/Onboarding/StepFinished.tsx b/src/screens/Onboarding/StepFinished.tsx index bc765781af..fdc0a3eb72 100644 --- a/src/screens/Onboarding/StepFinished.tsx +++ b/src/screens/Onboarding/StepFinished.tsx @@ -7,27 +7,26 @@ import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useQueryClient} from '@tanstack/react-query' -import {useAnalytics} from '#/lib/analytics/analytics' +import {uploadBlob} from '#/lib/api' import { BSKY_APP_ACCOUNT_DID, DISCOVER_SAVED_FEED, TIMELINE_SAVED_FEED, } from '#/lib/constants' +import {useRequestNotificationsPermission} from '#/lib/notifications/notifications' import {logEvent} from '#/lib/statsig/statsig' import {logger} from '#/logger' +import {useSetHasCheckedForStarterPack} from '#/state/preferences/used-starter-packs' +import {getAllListMembers} from '#/state/queries/list-members' import {preferencesQueryKey} from '#/state/queries/preferences' import {RQKEY as profileRQKey} from '#/state/queries/profile' import {useAgent} from '#/state/session' import {useOnboardingDispatch} from '#/state/shell' import {useProgressGuideControls} from '#/state/shell/progress-guide' -import {uploadBlob} from 'lib/api' -import {useRequestNotificationsPermission} from 'lib/notifications/notifications' -import {useSetHasCheckedForStarterPack} from 'state/preferences/used-starter-packs' -import {getAllListMembers} from 'state/queries/list-members' import { useActiveStarterPack, useSetActiveStarterPack, -} from 'state/shell/starter-pack' +} from '#/state/shell/starter-pack' import { DescriptionText, OnboardingControls, @@ -48,7 +47,6 @@ import {Text} from '#/components/Typography' export function StepFinished() { const {_} = useLingui() const t = useTheme() - const {track} = useAnalytics() const {state, dispatch} = React.useContext(Context) const onboardDispatch = useOnboardingDispatch() const [saving, setSaving] = React.useState(false) @@ -190,8 +188,6 @@ export function StepFinished() { startProgressGuide('like-10-and-follow-7') dispatch({type: 'finish'}) onboardDispatch({type: 'finish'}) - track('OnboardingV2:StepFinished:End') - track('OnboardingV2:Complete') logEvent('onboarding:finished:nextPressed', { usedStarterPack: Boolean(starterPack), starterPackName: AppBskyGraphStarterpack.isRecord(starterPack?.record) @@ -214,7 +210,6 @@ export function StepFinished() { agent, dispatch, onboardDispatch, - track, activeStarterPack, state, requestNotificationsPermission, @@ -223,10 +218,6 @@ export function StepFinished() { startProgressGuide, ]) - React.useEffect(() => { - track('OnboardingV2:StepFinished:Start') - }, [track]) - return ( diff --git a/src/screens/Onboarding/StepInterests/index.tsx b/src/screens/Onboarding/StepInterests/index.tsx index ded473ff59..2f41433aa5 100644 --- a/src/screens/Onboarding/StepInterests/index.tsx +++ b/src/screens/Onboarding/StepInterests/index.tsx @@ -4,7 +4,6 @@ import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useQuery} from '@tanstack/react-query' -import {useAnalytics} from '#/lib/analytics/analytics' import {logEvent} from '#/lib/statsig/statsig' import {capitalize} from '#/lib/strings/capitalize' import {logger} from '#/logger' @@ -36,7 +35,6 @@ export function StepInterests() { const {_} = useLingui() const t = useTheme() const {gtMobile} = useBreakpoints() - const {track} = useAnalytics() const interestsDisplayNames = useInterestsDisplayNames() const {state, dispatch} = React.useContext(Context) @@ -90,7 +88,6 @@ export function StepInterests() { `onboarding: getTaggedSuggestions fetch or processing failed`, ) logger.error(e) - track('OnboardingV2:StepInterests:Error') throw new Error(`a network error occurred`) } @@ -108,11 +105,6 @@ export function StepInterests() { selectedInterests: interests, }) dispatch({type: 'next'}) - - track('OnboardingV2:StepInterests:End', { - selectedInterests: interests, - selectedInterestsLength: interests.length, - }) logEvent('onboarding:interests:nextPressed', { selectedInterests: interests, selectedInterestsLength: interests.length, @@ -121,18 +113,12 @@ export function StepInterests() { logger.info(`onboading: error saving interests`) logger.error(e) } - }, [interests, data, setSaving, dispatch, track]) + }, [interests, data, setSaving, dispatch]) const skipOnboarding = React.useCallback(() => { onboardDispatch({type: 'finish'}) dispatch({type: 'finish'}) - track('OnboardingV2:Skip') - }, [onboardDispatch, dispatch, track]) - - React.useEffect(() => { - track('OnboardingV2:Begin') - track('OnboardingV2:StepInterests:Start') - }, [track]) + }, [onboardDispatch, dispatch]) const title = isError ? ( Oh no! Something went wrong. diff --git a/src/screens/Onboarding/StepProfile/PlaceholderCanvas.tsx b/src/screens/Onboarding/StepProfile/PlaceholderCanvas.tsx index d1d1af6d9f..eaad2113f8 100644 --- a/src/screens/Onboarding/StepProfile/PlaceholderCanvas.tsx +++ b/src/screens/Onboarding/StepProfile/PlaceholderCanvas.tsx @@ -1,14 +1,19 @@ import React from 'react' import {View} from 'react-native' -import ViewShot from 'react-native-view-shot' +import type ViewShot from 'react-native-view-shot' import {useAvatar} from '#/screens/Onboarding/StepProfile/index' import {atoms as a} from '#/alf' +const LazyViewShot = React.lazy( + // @ts-expect-error dynamic import + () => import('react-native-view-shot/src/index'), +) + const SIZE_MULTIPLIER = 5 export interface PlaceholderCanvasRef { - capture: () => Promise + capture: () => Promise } // This component is supposed to be invisible to the user. We only need this for ViewShot to have something to @@ -16,7 +21,7 @@ export interface PlaceholderCanvasRef { export const PlaceholderCanvas = React.forwardRef( function PlaceholderCanvas({}, ref) { const {avatar} = useAvatar() - const viewshotRef = React.useRef() + const viewshotRef = React.useRef(null) const Icon = avatar.placeholder.component const styles = React.useMemo( @@ -32,13 +37,16 @@ export const PlaceholderCanvas = React.forwardRef( ) React.useImperativeHandle(ref, () => ({ - // @ts-ignore this library doesn't have types - capture: viewshotRef.current.capture, + capture: async () => { + if (viewshotRef.current?.capture) { + return await viewshotRef.current.capture() + } + }, })) return ( - ( style={{color: 'white'}} /> - + ) }, diff --git a/src/screens/Onboarding/StepProfile/index.tsx b/src/screens/Onboarding/StepProfile/index.tsx index 5304aa5031..663418f220 100644 --- a/src/screens/Onboarding/StepProfile/index.tsx +++ b/src/screens/Onboarding/StepProfile/index.tsx @@ -9,14 +9,13 @@ import { import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useAnalytics} from '#/lib/analytics/analytics' +import {usePhotoLibraryPermission} from '#/lib/hooks/usePermissions' +import {compressIfNeeded} from '#/lib/media/manip' +import {openCropper} from '#/lib/media/picker' +import {getDataUriSize} from '#/lib/media/util' +import {useRequestNotificationsPermission} from '#/lib/notifications/notifications' import {logEvent, useGate} from '#/lib/statsig/statsig' -import {usePhotoLibraryPermission} from 'lib/hooks/usePermissions' -import {compressIfNeeded} from 'lib/media/manip' -import {openCropper} from 'lib/media/picker' -import {getDataUriSize} from 'lib/media/util' -import {useRequestNotificationsPermission} from 'lib/notifications/notifications' -import {isNative, isWeb} from 'platform/detection' +import {isNative, isWeb} from '#/platform/detection' import { DescriptionText, OnboardingControls, @@ -68,7 +67,6 @@ export function StepProfile() { const {_} = useLingui() const t = useTheme() const {gtMobile} = useBreakpoints() - const {track} = useAnalytics() const {requestPhotoAccessIfNeeded} = usePhotoLibraryPermission() const gate = useGate() const requestNotificationsPermission = useRequestNotificationsPermission() @@ -87,10 +85,6 @@ export function StepProfile() { const canvasRef = React.useRef(null) - React.useEffect(() => { - track('OnboardingV2:StepProfile:Start') - }, [track]) - React.useEffect(() => { requestNotificationsPermission('StartOnboarding') }, [gate, requestNotificationsPermission]) @@ -132,6 +126,10 @@ export function StepProfile() { const onContinue = React.useCallback(async () => { let imageUri = avatar?.image?.path + + // In the event that view-shot didn't load in time and the user pressed continue, this will just be undefined + // and the default avatar will be used. We don't want to block getting through create if this fails for some + // reason if (!imageUri || avatar.useCreatedAvatar) { imageUri = await canvasRef.current?.capture() } @@ -151,9 +149,8 @@ export function StepProfile() { } dispatch({type: 'next'}) - track('OnboardingV2:StepProfile:End') logEvent('onboarding:profile:nextPressed', {}) - }, [avatar, dispatch, track]) + }, [avatar, dispatch]) const onDoneCreating = React.useCallback(() => { setAvatar(prev => ({ diff --git a/src/screens/Onboarding/state.ts b/src/screens/Onboarding/state.ts index c41db5c3b7..70fa696408 100644 --- a/src/screens/Onboarding/state.ts +++ b/src/screens/Onboarding/state.ts @@ -51,13 +51,15 @@ export type OnboardingAction = | { type: 'setProfileStepResults' isCreatedAvatar: boolean - image?: OnboardingState['profileStepResults']['image'] - imageUri: string + image: OnboardingState['profileStepResults']['image'] | undefined + imageUri: string | undefined imageMime: string - creatorState?: { - emoji: Emoji - backgroundColor: AvatarColor - } + creatorState: + | { + emoji: Emoji + backgroundColor: AvatarColor + } + | undefined } export type ApiResponseMap = { diff --git a/src/screens/Profile/Header/ProfileHeaderLabeler.tsx b/src/screens/Profile/Header/ProfileHeaderLabeler.tsx index a807c70dd9..7b44e58693 100644 --- a/src/screens/Profile/Header/ProfileHeaderLabeler.tsx +++ b/src/screens/Profile/Header/ProfileHeaderLabeler.tsx @@ -12,18 +12,17 @@ import {useLingui} from '@lingui/react' // eslint-disable-next-line @typescript-eslint/no-unused-vars import {MAX_LABELERS} from '#/lib/constants' +import {useHaptics} from '#/lib/haptics' import {isAppLabeler} from '#/lib/moderation' import {logger} from '#/logger' +import {isIOS} from '#/platform/detection' +import {useProfileShadow} from '#/state/cache/profile-shadow' import {Shadow} from '#/state/cache/types' import {useModalControls} from '#/state/modals' import {useLabelerSubscriptionMutation} from '#/state/queries/labeler' import {useLikeMutation, useUnlikeMutation} from '#/state/queries/like' import {usePreferencesQuery} from '#/state/queries/preferences' import {useRequireAuth, useSession} from '#/state/session' -import {useAnalytics} from 'lib/analytics/analytics' -import {useHaptics} from 'lib/haptics' -import {isIOS} from 'platform/detection' -import {useProfileShadow} from 'state/cache/profile-shadow' import {ProfileMenu} from '#/view/com/profile/ProfileMenu' import * as Toast from '#/view/com/util/Toast' import {atoms as a, tokens, useBreakpoints, useTheme} from '#/alf' @@ -66,7 +65,6 @@ let ProfileHeaderLabeler = ({ const {_} = useLingui() const {currentAccount, hasSession} = useSession() const {openModal} = useModalControls() - const {track} = useAnalytics() const requireAuth = useRequireAuth() const playHaptic = useHaptics() const cantSubscribePrompt = Prompt.usePromptControl() @@ -102,12 +100,10 @@ let ProfileHeaderLabeler = ({ if (likeUri) { await unlikeMod({uri: likeUri}) - track('CustomFeed:Unlike') setLikeCount(c => c - 1) setLikeUri('') } else { const res = await likeMod({uri: labeler.uri, cid: labeler.cid}) - track('CustomFeed:Like') setLikeCount(c => c + 1) setLikeUri(res.uri) } @@ -120,15 +116,14 @@ let ProfileHeaderLabeler = ({ ) logger.error(`Failed to toggle labeler like`, {message: e.message}) } - }, [labeler, playHaptic, likeUri, unlikeMod, track, likeMod, _]) + }, [labeler, playHaptic, likeUri, unlikeMod, likeMod, _]) const onPressEditProfile = React.useCallback(() => { - track('ProfileHeader:EditProfileButtonClicked') openModal({ name: 'edit-profile', profile, }) - }, [track, openModal, profile]) + }, [openModal, profile]) const onPressSubscribe = React.useCallback( () => diff --git a/src/screens/Profile/Header/ProfileHeaderStandard.tsx b/src/screens/Profile/Header/ProfileHeaderStandard.tsx index 846fa4424b..3bfc4bf2f2 100644 --- a/src/screens/Profile/Header/ProfileHeaderStandard.tsx +++ b/src/screens/Profile/Header/ProfileHeaderStandard.tsx @@ -9,8 +9,10 @@ import { import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' +import {sanitizeDisplayName} from '#/lib/strings/display-names' import {logger} from '#/logger' import {isIOS} from '#/platform/detection' +import {useProfileShadow} from '#/state/cache/profile-shadow' import {Shadow} from '#/state/cache/types' import {useModalControls} from '#/state/modals' import { @@ -18,9 +20,6 @@ import { useProfileFollowMutationQueue, } from '#/state/queries/profile' import {useRequireAuth, useSession} from '#/state/session' -import {useAnalytics} from 'lib/analytics/analytics' -import {sanitizeDisplayName} from 'lib/strings/display-names' -import {useProfileShadow} from 'state/cache/profile-shadow' import {ProfileMenu} from '#/view/com/profile/ProfileMenu' import * as Toast from '#/view/com/util/Toast' import {atoms as a} from '#/alf' @@ -59,7 +58,6 @@ let ProfileHeaderStandard = ({ const {currentAccount, hasSession} = useSession() const {_} = useLingui() const {openModal} = useModalControls() - const {track} = useAnalytics() const moderation = useMemo( () => moderateProfile(profile, moderationOpts), [profile, moderationOpts], @@ -77,17 +75,15 @@ let ProfileHeaderStandard = ({ profile.viewer?.blockingByList const onPressEditProfile = React.useCallback(() => { - track('ProfileHeader:EditProfileButtonClicked') openModal({ name: 'edit-profile', profile, }) - }, [track, openModal, profile]) + }, [openModal, profile]) const onPressFollow = () => { requireAuth(async () => { try { - track('ProfileHeader:FollowButtonClicked') await queueFollow() Toast.show( _( @@ -109,7 +105,6 @@ let ProfileHeaderStandard = ({ const onPressUnfollow = () => { requireAuth(async () => { try { - track('ProfileHeader:UnfollowButtonClicked') await queueUnfollow() Toast.show( _( @@ -129,7 +124,6 @@ let ProfileHeaderStandard = ({ } const unblockAccount = React.useCallback(async () => { - track('ProfileHeader:UnblockAccountButtonClicked') try { await queueUnblock() Toast.show(_(msg`Account unblocked`)) @@ -139,7 +133,7 @@ let ProfileHeaderStandard = ({ Toast.show(_(msg`There was an issue! ${e.toString()}`), 'xmark') } } - }, [_, queueUnblock, track]) + }, [_, queueUnblock]) const isMe = React.useMemo( () => currentAccount?.did === profile.did, diff --git a/src/screens/Signup/StepInfo/index.tsx b/src/screens/Signup/StepInfo/index.tsx index 2d4b07318d..d9b680602a 100644 --- a/src/screens/Signup/StepInfo/index.tsx +++ b/src/screens/Signup/StepInfo/index.tsx @@ -59,6 +59,9 @@ export function StepInfo({ import('tldts/dist/index.cjs.min.js').then(tldts => { tldtsRef.current = tldts }) + // This will get used in the avatar creator a few steps later, so lets preload it now + // @ts-expect-error - valid path + import('react-native-view-shot/src/index') }, []) const onNextPress = () => { diff --git a/src/screens/Signup/index.tsx b/src/screens/Signup/index.tsx index 3209800328..e3da053c09 100644 --- a/src/screens/Signup/index.tsx +++ b/src/screens/Signup/index.tsx @@ -5,7 +5,6 @@ import {AppBskyGraphStarterpack} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useAnalytics} from '#/lib/analytics/analytics' import {FEEDBACK_FORM_URL} from '#/lib/constants' import {useServiceQuery} from '#/state/queries/service' import {useStarterPackQuery} from '#/state/queries/starter-packs' @@ -31,7 +30,6 @@ import {Text} from '#/components/Typography' export function Signup({onPressBack}: {onPressBack: () => void}) { const {_} = useLingui() const t = useTheme() - const {screen} = useAnalytics() const [state, dispatch] = React.useReducer(reducer, initialState) const {gtMobile} = useBreakpoints() const submit = useSubmitSignup() @@ -56,10 +54,6 @@ export function Signup({onPressBack}: {onPressBack: () => void}) { refetch, } = useServiceQuery(state.serviceUrl) - React.useEffect(() => { - screen('CreateAccount') - }, [screen]) - React.useEffect(() => { if (isFetching) { dispatch({type: 'setIsLoading', value: true}) diff --git a/src/state/cache/post-shadow.ts b/src/state/cache/post-shadow.ts index 65300a8ef1..b456a76d97 100644 --- a/src/state/cache/post-shadow.ts +++ b/src/state/cache/post-shadow.ts @@ -21,6 +21,7 @@ export interface PostShadow { repostUri: string | undefined isDeleted: boolean embed: AppBskyEmbedRecord.View | AppBskyEmbedRecordWithMedia.View | undefined + pinned: boolean } export const POST_TOMBSTONE = Symbol('PostTombstone') @@ -113,6 +114,7 @@ function mergeShadow( ...(post.viewer || {}), like: 'likeUri' in shadow ? shadow.likeUri : post.viewer?.like, repost: 'repostUri' in shadow ? shadow.repostUri : post.viewer?.repost, + pinned: 'pinned' in shadow ? shadow.pinned : post.viewer?.pinned, }, }) } diff --git a/src/state/queries/pinned-post.ts b/src/state/queries/pinned-post.ts new file mode 100644 index 0000000000..7e2c8ee798 --- /dev/null +++ b/src/state/queries/pinned-post.ts @@ -0,0 +1,87 @@ +import {msg} from '@lingui/macro' +import {useLingui} from '@lingui/react' +import {useMutation, useQueryClient} from '@tanstack/react-query' + +import {logger} from '#/logger' +import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed' +import * as Toast from '#/view/com/util/Toast' +import {updatePostShadow} from '../cache/post-shadow' +import {useAgent, useSession} from '../session' +import {useProfileUpdateMutation} from './profile' + +export function usePinnedPostMutation() { + const {_} = useLingui() + const {currentAccount} = useSession() + const agent = useAgent() + const queryClient = useQueryClient() + const {mutateAsync: profileUpdateMutate} = useProfileUpdateMutation() + + return useMutation({ + mutationFn: async ({ + postUri, + postCid, + action, + }: { + postUri: string + postCid: string + action: 'pin' | 'unpin' + }) => { + const pinCurrentPost = action === 'pin' + let prevPinnedPost: string | undefined + try { + updatePostShadow(queryClient, postUri, {pinned: pinCurrentPost}) + + // get the currently pinned post so we can optimistically remove the pin from it + if (!currentAccount) throw new Error('Not logged in') + const {data: profile} = await agent.getProfile({ + actor: currentAccount.did, + }) + prevPinnedPost = profile.pinnedPost?.uri + if (prevPinnedPost && prevPinnedPost !== postUri) { + updatePostShadow(queryClient, prevPinnedPost, {pinned: false}) + } + + await profileUpdateMutate({ + profile, + updates: existing => { + existing.pinnedPost = pinCurrentPost + ? {uri: postUri, cid: postCid} + : undefined + return existing + }, + checkCommitted: res => + pinCurrentPost + ? res.data.pinnedPost?.uri === postUri + : !res.data.pinnedPost, + }) + + if (pinCurrentPost) { + Toast.show(_(msg`Post pinned`)) + } else { + Toast.show(_(msg`Post unpinned`)) + } + + queryClient.invalidateQueries({ + queryKey: FEED_RQKEY( + `author|${currentAccount.did}|posts_and_author_threads`, + ), + }) + queryClient.invalidateQueries({ + queryKey: FEED_RQKEY( + `author|${currentAccount.did}|posts_with_replies`, + ), + }) + } catch (e: any) { + Toast.show(_(msg`Failed to pin post`)) + logger.error('Failed to pin post', {message: String(e)}) + // revert optimistic update + updatePostShadow(queryClient, postUri, { + pinned: !pinCurrentPost, + }) + if (prevPinnedPost && prevPinnedPost !== postUri) { + updatePostShadow(queryClient, prevPinnedPost, {pinned: true}) + } + } + }, + }) +} diff --git a/src/state/queries/post-feed.ts b/src/state/queries/post-feed.ts index 07c5da81b7..1785eb445f 100644 --- a/src/state/queries/post-feed.ts +++ b/src/state/queries/post-feed.ts @@ -91,6 +91,7 @@ export interface FeedPostSlice { feedContext: string | undefined reason?: | AppBskyFeedDefs.ReasonRepost + | AppBskyFeedDefs.ReasonPin | ReasonFeedSource | {[k: string]: unknown; $type: string} } diff --git a/src/state/queries/post.ts b/src/state/queries/post.ts index 982d224aee..7023580bbe 100644 --- a/src/state/queries/post.ts +++ b/src/state/queries/post.ts @@ -2,7 +2,6 @@ import {useCallback} from 'react' import {AppBskyActorDefs, AppBskyFeedDefs, AtUri} from '@atproto/api' import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' -import {track} from '#/lib/analytics/analytics' import {useToggleMutationQueue} from '#/lib/hooks/useToggleMutationQueue' import {logEvent, LogEvents, toClout} from '#/lib/statsig/statsig' import {updatePostShadow} from '#/state/cache/post-shadow' @@ -193,9 +192,6 @@ function usePostLikeMutation( }) return agent.like(uri, cid) }, - onSuccess() { - track('Post:Like') - }, }) } @@ -208,9 +204,6 @@ function usePostUnlikeMutation( logEvent('post:unlike:sampled', {logContext}) return agent.deleteLike(likeUri) }, - onSuccess() { - track('Post:Unlike') - }, }) } @@ -285,9 +278,6 @@ function usePostRepostMutation( logEvent('post:repost:sampled', {logContext}) return agent.repost(post.uri, post.cid) }, - onSuccess() { - track('Post:Repost') - }, }) } @@ -300,9 +290,6 @@ function usePostUnrepostMutation( logEvent('post:unrepost:sampled', {logContext}) return agent.deleteRepost(repostUri) }, - onSuccess() { - track('Post:Unrepost') - }, }) } @@ -313,9 +300,8 @@ export function usePostDeleteMutation() { mutationFn: async ({uri}) => { await agent.deletePost(uri) }, - onSuccess(data, variables) { + onSuccess(_, variables) { updatePostShadow(queryClient, variables.uri, {isDeleted: true}) - track('Post:Delete') }, }) } diff --git a/src/state/queries/preferences/index.ts b/src/state/queries/preferences/index.ts index ab866d5e2a..3cb121a470 100644 --- a/src/state/queries/preferences/index.ts +++ b/src/state/queries/preferences/index.ts @@ -5,7 +5,6 @@ import { } from '@atproto/api' import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' -import {track} from '#/lib/analytics/analytics' import {PROD_DEFAULT_FEED} from '#/lib/constants' import {replaceEqualDeep} from '#/lib/functions' import {getAge} from '#/lib/strings/time' @@ -218,7 +217,6 @@ export function useAddSavedFeedsMutation() { >({ mutationFn: async savedFeeds => { await agent.addSavedFeeds(savedFeeds) - track('CustomFeed:Save') // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -234,7 +232,6 @@ export function useRemoveFeedMutation() { return useMutation>({ mutationFn: async savedFeed => { await agent.removeSavedFeeds([savedFeed.id]) - track('CustomFeed:Unsave') // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, diff --git a/src/state/queries/profile.ts b/src/state/queries/profile.ts index 532b005cf4..3059d9efea 100644 --- a/src/state/queries/profile.ts +++ b/src/state/queries/profile.ts @@ -16,7 +16,6 @@ import { useQueryClient, } from '@tanstack/react-query' -import {track} from '#/lib/analytics/analytics' import {uploadBlob} from '#/lib/api' import {until} from '#/lib/async/until' import {useToggleMutationQueue} from '#/lib/hooks/useToggleMutationQueue' @@ -160,6 +159,9 @@ export function useProfileUpdateMutation() { } else { existing.displayName = updates.displayName existing.description = updates.description + if ('pinnedPost' in updates) { + existing.pinnedPost = updates.pinnedPost + } } if (newUserAvatarPromise) { const res = await newUserAvatarPromise @@ -316,9 +318,6 @@ function useProfileFollowMutation( }) return await agent.follow(did) }, - onSuccess(data, variables) { - track('Profile:Follow', {username: variables.did}) - }, }) } @@ -329,7 +328,6 @@ function useProfileUnfollowMutation( return useMutation({ mutationFn: async ({followUri}) => { logEvent('profile:unfollow:sampled', {logContext}) - track('Profile:Unfollow', {username: followUri}) return await agent.deleteFollow(followUri) }, }) diff --git a/src/state/queries/suggested-follows.ts b/src/state/queries/suggested-follows.ts index 5ae8317047..07e16946e7 100644 --- a/src/state/queries/suggested-follows.ts +++ b/src/state/queries/suggested-follows.ts @@ -105,17 +105,16 @@ export function useSuggestedFollowsQuery(options?: SuggestedFollowsOptions) { export function useSuggestedFollowsByActorQuery({did}: {did: string}) { const agent = useAgent() - return useQuery({ + return useQuery({ queryKey: suggestedFollowsByActorQueryKey(did), queryFn: async () => { const res = await agent.app.bsky.graph.getSuggestedFollowsByActor({ actor: did, }) - const data = res.data.isFallback ? {suggestions: []} : res.data - data.suggestions = data.suggestions.filter(profile => { - return !profile.viewer?.following - }) - return data + const suggestions = res.data.isFallback + ? [] + : res.data.suggestions.filter(profile => !profile.viewer?.following) + return {suggestions} }, }) } diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx index 21fe7f75b9..ab3352bf3a 100644 --- a/src/state/session/index.tsx +++ b/src/state/session/index.tsx @@ -1,7 +1,6 @@ import React from 'react' import {AtpSessionEvent, BskyAgent} from '@atproto/api' -import {track} from '#/lib/analytics/analytics' import {logEvent} from '#/lib/statsig/statsig' import {isWeb} from '#/platform/detection' import * as persisted from '#/state/persisted' @@ -70,7 +69,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) { async params => { addSessionDebugLog({type: 'method:start', method: 'createAccount'}) const signal = cancelPendingTask() - track('Try Create Account') logEvent('account:create:begin', {}) const {agent, account} = await createAgentAndCreateAccount( params, @@ -85,7 +83,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) { newAgent: agent, newAccount: account, }) - track('Create Account') logEvent('account:create:success', {}) addSessionDebugLog({type: 'method:end', method: 'createAccount', account}) }, @@ -109,7 +106,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) { newAgent: agent, newAccount: account, }) - track('Sign In', {resumedSession: false}) logEvent('account:loggedIn', {logContext, withPassword: true}) addSessionDebugLog({type: 'method:end', method: 'login', account}) }, diff --git a/src/state/shell/onboarding.tsx b/src/state/shell/onboarding.tsx index d3a8fec466..9aad9953d4 100644 --- a/src/state/shell/onboarding.tsx +++ b/src/state/shell/onboarding.tsx @@ -1,6 +1,5 @@ import React from 'react' -import {track} from '#/lib/analytics/analytics' import * as persisted from '#/state/persisted' export const OnboardingScreenSteps = { @@ -55,17 +54,14 @@ function reducer(state: StateContext, action: Action): StateContext { return compute({...state, step: nextStep}) } case 'start': { - track('Onboarding:Begin') persisted.write('onboarding', {step: 'Welcome'}) return compute({...state, step: 'Welcome'}) } case 'finish': { - track('Onboarding:Complete') persisted.write('onboarding', {step: 'Home'}) return compute({...state, step: 'Home'}) } case 'skip': { - track('Onboarding:Skipped') persisted.write('onboarding', {step: 'Home'}) return compute({...state, step: 'Home'}) } diff --git a/src/view/com/auth/LoggedOut.tsx b/src/view/com/auth/LoggedOut.tsx index cc57238053..5b9e3932f9 100644 --- a/src/view/com/auth/LoggedOut.tsx +++ b/src/view/com/auth/LoggedOut.tsx @@ -4,7 +4,6 @@ import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useAnalytics} from '#/lib/analytics/analytics' import {usePalette} from '#/lib/hooks/usePalette' import {logEvent} from '#/lib/statsig/statsig' import {s} from '#/lib/styles' @@ -32,7 +31,6 @@ export function LoggedOut({onDismiss}: {onDismiss?: () => void}) { const {_} = useLingui() const pal = usePalette('default') const setMinimalShellMode = useSetMinimalShellMode() - const {screen} = useAnalytics() const {requestedAccountSwitchTo} = useLoggedOutView() const [screenState, setScreenState] = React.useState(() => { if (requestedAccountSwitchTo === 'new') { @@ -48,9 +46,8 @@ export function LoggedOut({onDismiss}: {onDismiss?: () => void}) { const {clearRequestedAccount} = useLoggedOutViewControls() React.useEffect(() => { - screen('Login') setMinimalShellMode(true) - }, [screen, setMinimalShellMode]) + }, [setMinimalShellMode]) const onPressDismiss = React.useCallback(() => { if (onDismiss) { diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 49ce0d4428..ade37af1b6 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -45,7 +45,6 @@ import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useAnalytics} from '#/lib/analytics/analytics' import * as apilib from '#/lib/api/index' import {until} from '#/lib/async/until' import {MAX_GRAPHEME_LENGTH} from '#/lib/constants' @@ -147,7 +146,6 @@ export const ComposePost = ({ const {data: currentProfile} = useProfileQuery({did: currentAccount!.did}) const {isModalActive} = useModals() const {closeComposer} = useComposerControls() - const {track} = useAnalytics() const pal = usePalette('default') const {isMobile} = useWebMediaQueries() const {_} = useLingui() @@ -310,7 +308,6 @@ export const ComposePost = ({ const onPhotoPasted = useCallback( async (uri: string) => { - track('Composer:PastedPhotos') if (uri.startsWith('data:video/')) { selectVideo({uri, type: 'video', height: 0, width: 0}) } else { @@ -318,7 +315,7 @@ export const ComposePost = ({ onImageAdd([res]) } }, - [track, selectVideo, onImageAdd], + [selectVideo, onImageAdd], ) const isAltTextRequiredAndMissing = useMemo(() => { @@ -446,10 +443,6 @@ export const ComposePost = ({ logContext: 'Composer', }) } - track('Create Post', { - imageCount: images.length, - }) - if (replyTo && replyTo.uri) track('Post:Reply') } if (postUri && !replyTo) { emitPostCreated() @@ -499,7 +492,6 @@ export const ComposePost = ({ setExtLink, setLangPrefs, threadgateAllowUISettings, - track, videoAltText, videoUploadState.asset, videoUploadState.pendingPublish, diff --git a/src/view/com/composer/photos/OpenCameraBtn.tsx b/src/view/com/composer/photos/OpenCameraBtn.tsx index 2183ca7902..79d59a92d1 100644 --- a/src/view/com/composer/photos/OpenCameraBtn.tsx +++ b/src/view/com/composer/photos/OpenCameraBtn.tsx @@ -3,7 +3,6 @@ import * as MediaLibrary from 'expo-media-library' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useAnalytics} from '#/lib/analytics/analytics' import {POST_IMG_MAX} from '#/lib/constants' import {useCameraPermission} from '#/lib/hooks/usePermissions' import {openCamera} from '#/lib/media/picker' @@ -20,7 +19,6 @@ type Props = { } export function OpenCameraBtn({disabled, onAdd}: Props) { - const {track} = useAnalytics() const {_} = useLingui() const {requestCameraAccessIfNeeded} = useCameraPermission() const [mediaPermissionRes, requestMediaPermission] = @@ -28,7 +26,6 @@ export function OpenCameraBtn({disabled, onAdd}: Props) { const t = useTheme() const onPressTakePicture = useCallback(async () => { - track('Composer:CameraOpened') try { if (!(await requestCameraAccessIfNeeded())) { return @@ -58,7 +55,6 @@ export function OpenCameraBtn({disabled, onAdd}: Props) { } }, [ onAdd, - track, requestCameraAccessIfNeeded, mediaPermissionRes, requestMediaPermission, diff --git a/src/view/com/composer/photos/SelectPhotoBtn.tsx b/src/view/com/composer/photos/SelectPhotoBtn.tsx index 95d2df022c..34ead3d9a9 100644 --- a/src/view/com/composer/photos/SelectPhotoBtn.tsx +++ b/src/view/com/composer/photos/SelectPhotoBtn.tsx @@ -3,7 +3,6 @@ import React, {useCallback} from 'react' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useAnalytics} from '#/lib/analytics/analytics' import {usePhotoLibraryPermission} from '#/lib/hooks/usePermissions' import {openPicker} from '#/lib/media/picker' import {isNative} from '#/platform/detection' @@ -19,14 +18,11 @@ type Props = { } export function SelectPhotoBtn({size, disabled, onAdd}: Props) { - const {track} = useAnalytics() const {_} = useLingui() const {requestPhotoAccessIfNeeded} = usePhotoLibraryPermission() const t = useTheme() const onPressSelectPhotos = useCallback(async () => { - track('Composer:GalleryOpened') - if (isNative && !(await requestPhotoAccessIfNeeded())) { return } @@ -41,7 +37,7 @@ export function SelectPhotoBtn({size, disabled, onAdd}: Props) { ) onAdd(results) - }, [track, requestPhotoAccessIfNeeded, size, onAdd]) + }, [requestPhotoAccessIfNeeded, size, onAdd]) return (