fix:APP-push点击文案显示home页
This commit is contained in:
@@ -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}
|
||||
|
||||
|
||||
26
server/app/features/push_payload.py
Normal file
26
server/app/features/push_payload.py
Normal 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
|
||||
@@ -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
|
||||
|
||||
32
server/tests/test_push_payload.py
Normal file
32
server/tests/test_push_payload.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.features.push_payload import build_home_push_data
|
||||
|
||||
|
||||
def test_build_home_push_data_contains_home_route_fields() -> None:
|
||||
payload = build_home_push_data(
|
||||
client_user_id="client-123",
|
||||
body="今天也请温柔地对自己说话。",
|
||||
scene="push",
|
||||
content_id=9,
|
||||
)
|
||||
|
||||
assert payload == {
|
||||
"client_user_id": "client-123",
|
||||
"scene": "push",
|
||||
"target_screen": "home",
|
||||
"deep_link": "client://home",
|
||||
"home_text": "今天也请温柔地对自己说话。",
|
||||
"content_id": 9,
|
||||
}
|
||||
|
||||
|
||||
def test_build_home_push_data_omits_content_id_when_missing() -> None:
|
||||
payload = build_home_push_data(
|
||||
client_user_id="client-123",
|
||||
body="先看到这句,再回到首页。",
|
||||
)
|
||||
|
||||
assert "content_id" not in payload
|
||||
assert payload["target_screen"] == "home"
|
||||
assert payload["home_text"] == "先看到这句,再回到首页。"
|
||||
Reference in New Issue
Block a user