Repository navigation
feat(dispatch): 對話訊息也送推播——推給收訊那一方(U2) - #62
Merged
Merged
Conversation
對話先前只走 WS:對方 App 一離開前景 WS 就斷了,訊息只會躺在伺服器上, 要等他自己再打開 App 才看得到。「司機到了要聯絡乘客」「乘客回報遺失物」都因此斷線。 這是 Phase 2 清單上掛很久的「聊天訊息 FCM 推播(App 被殺時)」。 - Dispatcher 加 NotifyDriverRideUpdate,與 NotifyCustomerRideUpdate 共用 notifyRideUpdate (差別只在查哪個角色的裝置)。與 NotifyDriverRideOffer 分開:那支是派單邀請(要開接單卡), 這支是行程進行中的通知。 - ChatService.Send 發完 WS 後推給收訊那一方;**不推給發話者自己的其他裝置**—— 系統匣跳出自己剛送出的訊息只會讓人以為對方回話了。 - 訊息內容放通知本文、不放 data(data 仍只有 type+ride_id):App 醒來後仍以 REST 重讀對話拿完整歷史。本文以 rune 計截斷 60 字,用 byte 截會把中文切成亂碼。 - 用 context.Background():HTTP 回應一送出請求 ctx 就被取消,推播會被腰斬。 驗收:go test ./internal/service -run TestChatSend_ 三支整合測試(真 PostGIS+Redis)通過 +TestPreviewText。反向確認:拿掉 pushToRecipient,「推給對方」那支 FAIL(0 則)。 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.
問題
行程內對話先前只走 WS:對方 App 一離開前景,WS 就斷了,訊息只會躺在伺服器上,
要等他自己再打開 App 才看得到。實務上斷掉的正是最需要的兩個情境——
司機到了要聯絡乘客、乘客回報遺失物。
這是 Phase 2 清單上掛了很久的「聊天訊息 FCM 推播(App 被殺時)」,
地基(
SendRideUpdate/notifyRideUpdate)在 #61 已經備妥。做了什麼
Dispatcher加NotifyDriverRideUpdate,與NotifyCustomerRideUpdate共用notifyRideUpdate(差別只在查哪個角色的裝置)。與NotifyDriverRideOffer分開,因為用途不同:那支是派單邀請(要開接單卡),這支是行程進行中的通知。
ChatService.Send發完 WS 後推給收訊那一方:乘客發話推司機、司機發話推乘客。不推給發話者自己的其他裝置——他知道自己說了什麼,系統匣跳出自己剛送出的訊息
只會讓人以為對方回話了。
data仍只有type+ride_id):使用者看得到的就是要看內容,但 App 醒來後仍以 REST 重讀對話拿完整歷史,避免推播裡那一則與伺服器
狀態各說各話。本文以 rune 計截斷 60 字——用 byte 截會把中文切成亂碼。
context.Background()而非請求的 ctx:HTTP 回應一送出,請求 ctx 就被取消,推播是回應之後才完成的背景動作,掛在請求 ctx 上會被腰斬。
驗收
go test ./internal/service -run TestChatSend_三支整合測試(真 PostGIS + Redis 容器)通過:推給對方而非發話者、尚未指派司機時不推、未注入 notifier 仍能發話;
另有
TestPreviewText釘住 rune 截斷。go test ./internal/notify/綠。pushToRecipient呼叫,「推給對方」那支 FAIL(0 則)。App 端同批
chat.message進兩端推播白名單、收到時只點亮未讀角標——推播 data 沒有訊息本體,餵給
RideMessage.fromJson只會解析失敗被丟掉;內容等聊天室自己以 REST 補齊。🤖 Generated with Claude Code