diff --git a/expo/features/app/user/internals/UserRoot.tsx b/expo/features/app/user/internals/UserRoot.tsx index 9a949376..6f630205 100644 --- a/expo/features/app/user/internals/UserRoot.tsx +++ b/expo/features/app/user/internals/UserRoot.tsx @@ -1,17 +1,12 @@ import { useCurrentUser, useUserConfig } from '@hpapp/features/app/settings'; import { Initializer, Loading } from '@hpapp/features/common'; import { Screen, ScreenParams, createStackNavigator } from '@hpapp/features/common/stack'; -import { - usePushNotificationToken, - usePushNotificationTokenUpdator, - PushNotificationData, - PushNotificationHandler -} from '@hpapp/features/push'; +import { usePushNotificationToken, usePushNotificationTokenUpdator } from '@hpapp/features/push'; import { logScreenView, useSetUserId } from '@hpapp/system/firebase'; import * as logging from '@hpapp/system/logging'; import { init as initURICache } from '@hpapp/system/uricache'; import { useNavigationContainerRef } from '@react-navigation/native'; -import { useCallback, useEffect } from 'react'; +import { useEffect } from 'react'; import UserError from './UserError'; import UserServiceProvider from './UserServiceProvider'; @@ -24,16 +19,11 @@ const Stack = createStackNavigator({ const initializers = [initURICache]; const Screens: Screen[] = []; -// TODO: genscreen should create this param types as well. -type PushNotificationParams = { - '/feed/item/': { feedId: string }; -}; - export type UserRootProps = { screens?: Screen[] }; export default function UserRoot({ screens = Screens }: UserRootProps) { const userConfig = useUserConfig(); - const navigation = useNavigationContainerRef(); + const navigation = useNavigationContainerRef(); const token = usePushNotificationToken(); const [tokenUpdator] = usePushNotificationTokenUpdator(); useEffect(() => { @@ -43,52 +33,22 @@ export default function UserRoot({ screens = Screens }: UserRootProps) { }, [token.data]); const currentUser = useCurrentUser(); useSetUserId(currentUser?.id ?? null); - const onData = useCallback((data: PushNotificationData) => { - // TODO: if navigation is not ready, we should wait for it, and navigate after it's ready. - const nav = navigation?.current; - if (nav === null) { - return; - } - if (!nav.isReady()) { - return; - } - - // we need a compatibility of payload with v2 implementation - // == Ameblo Notification payload example - // { - // "params": { - // "id": 94489510263, - // "memberKey": "yukiho_shimoitani", - // "path": "/angerme-new/entry-12876844045.html", - // "post_id": 12889971534 - // }, - // "path": "/ameblo/post/" - // } - if (data.body.payload.path === '/ameblo/post/') { - nav.navigate('/feed/item/', { feedId: data.body.payload.params.id }); - return; - } - // in v3, the server should send path and params so that we don't have to handle details. - nav.navigate(data.body.payload.path, data.body.payload.params); - }, []); return ( }> - - { - logScreenView(state.screen.name); - logging.Info('features.app.user.onStateChagne', `to ${state.screen.name}`, { - name: state.screen.name, - path: state.screen.path, - params: state.params - }); - }} - /> - + { + logScreenView(state.screen.name); + logging.Info('features.app.user.onStateChagne', `to ${state.screen.name}`, { + name: state.screen.name, + path: state.screen.path, + params: state.params + }); + }} + /> ); diff --git a/expo/features/devtool/DevtoolScreen.tsx b/expo/features/devtool/DevtoolScreen.tsx index 68facf0e..9b8e6b9e 100644 --- a/expo/features/devtool/DevtoolScreen.tsx +++ b/expo/features/devtool/DevtoolScreen.tsx @@ -4,7 +4,6 @@ import { useThemeColor } from '@hpapp/features/app/theme'; import { AuthGateByRole } from '@hpapp/features/auth'; import { Text } from '@hpapp/features/common'; import { defineScreen } from '@hpapp/features/common/stack'; -import { usePushNotificationToken } from '@hpapp/features/push'; import { getAppCheckToken } from '@hpapp/system/firebase'; import { t } from '@hpapp/system/i18n'; import { Divider, ListItem } from '@rneui/themed'; @@ -20,8 +19,6 @@ export default defineScreen('/devtool/', function DevtoolScreen() { const appConfig = useAppConfig(); const userConfig = useUserConfig(); const [appCheckToken, setAppCheckToken] = useState(null); - const pushToken = usePushNotificationToken(); - useEffect(() => { (async () => { setAppCheckToken((await getAppCheckToken()).token); @@ -52,15 +49,6 @@ export default defineScreen('/devtool/', function DevtoolScreen() { displayValue={(appCheckToken ?? '').substring(0, 20) + '****'} /> - - - diff --git a/expo/features/feed/FeedItemScreen.tsx b/expo/features/feed/FeedItemScreen.tsx index 23535f6f..0b1a873c 100644 --- a/expo/features/feed/FeedItemScreen.tsx +++ b/expo/features/feed/FeedItemScreen.tsx @@ -9,7 +9,7 @@ export type FeedItemScreenProps = { feedId: string; }; -export default defineScreen('/feed/item/', function FeedItemScreen(props: FeedItemScreenProps) { +export default defineScreen('/feed/', function FeedItemScreen(props: FeedItemScreenProps) { return ( }> diff --git a/expo/features/push/index.tsx b/expo/features/push/index.tsx index bf22e043..26a844e8 100644 --- a/expo/features/push/index.tsx +++ b/expo/features/push/index.tsx @@ -1,4 +1,4 @@ -import PushNotificationHandler, { PushNotificationData } from './internals/PushNotificationHandler'; import usePushNotificationToken from './internals/usePushNotificationToken'; import usePushNotificationTokenUpdator from './internals/usePushNotificationTokenUpdator'; -export { usePushNotificationToken, usePushNotificationTokenUpdator, PushNotificationHandler, PushNotificationData }; + +export { usePushNotificationToken, usePushNotificationTokenUpdator }; diff --git a/expo/features/push/internals/PushNotificationHandler.tsx b/expo/features/push/internals/PushNotificationHandler.tsx deleted file mode 100644 index 0a054f8a..00000000 --- a/expo/features/push/internals/PushNotificationHandler.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import { logEvent } from '@hpapp/system/firebase'; -import * as Notifications from 'expo-notifications'; -import React, { useEffect, useRef } from 'react'; - -type Subscription = ReturnType; - -export type PushNotificationData = { - id: string; - timestamp: Date; - body: { - type: string; - payload: { [key: string]: any }; - }; -}; - -export type PushNotificationHandlerProps = { - children: React.ReactElement; - onData?: (data: PushNotificationData) => void; -}; - -export default function PushNotificationHandler({ children, onData }: PushNotificationHandlerProps) { - const responseSubscription = useRef(); - useEffect(() => { - (async () => { - responseSubscription.current = Notifications.addNotificationResponseReceivedListener((response) => { - const body = response.notification.request.content.data as { - type: string; - payload: string; - }; - logEvent('respond_to_notification', { - body - }); - onData?.({ - id: response.notification.request.identifier, - timestamp: new Date(response.notification.date), - body: { - type: body.type, - payload: JSON.parse(body.payload) - } - }); - }); - return () => { - if (responseSubscription.current) { - Notifications.removeNotificationSubscription(responseSubscription.current); - } - }; - })(); - }, [onData]); - return <>{children}; -} diff --git a/expo/jest.setup.tsx b/expo/jest.setup.tsx index 044156e5..26e7ff89 100644 --- a/expo/jest.setup.tsx +++ b/expo/jest.setup.tsx @@ -218,5 +218,4 @@ jest.mock('@hpapp/features/app/storybook', () => { } }; }); - jest.setTimeout(30000); diff --git a/go/service/push/notification.go b/go/service/push/notification.go index 0440b130..a1a7b6f3 100644 --- a/go/service/push/notification.go +++ b/go/service/push/notification.go @@ -8,7 +8,6 @@ import ( "github.com/yssk22/hpapp/go/foundation/slice" "github.com/yssk22/hpapp/go/service/ent" - "github.com/yssk22/hpapp/go/service/ent/usernotificationlog" "github.com/yssk22/hpapp/go/service/ent/usernotificationsetting" "github.com/yssk22/hpapp/go/service/entutil" "github.com/yssk22/hpapp/go/service/schema/enums" @@ -134,28 +133,20 @@ func Deliver(ctx context.Context, notif Notification, options ...DeliveryOption) fmt.Println(receivers) entclient := entutil.NewClient(ctx) - isTest := len(o.TestTokens) > 0 record, err := entclient.UserNotificationLog.Create(). SetKey(key). SetTrigger(trigger). SetReactNavigationMessage(*message). - SetIsTest(isTest). + SetIsTest(len(o.TestTokens) > 0). SetStatus(enums.UserNotificationStatusPrepared). SetExpectedDeliveryTime(expectedTime). AddReceivers(receivers...). Save(ctx) if err != nil { - if !ent.IsConstraintError(err) { - return nil, err - } - // ignore duplicate notification if it's test - if !isTest { + if ent.IsConstraintError(err) { return nil, ErrDuplicateNotification } - record, err = entclient.UserNotificationLog.Query().Where(usernotificationlog.KeyEQ(key), usernotificationlog.TriggerEQ(trigger)).WithReceivers().First(ctx) - if err != nil { - return nil, err - } + return nil, err } messages, err := buildPushMessage(ctx, record) var status enums.UserNotificationStatus