Building 1:1 chat
A 1:1 chat thread connects two user IDs over WebSocket: load history when opening the thread, send new messages with send(), and append live deliveries from onMessage.
Thread model
User A (user-alice) User B (user-bob)
β β
β fetchChatHistory([bob]) on open β
β send({ receiverId: "user-bob" }) β
ββββββββββββββββββββββββββββββββββββββββββββΊβ
β β
βββββββββββββββββββββββββββββββββββββββββββββ€
β onMessage on both sides βThread key β pair
(userA, userB); your app defines sort order forfetchChatHistorySame
appIdβ both participants use the same DNotifier applicationStable
userIdβ map your auth user to a consistent DNotifier id
Implementation checklist
Connect on login β
transport: "ws",userId= authenticated userOpen thread β call
fetchChatHistory({ senderId, receiverIds: [peerId] })Render history β handle history response in
onMessageSend message β
send({ senderId, receiverId, data: { type: "text", text } })Live updates β append
onMessagepayloads to the thread viewReconnect β refetch history after disconnect to fill gaps
Message payload convention
Extend with image, audio, doc for rich chat β see Structured payloads.
Language guides
JavaScript / TypeScript
Dart / Flutter
Related topics
Chat history
Save history
UI patterns
Full example
Last updated