Repository navigation
feat(chat): real-time chat with the driver on an order - #74
Merged
Merged
Conversation
- Order chat: driver header with presence, call button, intro notice, message bubbles with photos, times and read receipts, older messages on scroll, quick replies, photo sending, and optimistic sends that can be retried. - Live: new messages and receipts arrive on the chat's socket channel; a reconnecting banner shows while the socket is down. Read when opened. - States: no driver yet (409), load errors, closed chats read-only once the order is finished (and sends refused with 423 close the composer). - Tracking: a Message button with the unread count on the driver card, and "View messages" after the order is finished. Driver-message notifications open the chat. - src/commerce/order-chat.ts and http.ts (requests that keep refusal reasons), with tests; order.chat screen id.
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.
Summary
This implements real-time chat with the driver from the redesign prototype. It's stacked on
feat/notificationsand uses the order chat API from fleetbase/storefront#117, with socket authorization from fleetbase/core-api#290.Order chat (
order.chat, routeOrderChat)beforecursor).chat_*event re-reads the latest messages, which keeps it independent of the socket payload shape. The driver's messages are marked read when they arrive or when the chat opens. A "Reconnecting…" banner shows while the socket is down. Sending still works then, because it goes over HTTP.driver_not_assigned), with retry.chat_closedcloses the composer.Tracking
Shared code
src/commerce/order-chat.ts: parsing, merging (server copies replace local ones; unsent messages stay last), and the chat endpoints.src/commerce/http.ts: requests that keep the status andreasonof refusals. The SDK adapter only keepserrors[0].useChatRequest: chat calls with the customer token.Backend fix in #117
The chat payload advertised
chat_channel.{uuid}. That channel is authorized, but core broadcasts chat events onchat.{id}, so live messages would never have arrived. #117 now returnschat.{public_id}. Its suite passes (612 tests) with every changed line covered.Not included
Typing indicators: there are no typing events to listen to.
Testing
__tests__/commerce/order-chat.test.ts, covering the chat module andapiRequest.yarn jest: 188 tests pass.yarn typecheck:strictis clean.yarn lint:stricthas 0 errors.