The Coliving App includes a robust messaging system designed to support communication between users (mates) and coliving space admins. This guide explains the structure, flow, and design philosophy behind the system.
- Stores private (1:1) conversations between mates.
user1,user2: participants (by UID).user1_checked,user2_checked: track when each user last checked the conversation.
- Stores conversations between a mate and a coliving space (e.g., joining requests, general questions).
user1: the mate UID.user2: the space UID.user1_checked,user2_checked: similar logic as above.
- Stores the actual messages.
conversation_uid: links to the conversation.sender_uid: UID of the sender.content: the message content.
- The frontend fetches
/api/conversations, which returns:conversations_mate_pov: all personal conversations from the user’s point of view, including:inbox_mate_mate(mate-to-mate)inbox_mate_spacewhere the user isuser1(initiator)
conversations: space-related conversations (frominbox_mate_spacewhere the user is the space admin)
- Each conversation includes:
- Last message timestamp (
updated_at) user1_checkedanduser2_checkednew: boolean flag computed in frontend if there are unread messages
- Last message timestamp (
Unread status is determined by comparing the conversation’s updated_at with the userX_checked timestamp:
- If
updated_at > user1_checked, the message is unread byuser1 - Same applies for
user2
This logic runs both:
- In the frontend, for live updating and dot indicators in inbox views
- In the MateService backend, to include top-level
.hasUnreadPersonaland.hasUnreadSpacesflags used globally (e.g., in the header menu)
When a user visits the Inbox view:
/api/conversationsis called- Unread states are calculated in JavaScript and
newflags are added per conversation - Vue's
computedvalues derivehasNewPersonalandhasNewSpaces - Red dots (
●) are shown automatically in Inbox tabs
The header Inbox menu dot checks window.mate.hasUnreadPersonal and .hasUnreadSpaces, which are set by backend and updated live by the frontend via inboxStore.js. No watchers are required in the header.
- Only conversations are stored in the
inbox_mate_mateandinbox_mate_spacetables – messages themselves live in themessagestable. - Separation of user-facing logic and backend tracking ensures speed and flexibility.
- The system is easily extendable (e.g., groups, threads, reactions) with minimal changes.
For questions, improvements, or to contribute, feel free to open an issue or submit a pull request.