feat: 通知推送/免打扰偏好 + 饮食记录侧滑删除修复 + 聊天交互优化

- 通知: 新增推送开关/免打扰时段偏好持久化 + EF 迁移; 通知管线支持免打扰过滤
- 饮食: 侧滑删除 confirmDismiss 按方向放行(修复删不掉); 新增 diet_nutrition_widgets; 饮食录入页重构
- 聊天: 智能体胶囊点击锁防误触; 流式状态 select 优化; 卡片入场动画
- 主页: 消息列表提取 _HomeMessages + 侧滑手势打开抽屉
- 其他: api_client IP 适配; 通知/用药/饮食端点微调; 测试更新
This commit is contained in:
MingNian
2026-07-13 10:39:34 +08:00
parent 335a3e6440
commit e654c1e0cc
19 changed files with 2140 additions and 343 deletions

View File

@@ -94,7 +94,11 @@ public sealed class EfNotificationOutboxProcessor(AppDbContext db) : INotificati
var message = JsonSerializer.Deserialize<NotificationMessage>(candidate.Payload)
?? throw new InvalidOperationException("通知消息内容为空");
if (!await _db.UserNotifications.AsNoTracking()
var preference = await _db.NotificationPreferences.AsNoTracking()
.FirstOrDefaultAsync(x => x.UserId == candidate.UserId, ct);
var deliver = preference == null || ShouldDeliver(preference, message.Type, DateTime.UtcNow.AddHours(8));
if (deliver && !await _db.UserNotifications.AsNoTracking()
.AnyAsync(x => x.SourceId == candidate.SourceTaskId, ct))
{
await _db.UserNotifications.AddAsync(new UserNotification
@@ -136,4 +140,25 @@ public sealed class EfNotificationOutboxProcessor(AppDbContext db) : INotificati
return true;
}
private static bool ShouldDeliver(NotificationPreference preference, string type, DateTime nowCst)
{
if (!preference.PushEnabled) return false;
var minuteOfDay = nowCst.Hour * 60 + nowCst.Minute;
var inDnd = preference.DndEnabled && (preference.DndStartMinutes <= preference.DndEndMinutes
? minuteOfDay >= preference.DndStartMinutes && minuteOfDay < preference.DndEndMinutes
: minuteOfDay >= preference.DndStartMinutes || minuteOfDay < preference.DndEndMinutes);
if (inDnd) return false;
return type switch
{
"medication_reminder" => preference.MedicationReminder,
"follow_up_reminder" => preference.FollowUpReminder,
"doctor_reply" => preference.DoctorReply,
"abnormal_alert" => preference.AbnormalAlert,
"health_record_reminder" => preference.HealthRecordReminder,
_ => true,
};
}
}