The Messaging module provides a complete interface for managing real-time chat interactions. It leverages the MessagesMenu component to fetch and display chat conversations, handle new chat creation, and update chats in real time using Supabase channels.
The messaging system includes comprehensive media support:
The MessagesMenu component is the central hub for chat functionality. Here's a key implementation snippet:
tsx
export default function MessagesMenu() {
const [chats, setChats] = useState<Chat[]>([]);
const [showNewChat, setShowNewChat] = useState(false);
const [selectedChatId, setSelectedChatId] = useState<string | null>(null);
const [hiddenChatIds, setHiddenChatIds] = useState<string[]>([]);
const [currentGroupId, setCurrentGroupId] = useState<string | null>(null);
// Real-time subscriptions for chat updates
useEffect(() => {
fetchChats();
const channel = supabase
.channel("chats-channel")
.on("postgres_changes", { event: "*", schema: "public", table: "chats" }, () => fetchChats())
.on("postgres_changes", { event: "*", schema: "public", table: "messages" }, () => fetchChats())
.on("postgres_changes", { event: "*", schema: "public", table: "chat_participants" }, () => fetchChats())
.on("postgres_changes", { event: "*", schema: "public", table: "group_settings" }, () => fetchChats())
.subscribe();
return () => channel.unsubscribe();
}, []);
// Event handling for menu actions
useEffect(() => {
const menuListener = EventRegister.addEventListener("openMenu", (data: any) => {
if (data.tab === "messages") {
if (data.action === "openChat" && data.chatId) {
setSelectedChatId(data.chatId);
// Additional chat opening logic...
}
}
});
return () => EventRegister.removeEventListener(menuListener as string);
}, []);
}
The messaging system supports several types of chats:
Chats are stored in the following tables:
chats: Main chat informationmessages: Individual messageschat_participants: User participation in chatsgroup_settings: Chat settings for groupsThe module uses an event-driven architecture with the following key events:
openMenu: Handles navigation between chat viewsslidingMenuStateChange: Manages menu visibilityThe messaging module integrates with: