From c5c616e3dcc8926663bf3a8104ab02275a604782 Mon Sep 17 00:00:00 2001 From: xmflsct Date: Wed, 16 Aug 2023 23:47:00 +0200 Subject: [PATCH] Fix #754 --- src/screens/Tabs/Me/Push.tsx | 22 +++++++--- src/screens/Tabs/Me/Settings/Dev.tsx | 15 ++++++- src/utils/push/updateExpoToken.ts | 31 ++++++++------ src/utils/push/useConnect.ts | 60 ++++++++++++++++++++++++++-- 4 files changed, 104 insertions(+), 24 deletions(-) diff --git a/src/screens/Tabs/Me/Push.tsx b/src/screens/Tabs/Me/Push.tsx index 5cb54529..191ee5d3 100644 --- a/src/screens/Tabs/Me/Push.tsx +++ b/src/screens/Tabs/Me/Push.tsx @@ -23,6 +23,20 @@ import { useTranslation } from 'react-i18next' import { AppState, Linking, Platform, ScrollView, View } from 'react-native' import { fromByteArray } from 'react-native-quick-base64' +export const getPushPath = ({ + expoToken, + domain, + accountId +}: { + expoToken?: string + domain: string + accountId: string | number +}) => `${expoToken}/${domain}/${accountId}` +export const getPushendpoint = (pushPath: string) => + `https://${TOOOT_API_DOMAIN}/push/send/${pushPath}/${(Math.random() + 1) + .toString(36) + .substring(2)}` + const TabMePush: React.FC = () => { const { colors } = useTheme() const { t } = useTranslation('screenTabs') @@ -116,7 +130,7 @@ const TabMePush: React.FC = () => { )) : null - const pushPath = `${expoToken}/${domain}/${accountId}` + const pushPath = getPushPath({ expoToken, domain, accountId }) const accountFull = `@${accountAcct}@${accountDomain}` return appsQuery.isFetched ? ( @@ -176,17 +190,13 @@ const TabMePush: React.FC = () => { if (push.key?.length <= 10) { authKey = fromByteArray(Crypto.getRandomBytes(16)) } - // Turning on - const randomPath = (Math.random() + 1).toString(36).substring(2) - - const endpoint = `https://${TOOOT_API_DOMAIN}/push/send/${pushPath}/${randomPath}` const body: { subscription: any data: { alerts: Mastodon.PushSubscription['alerts'] } } = { subscription: { - endpoint, + endpoint: getPushendpoint(pushPath), keys: { p256dh: 'BMn2PLpZrMefG981elzG6SB1EY9gU7QZwmtZ/a/J2vUeWG+zXgeskMPwHh4T/bxsD4l7/8QT94F57CbZqYRRfJo=', diff --git a/src/screens/Tabs/Me/Settings/Dev.tsx b/src/screens/Tabs/Me/Settings/Dev.tsx index 4ea81e24..59fafd39 100644 --- a/src/screens/Tabs/Me/Settings/Dev.tsx +++ b/src/screens/Tabs/Me/Settings/Dev.tsx @@ -6,7 +6,7 @@ import { useNavigation } from '@react-navigation/native' import { androidActionSheetStyles } from '@utils/helpers/androidActionSheetStyles' import { urlMatcher } from '@utils/helpers/urlMatcher' import { storage } from '@utils/storage' -import { getGlobalStorage, useGlobalStorage } from '@utils/storage/actions' +import { getGlobalStorage, setGlobalStorage, useGlobalStorage } from '@utils/storage/actions' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import React from 'react' @@ -59,6 +59,17 @@ const SettingsDev: React.FC = () => { }} onPress={() => displayMessage({ message: 'This is a testing message' })} /> +