Repository navigation
feat(dispatch): 乘客端推播的送出路徑——接單/抵達/完成/取消都送得到手機(U) - #61
Merged
Merged
Conversation
App 端(fleet-app #78)已經接完線:登入註冊 device token、推播只當對帳訊號。 但後端 `notify.Dispatcher` 只有 `NotifyDriverRideOffer` 一條路徑—— `/api/customer/device-token` 從上線那天起收到的 token 就沒有任何用途, 乘客把 App 收到背景(WS 斷線)後,司機接單/抵達/完成/取消**手機上一則通知都沒有**。 - `AppPusher` 加 `SendRideUpdate`、`Dispatcher` 加 `NotifyCustomerRideUpdate`; 與派單邀請分兩個方法,讓失敗的 log 分得出是哪一條路徑。FCM 兩條共用送出邏輯、 同樣 Priority=high(「司機已抵達」晚到就沒有意義)。 - 接上五種事件:ride.accepted/driver.arrived/ride.completed/ride.cancelled/ ride.redispatched。TrackingService 補 SetAppNotifier(先前只有 DispatchService 有, 抵達與完成因此送不出去)。 - 白名單與 App 端 `_customerPushTypes` 對齊;**不送 driver.location**(每 8 秒一則)。 - data 只帶 type 與 ride_id:App 醒來後重讀 rides/active,車資這類會變的欄位不放 (推播延遲數十秒才到時,內容早就過期)。 - 乘客自己按的取消不推播(他人就在前景);admin/逾時取消才推。 順手修掉:`checkGeofence` 原本把**整個抵達通知(含 WS 事件與審計)**掛在 「查得到 LINE ID」上,改成 LINE 只是其中一條管道。 驗收:go test ./internal/notify 綠;service 四支整合測試(真 PostGIS+Redis)通過, 含「乘客自撤不推播」的負向斷言。反向確認:把 notifyCustomerRide 改成永遠早退,四支全紅。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題
App 端(fleet-app #78)已經接完線:乘客登入後註冊 device token、推播只當對帳訊號。
但後端
notify.Dispatcher只有NotifyDriverRideOffer一條送出路徑——POST /api/customer/device-token從上線那天起收到的 token 就沒有任何用途。實際後果:乘客把 App 收到背景(WS 隨即斷線)後,司機接單/抵達/完成/取消
手機上一則通知都不會有,要等他自己再打開 App、輪詢跑一次才知道。
LINE 那條有推文字,但那是官方帳號的對話,不是 App 通知。
做了什麼
AppPusher加SendRideUpdate、Dispatcher加NotifyCustomerRideUpdate。與派單邀請分兩個方法,讓失敗的 log 分得出是哪一條路徑;
FCMPusher兩條共用送出邏輯,同樣
Priority=high(「司機已抵達」晚到就沒有意義)。ride.accepted/driver.arrived/ride.completed/ride.cancelled/ride.redispatched。TrackingService補SetAppNotifier——先前只有DispatchService有,抵達與完成這兩則因此根本送不出去。
_customerPushTypes對齊;不送driver.location(每 8 秒一則,拿它推播會把電池與推播額度燒光)。
type與ride_id:App 醒來後重讀rides/active,車資這類會變的欄位不放(推播可能延遲數十秒才到,內容早就過期,直接顯示反而讓 App 說謊)。
順手修掉一個洞:
checkGeofence原本是if err != nil || customerLineID == "" { return }——整個抵達通知(含 WS 事件與審計記錄)都掛在「查得到 LINE ID」上。現行資料每位乘客都有
line_user_id,所以還沒人踩到;已改成「LINE 只是其中一條管道」。驗收
go test ./internal/notify/綠(新增乘客推播、角色不混淆、失敗不中斷、nil 安全)。各驗到一則推播;乘客自己取消驗到沒有推播。
notifyCustomerRide改成永遠早退,四支全部 FAIL——斷言吃的是真的送出路徑。
還缺的一半(不在後端)
Firebase 專案憑證(
FCM_CREDENTIALS_FILE)。沒有憑證時走LogPusherstub,這條路徑照樣可驗(log 印得出送給誰、送什麼 data),但手機不會真的響。
憑證到位後不必再改程式碼。
🤖 Generated with Claude Code