Chats and notifications
How agents, landlords and lawyers read and answer messages, what the Notifications screen really shows, and how push notifications are registered and routed.
Chat is real time and runs almost entirely over a Socket.IO connection. The Notifications screen is a different thing: it is a view over the dashboard activity feed, with read state kept on the device. Push notifications are registered once per signed-in account and decide where a tap lands.
Where it lives
| Screen route | File | Who sees it |
|---|---|---|
/(tabs)/chats | app/(tabs)/chats/index.tsx | Agents, landlords and lawyers (Chats tab, second icon in the tab bar) |
/(tabs)/chats/[id] | app/(tabs)/chats/[id].tsx | Same roles, opened from a row in the list or from a push notification |
/(tabs)/notifications | app/(tabs)/notifications.tsx | Same roles. Hidden from the tab bar (href: null), opened from the bell on the dashboard home or from a push notification |
| (no screen) | hooks/use-push-notifications.ts, lib/push-notifications.ts | Every signed-in user. Mounted once in app/_layout.tsx as PushNotificationsRegistrar |
Supporting code: hooks/use-chat.ts (socket lifecycle and events), services/chat/socket.service.ts (the single socket instance), services/chat/chat-slice.ts (Redux chat slice), services/chat/chat-api.ts (REST endpoints under /api/v1/chat), components/ChatListItem.tsx, components/ChatHeader.tsx.
Before you start
- The user must be signed in. The socket authenticates with the access token read from AsyncStorage key
session:ACCESS_TOKENat the moment the socket is created. - An agent must have finished agent setup, otherwise the
(tabs)layout redirects to/agent-onboardingbefore any of these screens render. - Push notifications need a physical device, the OS notification permission, and a build that carries an EAS project id. On a simulator the app logs
[push] skipped: push tokens need a physical deviceand carries on without push. - No camera, photo or microphone permission is requested by these screens. The attachment and microphone buttons in the composer are not wired up (see States and edge cases).
Flow
Chat list
- The user taps the Chats tab. The screen title is Messages.
useChat(null)connects the socket to the API host (not the/api/v1path) withauth: { token }, reconnection on, 5 attempts, 2000 ms apart.- On
connectthe app setschat.connectedtotrueand emitschat:get_rooms. The server answers withchat:rooms, an array of rooms, which is stored inchat.rooms. - Under the search box a status line reads Connected to chat server or Connecting to chat....
- Each room becomes one row:
- Name:
room.name, else the first participant's first and last name, elseChat room. - Preview:
room.lastMessage, elseStart a new conversation. - Time: hours and minutes of
lastMessageAt(falling back tocreatedAt). No date is shown, even for old conversations. - Avatar: the first participant's avatar, else a generated placeholder image.
- Name:
- Typing in Search by name... filters rows locally by name (case-insensitive substring). An X button clears the query. Nothing is sent to the server.
- While the list is open,
chat:room_updatedevents (roomId,lastMessage,lastMessageAt) update the preview and time of the matching row in place. - Tapping a row pushes
/chats/[id]with the room id.
List indicators that are not real yet
The green dot on an avatar is driven by whether the participant has an avatar image, not by presence. The unread badge is always hidden because unreadCount is hardcoded to 0. The filter icon in the search box has no handler.
Chat thread
- On mount the screen reads the signed-in user's id from AsyncStorage key
local:USER(_id, falling back toid). Until that resolves the id is the placeholder"1", so for a moment every bubble is drawn as the other party's. useChat(roomId)emitschat:joinwith{ roomId }. The server replies withchat:history(roomIdplusmessages), which is merged intochat.socketMessages[roomId], de-duplicated by_idand sorted oldest first.- The header shows the room name (or
Chat), the avatar of the first participant, and a status of Online when the socket is connected or Connecting when it is not. A verified tick is always drawn next to the name. - The user types in Type a message.... The send button is disabled until the trimmed text is non-empty.
- Tapping send emits
chat:messagewith{ roomId, content, messageType: "TEXT" }and clears the input. There is no optimistic bubble: the message appears when the server broadcastschat:messageback to the room. - Incoming
chat:messageevents are appended tochat.socketMessages[roomId]unless a message with the same_idis already there. - The user's own bubbles sit on the right with a double tick; the tick is decorative and does not reflect
readBy. Each bubble shows the time as hours and minutes. - Leaving the screen emits
chat:leavewith{ roomId }.
Only plain text can be sent. The MessageType type lists IMAGE, FILE and AUDIO, but nothing in the screen produces them.
Composer menu
The menu (three lines) button inside the composer opens a bottom sheet with three shortcuts:
| Label | Navigates to |
|---|---|
| Schedule Inspection | /property/inspection |
| Make Payment | /property/payment |
| Request Documents | /property/contract |
Menu shortcuts look tenant-oriented
All three routes are tenant-side flows and are pushed without a property id or any other parameter. For an agent, landlord or lawyer they are unlikely to be meaningful. Treat this menu as unfinished on the professional side.
Report a chat
- The red flag in the header opens the Report Chat sheet with the prompt Why are you reporting this chat?
- The user picks one reason:
Spam(preselected),Harassment,Fraud,Inappropriate ContentorOther. There is no free-text field. - Submit fires
POST /api/v1/chat/rooms/:roomId/reportwith body{ reason }. - Success closes the sheet and shows the toast Chat Reported / Your report has been submitted for review.
- Failure keeps the sheet open and shows Report Failed / Could not submit your report at this time.
- Cancel or tapping outside closes the sheet without sending anything.
How a conversation starts
No screen in the (tabs) navigator creates a room. Rooms arrive only through chat:rooms, so an agent or landlord sees a conversation once the other party has opened it. The hook exposes createAndSend(propertyId, content), which emits chat:create_and_send, and chat-api.ts defines POST /api/v1/chat/rooms, but neither is called from any screen in this part of the app.
Notifications screen
- The user taps the bell on the dashboard home (
router.push("/notifications")), or taps a push notification that is not a chat event. - The screen calls
GET /api/v1/dashboard/recent-activity. There is no dedicated notifications endpoint behind this screen. - Each activity item is mapped to a card:
Activity type | Category chip | Title | Body |
|---|---|---|---|
booking | Payments | Payment Request Update | <actor> requested payment for <property>. |
message | Messages | <actor> sent a message | The message text, else the property name, else You have a new message. |
inspection | Property | Inspection Activity | <actor> updated <property>. |
review | Property | Property Review Activity | <actor> updated <property>. |
| anything else | Security | Security Alert | The item text, else A security-related update was received. |
- Cards are sorted newest first and show a relative time such as
5 mins ago,2 hrs agoor3 days ago. - The chips All, Property, Messages, Payments and Security filter the list locally.
- Tapping a card marks it read: the unread dot disappears and the card dims. Read state is a map of card id to
truein AsyncStorage keynotifications_read_map_v1. It is device-local and never sent to the server. - Clear all marks every loaded card as read. It does not remove cards.
- Refresh at the bottom refetches the activity feed.
Cards do not deep link
Tapping a card only marks it read. It does not open the related chat, inspection request or payment request. The subtitle Real-time in-app notifications is aspirational: the list updates only on load and on Refresh.
Push notification registration
PushNotificationsRegistrarruns for every signed-in user once the session has been restored. It re-runs when the signed-in account changes.- On Android the app creates the
defaultchannel (name Notifications, high importance) before asking for permission. - If permission is undecided the OS prompt is shown. A refusal ends the flow silently.
- The app requests an Expo push token and posts it with
platform(iosorandroid) anddeviceName. The token is then cached in AsyncStorage keylocal:PUSH_TOKEN. - If Expo rotates the token, the listener registers the new one the same way.
- While the app is in the foreground, pushes still show a banner and play a sound; the badge count is not set.
- On sign out the app sends a delete request for the cached token before the session is cleared, then removes
local:PUSH_TOKEN. A failure here never blocks sign out.
Push token path does not match the backend mount
The app posts to and deletes from /api/v1/users/push-tokens (plural). In the service, the handler is registered on the user router, which is mounted at /api/v1/user (singular), so the route the backend serves is POST /api/v1/user/push-tokens and DELETE /api/v1/user/push-tokens. No /users mount exists in service/src/routes/index.ts. Registration errors are swallowed, so this would fail silently. Confirm on a device before relying on push.
Tapping a push notification
- Taps are ignored until the session is restored, a user is present, and the current route is outside
(onboarding),(auth)andagent-onboarding. A tap that cold-starts the app is replayed once those conditions hold. - The push
datacarrieseventTypeandmeta. - If
eventTypeisnew_chat_requestornew_messageandmeta.roomIdis set, the app pushes/(tabs)/chats/<roomId>. - Every other event opens
/(tabs)/notifications. - The handled response is cleared so the next launch does not replay it.
States and edge cases
- Chat list empty states. Connected with no rooms: No Conversations Yet /
Start a chat from any property and it will show up here.Not connected: Connecting… /Waiting for the chat connection. This usually takes a moment.Search with no match: No Conversations Found /Nothing matched "<query>". Try a different name. - No loading skeleton in either chat screen. The list shows the connecting empty state; the thread is simply empty until
chat:historyarrives. - Send failures are silent. The server emits
chat:errorwhen a join or send fails, but the app does not listen for it. Nothing tells the user a message was not delivered. - Dead buttons. In the thread header the phone and video icons have no handler. In the composer the paperclip and microphone have no handler.
- Typing indicators are not shown. The hook listens for
chat:typingand can emit it, but the thread screen neither callssendTypingnor renderstypingUsers. - Unused REST endpoints.
GET /api/v1/chat/rooms,GET /api/v1/chat/rooms/:roomId/messages,POST /api/v1/chat/rooms/:roomId/messagesandDELETE /api/v1/chat/messages/:messageIdare defined inchat-api.tsbut not called by these screens. There is no delete-message or edit-message UI. - Reconnects. After 5 failed reconnection attempts the socket gives up; the status stays on Connecting to chat... until the screen is remounted. The token is read once when the socket is created, so a socket opened with an expired access token is not rebuilt automatically.
- Notifications loading and empty. While loading or refetching: a spinner with
Loading notifications.... No items in the selected category: No Notifications Yet /Updates about your properties, requests and payments will appear here. - Security chip is effectively empty. The activity feed only declares the types
message,inspection,bookingandreview, so nothing normally falls through to the Security category. - Notification ids are derived, built from type, time and actor. Two activities by the same actor at the same instant would share a read state.
- Sign out. The whole Redux store, including the
chatslice, is reset on logout or session expiry, so rooms and messages from one account never leak into the next.
Returning from a thread may leave the list disconnected
Both the list and the thread mount useChat, and each instance calls disconnectSocket() when it unmounts. Closing a thread therefore disconnects the socket the list is still listening on, and a manual disconnect does not auto-reconnect. Reading the code, the list would then show Connecting to chat... and stop receiving chat:room_updated until it remounts. Verify on a device.
What happens next
- A sent message is broadcast by the server to everyone in the room as
chat:message, and each participant receiveschat:room_updatedso their chat list preview changes. - A submitted report is stored by the backend for review. The app shows no follow-up state for it.
- Which pushes a user receives is governed by their notification preferences. See the Profile and settings page for the Push and Email switches.
HomeLink Hub