Messages
The chat screen for agents and landlords, how rooms load, how messages are sent in real time over socket.io, and what is not built yet.
Where it lives
| Route | View file | Access |
|---|---|---|
/messages | src/views/app/messages/messages.tsx | agent, landlord |
/messages?room=:id | same file, opens that conversation (used by global search results) | agent, landlord |
Supporting code: src/hooks/use-chat.ts (socket lifecycle), src/services/chat/socket.service.ts (one shared socket), src/services/chat/chat-slice.ts (Redux state), src/services/chat/chat-api.ts (REST, base path /api/v1/chat).
Before you start
- Signed in as an agent or landlord. The socket authenticates with the access token from the session.
- A conversation must already exist. Rooms are started by a client from the consumer app, or by Send Message on an inspection request, see Inspection requests. This screen has no "new conversation" button.
Flow
Connect and load rooms
- Opening
/messagesconnects a socket.io client to the API host withauth: { token }. It retries up to five times, two seconds apart. - On connect the app emits
chat:get_rooms. The server answers withchat:rooms, and the list is stored in Redux. - The left panel is headed "Messages" with three tabs: All Chats, Unread, Active Leads.
- Each row shows the other participant's name and avatar, the last message (or "No messages yet") and a relative time: "just now", "5m ago", "3h ago", or a date after 24 hours.
- On a desktop the middle panel reads "Select a conversation to start messaging" until a row is clicked. On a phone the list fills the screen.
The first room is joined in the background
Before any row is clicked, the app already joins the first room in the list and loads its messages. The chat panel still stays on the placeholder until the user picks a conversation.
Open a conversation
- Click a row, or arrive with
?room={id}. Picking another row drops theroomparameter from the URL. - The app emits
chat:joinwith{ roomId }. The server replies withchat:history. - In parallel it calls
GET /api/v1/chat/rooms/{roomId}/messages?limit=50&offset=0. - Both results are merged in Redux, de-duplicated by message id and sorted oldest first. The view scrolls to the newest message.
- Switching rooms emits
chat:leavefor the old room andchat:joinfor the new one. - The header shows the other person's name, Active Now or Offline, Call and Video icons, and a Schedule Tour button. On a phone a back arrow returns to the list.
- On wide screens a right-hand column shows Referenced Property (photo, title, price, or "No property linked"), Client Insights and Quick Replies.
Send a message
- Type into "Type your message here...". The send button is disabled while the text is empty or only spaces.
- Press Enter or the send button.
- The message appears at once as an optimistic bubble with a temporary id.
- The app emits
chat:messagewith{ roomId, content, messageType: "TEXT", replyToId }. No REST call is made. - The server broadcasts
chat:messageto the room. The echo replaces the optimistic bubble, matched by its text. - The server also sends
chat:room_updatedto each participant, which updates the last-message preview in the list.
Only text can be sent. The message types IMAGE, FILE and AUDIO exist in the type definitions but have no upload control.
Reply, typing and read ticks
- Reply: hover a bubble and click the reply arrow. A bar reading "Replying to (name)" or "Replying to yourself" appears above the input with the quoted text. The X cancels it. The sent bubble carries the quote.
- Typing: every keystroke emits
chat:typingwith{ roomId, isTyping }. It is switched off automatically after two seconds. When the other person types, three bouncing dots show at the bottom of the thread. - Read ticks: your own messages show one grey tick, or two coloured ticks once
readByholds more than one user. - Quick Replies: "Confirm Viewing" and "Inquiry Response" drop a starter sentence into the input. Nothing is sent until you press Enter.
Schedule Tour
The Schedule Tour dialog is a mock-up
The "Schedule Inspection" dialog shows a calendar preset to 12 September 2024, four fixed time slots (one marked Booked) and the caption "Available slots for Thursday, Sept 12". Confirm Booking only closes the dialog. No request is sent and no inspection is created.
Delete and report
No delete or report control
The screen has no way to delete a message or report a conversation.
DELETE /api/v1/chat/messages/{messageId} is defined in chat-api.ts but no component calls it. The API also has POST /api/v1/chat/rooms/{roomId}/report, which this app never references.States and edge cases
| Situation | What the user sees |
|---|---|
| Socket not yet connected, no rooms | "Connecting…" in the list and in the chat panel, plus a no-signal icon in the header |
| Connected, no rooms | "No conversations yet" and "Messages from clients will appear here" |
| Socket drops mid-chat | The header status changes to Offline. Messages typed now are shown optimistically and only reach the server if the socket reconnects |
| Server rejects a message | Nothing. The server emits chat:error, which the app does not listen for |
| Leaving the page | The app emits chat:leave and disconnects the socket |
Things on this screen that are placeholders:
| Element | Actual behaviour |
|---|---|
| Active Now / Offline | Reflects your own socket connection, not the other person's presence |
| Unread tab | Shows every room that has a last message. There is no unread count |
| Active Leads tab | Shows every room |
| "Today" divider | Fixed text, shown above every thread |
| Call, Video, attach (+) and emoji buttons | No action |
| Client Insights | Fixed sample text ("ID Verified", "12 Bookings", a budget range) |
| Referenced Property price | Printed with a dollar sign regardless of currency. Details has no action |
Leaving Messages stops live notifications
The chat and the notification bell share one socket. When the Messages page unmounts it disconnects and discards that socket, so the listener for new notifications is lost until the next full page load. This looks unintended.
What happens next
- The other participant receives the message live if they are in the room, and their room list preview updates.
- A message sent from an inspection request lands in the same rooms and appears here, see Inspection requests.
HomeLink Hub