Skip to content

feat(chat): real-time chat with the driver on an order - #74

Merged
roncodes merged 1 commit into
release/v0.1.0from
feat/order-chat
Oct 7, 2026
Merged

roncodes merged 1 commit into
release/v0.1.0from
feat/order-chat

Conversation

@roncodes

@roncodes roncodes commented Oct 6, 2026

Copy link
Copy Markdown
Member

Summary

This implements real-time chat with the driver from the redesign prototype. It's stacked on feat/notifications and uses the order chat API from fleetbase/storefront#117, with socket authorization from fleetbase/core-api#290.

Order chat (order.chat, route OrderChat)

  • Header: back to tracking, the driver's avatar (or initials) with a presence dot, name, "Your driver · #order · online", and a call button when the driver's phone is known.
  • Messages:
    • an intro notice;
    • bubbles (yours on the right in the brand colour, the driver's on the left) with photos, times and "Read" on your messages;
    • older messages load as you scroll up (before cursor).
  • Composer: quick replies ("Coming down now", "Please leave it at the door", …), photo sending (up to four), and text up to 2000 characters.
  • Optimistic sending: a message shows straight away as "Sending…". It's replaced by the server copy when confirmed, or offers "Not sent · Tap to retry".
  • Live updates: the screen subscribes to the chat's socket channel. Any 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.
  • States:
    • No driver yet (409 driver_not_assigned), with retry.
    • Load error.
    • Closed once the order is finished: read-only, with a note to contact the store. A send refused with 423 chat_closed closes the composer.
    • Signed out.

Tracking

  • The driver card gets a Message button with the unread count.
  • After the order is finished: "Chat with your driver closed when the order was finished. View messages".
  • Driver-message notifications (inbox and push) now open the chat.

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 and reason of refusals. The SDK adapter only keeps errors[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 on chat.{id}, so live messages would never have arrived. #117 now returns chat.{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

  • Unit tests: __tests__/commerce/order-chat.test.ts, covering the chat module and apiRequest.
  • yarn jest: 188 tests pass. yarn typecheck:strict is clean. yarn lint:strict has 0 errors.
  • Not tested yet:
    • a live chat: it needs #117 and core-api#290 deployed, a signed-in customer and an assigned driver;
    • the chat screen's rendering: the local API has no customer account, so the preview never got past the signed-out state.

- 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.
Base automatically changed from feat/notifications to release/v0.1.0 October 7, 2026 05:44
@roncodes
roncodes merged commit bc5688d into release/v0.1.0 Oct 7, 2026
@roncodes
roncodes deleted the feat/order-chat branch October 7, 2026 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant