feat(challenges): 新增挑战鼓励提醒后台任务与通知支持
- 在 backgroundTaskManager 中增加 executeChallengeReminderTask,每日检查已加入且未打卡的挑战并发送鼓励通知 - 扩展 ChallengeNotificationHelpers 提供 sendEncouragementNotification 方法 - 新增 NotificationTypes.CHALLENGE_ENCOURAGEMENT 及对应点击跳转处理 - challengesApi 补充 checkedInToday 字段用于判断今日是否已打卡 - 临时注释掉挑战列表与详情页头部的礼物/分享按钮,避免干扰主流程
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as Notifications from 'expo-notifications';
|
||||
import { NotificationData, notificationService } from '../services/notifications';
|
||||
import { NotificationData, NotificationTypes, notificationService } from '../services/notifications';
|
||||
import { getNotificationEnabled } from './userPreferences';
|
||||
|
||||
/**
|
||||
@@ -287,6 +287,33 @@ export class GoalNotificationHelpers {
|
||||
}
|
||||
}
|
||||
|
||||
export class ChallengeNotificationHelpers {
|
||||
static buildChallengesTabUrl(): string {
|
||||
return '/(tabs)/challenges';
|
||||
}
|
||||
|
||||
static async sendEncouragementNotification(params: {
|
||||
userName: string;
|
||||
challengeTitle: string;
|
||||
challengeId: string;
|
||||
}): Promise<string> {
|
||||
const { userName, challengeTitle, challengeId } = params;
|
||||
const notification: NotificationData = {
|
||||
title: '挑战提醒',
|
||||
body: `${userName},今天还没有完成「${challengeTitle}」挑战,快来打卡吧!`,
|
||||
data: {
|
||||
type: NotificationTypes.CHALLENGE_ENCOURAGEMENT,
|
||||
challengeId,
|
||||
url: ChallengeNotificationHelpers.buildChallengesTabUrl(),
|
||||
},
|
||||
sound: true,
|
||||
priority: 'high',
|
||||
};
|
||||
|
||||
return notificationService.sendImmediateNotification(notification);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 营养相关的通知辅助函数
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user