Introduce messaging feature allowing users to communicate with contacts
Implements a new ChatPage component with WebSocket for real-time messaging. Replit-Commit-Author: Agent Replit-Commit-Session-Id: c5f0c281-8dd8-4846-b452-4a07bcd21062 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9777c70b-fc38-4831-8d6b-78dfffe041b0/9d44895d-6eba-4363-a24d-e3722f77b5e9.jpg
This commit is contained in:
@@ -27,6 +27,7 @@ import SettingsPage from "@/pages/SettingsPage";
|
||||
import FocusPage from "@/pages/FocusPage";
|
||||
import ThemePage from "@/pages/ThemePage";
|
||||
import BenchmarkPage from "@/pages/BenchmarkPage";
|
||||
import ChatPage from "@/pages/ChatPage";
|
||||
import NotFound from "@/pages/not-found";
|
||||
|
||||
function Router() {
|
||||
@@ -45,6 +46,7 @@ function Router() {
|
||||
<Route path="/monitoring" component={SystemMonitoringPage} />
|
||||
<Route path="/focus" component={FocusPage} />
|
||||
<Route path="/themes" component={ThemePage} />
|
||||
<Route path="/chat" component={ChatPage} />
|
||||
<Route path="/settings" component={SettingsPage} />
|
||||
<Route path="/professionals" component={ProfessionalDirectory} />
|
||||
<Route component={NotFound} />
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"voice": "Voice Commands",
|
||||
"analytics": "Analytics",
|
||||
"monitoring": "System Monitor",
|
||||
"chat": "Messages",
|
||||
"settings": "Settings",
|
||||
"logout": "Logout",
|
||||
"profile": "Profile"
|
||||
@@ -70,6 +71,44 @@
|
||||
"taskUpdated": "Task updated successfully",
|
||||
"taskDeleted": "Task deleted successfully"
|
||||
},
|
||||
"chat": {
|
||||
"title": "Messages",
|
||||
"searchPlaceholder": "Search conversations...",
|
||||
"professionalServices": "Professional Services",
|
||||
"typeMessage": "Type a message...",
|
||||
"welcome": "Welcome to Messages",
|
||||
"welcomeDescription": "Select a conversation to start messaging with your contacts and professional service providers.",
|
||||
"selectedChat": "Selected Contact",
|
||||
"lastSeen": "Last seen",
|
||||
"minutesAgo": "minutes ago",
|
||||
"noMessages": "No messages yet",
|
||||
"edited": "edited",
|
||||
"online": "Online",
|
||||
"offline": "Offline",
|
||||
"newContact": "Add Contact",
|
||||
"newGroup": "New Group",
|
||||
"callContact": "Call",
|
||||
"videoCall": "Video Call",
|
||||
"moreOptions": "More Options",
|
||||
"messageStatus": {
|
||||
"sent": "Sent",
|
||||
"delivered": "Delivered",
|
||||
"read": "Read"
|
||||
},
|
||||
"messageTypes": {
|
||||
"text": "Text",
|
||||
"image": "Image",
|
||||
"document": "Document",
|
||||
"voice": "Voice Message",
|
||||
"video": "Video",
|
||||
"location": "Location"
|
||||
},
|
||||
"attachments": "Attachments",
|
||||
"voiceMessage": "Voice Message",
|
||||
"sendMessage": "Send Message",
|
||||
"today": "Today",
|
||||
"yesterday": "Yesterday"
|
||||
},
|
||||
"finances": {
|
||||
"title": "Finances",
|
||||
"overview": "Financial Overview",
|
||||
|
||||
@@ -443,5 +443,55 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
app.use(errorTrackingMiddleware);
|
||||
|
||||
const httpServer = createServer(app);
|
||||
|
||||
// WebSocket server setup for real-time chat
|
||||
const wss = new WebSocketServer({ server: httpServer, path: '/ws' });
|
||||
|
||||
wss.on('connection', (ws: WebSocket) => {
|
||||
console.log('New WebSocket connection');
|
||||
let userId: number | null = null;
|
||||
|
||||
ws.on('message', (data: Buffer) => {
|
||||
try {
|
||||
const message = JSON.parse(data.toString());
|
||||
|
||||
if (message.type === 'join' && message.userId) {
|
||||
userId = message.userId;
|
||||
|
||||
// Add connection to user's connection list
|
||||
if (!wsConnections.has(userId)) {
|
||||
wsConnections.set(userId, []);
|
||||
}
|
||||
wsConnections.get(userId)!.push(ws);
|
||||
|
||||
console.log(`User ${userId} connected to WebSocket`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error parsing WebSocket message:', error);
|
||||
}
|
||||
});
|
||||
|
||||
ws.on('close', () => {
|
||||
if (userId) {
|
||||
// Remove connection from user's connection list
|
||||
const connections = wsConnections.get(userId);
|
||||
if (connections) {
|
||||
const index = connections.indexOf(ws);
|
||||
if (index > -1) {
|
||||
connections.splice(index, 1);
|
||||
}
|
||||
if (connections.length === 0) {
|
||||
wsConnections.delete(userId);
|
||||
}
|
||||
}
|
||||
console.log(`User ${userId} disconnected from WebSocket`);
|
||||
}
|
||||
});
|
||||
|
||||
ws.on('error', (error) => {
|
||||
console.error('WebSocket error:', error);
|
||||
});
|
||||
});
|
||||
|
||||
return httpServer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user