fix:APP-push点击文案显示home页

This commit is contained in:
吕新雨
2026-03-12 18:02:25 +08:00
parent d37262876b
commit 22443c82b6
12 changed files with 414 additions and 16 deletions

View File

@@ -16,6 +16,7 @@ from app.db.models.push_preference import PushPreference
from app.db.models.push_token import PushToken
from app.db.models.push_send_log import PushSendLog
from app.db.session import get_db
from app.features.push_payload import build_home_push_data
from app.features.user_profile_scoring.types import UserProfileV1_2
from app.worker import celery_app
@@ -289,7 +290,16 @@ async def test_push(
title = req.title or "Dear Mama"
body = req.body or "这是一条测试推送dev"
expo_res = await _send_expo_push(to=token.push_token, title=title, body=body, data={"client_user_id": req.client_user_id})
expo_res = await _send_expo_push(
to=token.push_token,
title=title,
body=body,
data=build_home_push_data(
client_user_id=req.client_user_id,
body=body,
scene="push",
),
)
_ = accept_language
return {"status": "ok", "expo": expo_res}

View File

@@ -0,0 +1,26 @@
from __future__ import annotations
from typing import Any, Optional
def build_home_push_data(
*,
client_user_id: str,
body: str,
scene: str = "push",
content_id: Optional[int] = None,
) -> dict[str, Any]:
"""
构建客户端点击通知后回到 Home 所需的最小 payload。
"""
data: dict[str, Any] = {
"client_user_id": str(client_user_id),
"scene": str(scene),
"target_screen": "home",
"deep_link": "client://home",
"home_text": str(body),
}
if content_id is not None:
data["content_id"] = int(content_id)
return data

View File

@@ -16,6 +16,7 @@ from app.db.models.push_preference import PushPreference
from app.db.models.push_send_log import PushSendLog
from app.db.models.push_token import PushToken
from app.db.session import AsyncSessionLocal
from app.features.push_payload import build_home_push_data
from app.features.personalized_reco.content_repository.types import normalize_locale
from app.features.user_profile_scoring.scoring import build_user_profile_from_questionnaire
from app.features.user_profile_scoring.types import QuestionnaireAnswersV1_2, UserProfileV1_2
@@ -365,7 +366,12 @@ async def _send_once_async(*, client_user_id: str, local_date: date, slot_index:
to=str(token.push_token),
title=title,
body=body,
data={"client_user_id": client_user_id, "scene": "push"},
data=build_home_push_data(
client_user_id=client_user_id,
body=body,
scene="push",
content_id=picked_content_id,
),
)
# 6) 解析 Expo 回执,必要时停用 token