mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-04 14:53:33 -04:00
Display toast notifications for push messages with navigation fixes
This commit is contained in:
@@ -11,7 +11,7 @@ android {
|
||||
applicationId "com.compassconnections.app"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 83
|
||||
versionCode 84
|
||||
versionName "1.17.0"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
aaptOptions {
|
||||
|
||||
@@ -238,7 +238,16 @@ public class MainActivity extends BridgeActivity implements ModifiedMainActivity
|
||||
checkForUpdates();
|
||||
|
||||
Uri data = getIntent().getData();
|
||||
if (data != null) pendingDeepLink = data.toString();
|
||||
if (data != null) {
|
||||
pendingDeepLink = data.toString();
|
||||
} else {
|
||||
// Check for notification endpoint when app is opened from cold start via notification click
|
||||
String endpoint = getIntent().getStringExtra("endpoint");
|
||||
if (endpoint != null) {
|
||||
Log.i("CompassApp", "onCreate found endpoint from notification: " + endpoint);
|
||||
pendingDeepLink = endpoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDeepLink(String url) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {PushNotifications} from '@capacitor/push-notifications'
|
||||
import {debug} from 'common/logger'
|
||||
import {useRouter} from 'next/router'
|
||||
import {useEffect} from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import {useUser} from 'web/hooks/use-user'
|
||||
import {api} from 'web/lib/api'
|
||||
import {isAndroidApp} from 'web/lib/util/webview'
|
||||
@@ -9,7 +9,6 @@ import {isAndroidApp} from 'web/lib/util/webview'
|
||||
export default function AndroidPush() {
|
||||
const user = useUser() // authenticated user
|
||||
const isAndroid = isAndroidApp()
|
||||
const router = useRouter()
|
||||
useEffect(() => {
|
||||
if (!user?.id || !isAndroid) return
|
||||
debug('AndroidPush', user)
|
||||
@@ -36,12 +35,14 @@ export default function AndroidPush() {
|
||||
})
|
||||
|
||||
PushNotifications.addListener('pushNotificationReceived', (notif) => {
|
||||
debug('Push received', notif)
|
||||
const url = notif?.data?.url
|
||||
if (url) {
|
||||
router.push(url)
|
||||
window.location.href = url
|
||||
}
|
||||
console.debug('Push received', notif, window.location.pathname)
|
||||
const endpoint = notif?.data?.endpoint as string
|
||||
if (!endpoint) return
|
||||
if (!endpoint.startsWith('/messages/')) return
|
||||
if (endpoint === window.location.pathname) return
|
||||
const author = notif?.title
|
||||
const message = notif?.body
|
||||
toast.success(`${author}: "${message}"`)
|
||||
})
|
||||
}, [user?.id, isAndroid])
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import clsx from 'clsx'
|
||||
import {DEPLOYED_WEB_URL} from 'common/envs/constants'
|
||||
import {IS_VERCEL, PNG_FAVICON} from 'common/hosting/constants'
|
||||
import {debug} from 'common/logger'
|
||||
import {isUrl} from 'common/parsing'
|
||||
import type {AppProps} from 'next/app'
|
||||
import {Major_Mono_Display} from 'next/font/google'
|
||||
import Head from 'next/head'
|
||||
@@ -164,7 +165,7 @@ function MyApp(props: AppProps<PageProps>) {
|
||||
|
||||
const link = window.AndroidBridge?.getPendingDeepLink?.()
|
||||
if (link) {
|
||||
handleAppLink({url: link, endpoint: new URL(link).pathname})
|
||||
handleAppLink({endpoint: isUrl(link) ? new URL(link).pathname : link})
|
||||
}
|
||||
}, [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user