feat(native): the app asks for notifications by itself, once

A moment after signing in, the app asks whether to turn notifications on, once per device and only where the server offers push and the device is not signed up yet. Turning them on goes the way of the settings card, which brings up the system's question. iOS asked only when someone found that card.
This commit is contained in:
Maurice
2026-11-08 11:05:07 +01:00
parent 236b4c34ac
commit 6a60fc183a
32 changed files with 343 additions and 1 deletions
+15 -1
View File
@@ -1,4 +1,5 @@
import type { PushSubscriptionInput, PushUnsubscribeRequest } from '@trek/shared'
import { WEB_PUSH_CHANNEL_ID, type PushSubscriptionInput, type PushUnsubscribeRequest } from '@trek/shared'
import { notificationsApi } from '../api/client'
import { pushApi } from '../api/push'
import { isEffectivelyOffline } from '../sync/networkMode'
import { isIosDevice, isIosStandalone } from '../utils/iosDevice'
@@ -178,6 +179,19 @@ export async function loadPushPublicKey(): Promise<string | null> {
}
/** What the settings card shows for this device. Never rejects. */
/**
* Whether this server offers push to its users: the admin has the channel on
* and the server can sign. The same answer the settings' push card goes by.
*/
export async function pushChannelOffered(): Promise<boolean> {
try {
const matrix = (await notificationsApi.getPreferences()) as { channels?: { id: string; active?: boolean }[] }
return matrix.channels?.some((ch) => ch.id === WEB_PUSH_CHANNEL_ID && ch.active) ?? false
} catch {
return false
}
}
export async function readWebPushDeviceState(): Promise<WebPushDeviceState> {
if (nativePushActive()) return nativePushEndpoint() ? 'on' : 'off'
const { reason } = getWebPushSupport()