fix:每日推荐修复
This commit is contained in:
@@ -153,6 +153,32 @@ async def register(req: PushRegisterRequest, db: AsyncSession = Depends(get_db))
|
||||
token.is_active = True
|
||||
token.last_seen_at = _ensure_utc(now)
|
||||
|
||||
# 额外:尽早写入/补齐时区与语言(用于按用户时区生成排程)
|
||||
# 说明:
|
||||
# - 用户首次授权后会立即调用 /register,但不一定马上进入“每日提醒”确认页
|
||||
# - 若 push_preferences 里 timezone 为空,会导致排程回退到 UTC,体验不符合预期
|
||||
if req.device_meta:
|
||||
tz = (req.device_meta.timezone or "").strip() or None
|
||||
loc = (req.device_meta.locale or "").strip() or None
|
||||
if tz or loc:
|
||||
qpref = select(PushPreference).where(PushPreference.client_user_id == req.client_user_id)
|
||||
rpref = await db.execute(qpref)
|
||||
pref = rpref.scalar_one_or_none()
|
||||
if pref is None:
|
||||
pref = PushPreference(
|
||||
client_user_id=req.client_user_id,
|
||||
enabled=False,
|
||||
times_per_day=0,
|
||||
timezone=tz,
|
||||
locale=loc,
|
||||
)
|
||||
db.add(pref)
|
||||
else:
|
||||
if tz and not (pref.timezone or "").strip():
|
||||
pref.timezone = tz
|
||||
if loc and not (pref.locale or "").strip():
|
||||
pref.locale = loc
|
||||
|
||||
await db.commit()
|
||||
return {"status": "ok"}
|
||||
|
||||
@@ -187,8 +213,11 @@ async def put_preferences(req: PushPreferencesRequest, db: AsyncSession = Depend
|
||||
else:
|
||||
pref.enabled = enabled
|
||||
pref.times_per_day = times
|
||||
pref.timezone = req.timezone
|
||||
pref.locale = req.locale
|
||||
# 注意:只在客户端显式传入时覆盖,避免把已保存的 timezone/locale 清空导致排程回退到 UTC
|
||||
if req.timezone is not None:
|
||||
pref.timezone = req.timezone
|
||||
if req.locale is not None:
|
||||
pref.locale = req.locale
|
||||
if req.user_profile is not None:
|
||||
pref.user_profile_json = req.user_profile.model_dump(mode="json")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user