fix:重复点击
This commit is contained in:
@@ -5,7 +5,13 @@ import { Platform } from 'react-native';
|
||||
|
||||
import { httpJson } from '../utils/http';
|
||||
import { APP_ENV } from '../constants/env';
|
||||
import { getDailyReminderSettings, getOrCreateClientUserId, getUserProfileScoring } from '../storage/appStorage';
|
||||
import {
|
||||
getDailyReminderSettings,
|
||||
getLastRegisteredPushToken,
|
||||
getOrCreateClientUserId,
|
||||
getUserProfileScoring,
|
||||
setLastRegisteredPushToken,
|
||||
} from '../storage/appStorage';
|
||||
import type { UserProfileScoring } from '../storage/appStorage';
|
||||
import { toBackendLocaleFromLanguageTag } from '../i18n/locale';
|
||||
|
||||
@@ -154,6 +160,22 @@ export async function registerPushToken(args: { pushToken: string }): Promise<vo
|
||||
});
|
||||
}
|
||||
|
||||
export async function ensurePushTokenRegisteredIfPermitted(): Promise<{ ok: boolean; reason: string }> {
|
||||
// 只要系统权限已授权,就应尽早把 token 写入后端(不依赖用户在“每日提醒”里点确认)
|
||||
const settings = await Notifications.getPermissionsAsync();
|
||||
if (settings.status !== 'granted') return { ok: false, reason: 'permission_not_granted' };
|
||||
|
||||
const token = await getExpoPushTokenOrThrow();
|
||||
|
||||
// 简单去重:token 未变化则不重复上报(减少网络与日志噪音)
|
||||
const last = await getLastRegisteredPushToken().catch(() => null);
|
||||
if (last && String(last) === String(token)) return { ok: true, reason: 'already_registered' };
|
||||
|
||||
await registerPushToken({ pushToken: token });
|
||||
await setLastRegisteredPushToken(token);
|
||||
return { ok: true, reason: 'registered' };
|
||||
}
|
||||
|
||||
export async function setPushPreferences(args: { enabled: boolean; timesPerDay: number }): Promise<PushPreferencesResponse> {
|
||||
const clientUserId = await getOrCreateClientUserId();
|
||||
const tz = pickTimezone();
|
||||
|
||||
Reference in New Issue
Block a user