This pull request introduces chat functionality and socket integration into the application, along with significant improvements to classroom management and error handling. The changes include new utility functions, socket configuration, API endpoints for chat operations, and updates to existing schemas.
Changes
Chat and Socket Integration
Implemented chatUtils.js to handle finding common classrooms and managing errors.
Created socketConfig.js to initialize and define socket events.
Developed socketIo.js to configure socket connections based on JWT authentication.
Integrated configureSocket and handleSocketConnection functions into server.js for managing socket connections.
Added event listeners in socketIo.js for joinRoom, leaveRoom, messageRoom, chat message, and chat activity events.
Implemented logging for socket events to monitor user actions and message flows.
Backend Enhancements
Developed controller functions based on chat and classroom schemas, integrated into their respective API endpoints in chatRoutes.js.
Integrated chatRoutes into the main router via router.js.
Updated classroomModel.js to include name and chat fields for better chat management.
Implemented a new chatModel.js schema with fields for sender, receiver, text, classroom, and timestamp.
Added sendMessage, joinClassroom, getMessages, getUserClassrooms, and leaveClassroom thunks in chatSlice.js for handling asynchronous chat operations.
Updated chatService.js with API calls for sending messages, joining/leaving classrooms, and fetching messages and user classrooms.
Configured axios requests in chatService.js with authentication tokens.
Enhanced error handling in chatService.js to effectively manage API errors.
API Endpoints and Error Handling
Added joinClassroom endpoint to allow users to join classrooms, create a chat entry, and handle errors.
Implemented getClassroomMessages endpoint to retrieve messages from a classroom, with validation for user membership.
Added leaveClassroom endpoint to enable users to leave a classroom, delete associated messages, and handle errors.
Integrated the findCommonClassroom utility to manage chat message distribution based on shared classrooms.
Enhanced error handling across the application for missing classroom IDs, authorization issues, and invalid classroom states.
Testing
Tests pending.
Additional Information
These changes significantly improve the application's chat functionality, making it more robust and secure. Enhanced error handling ensures that the system gracefully manages edge cases and provides clear feedback to users.
Summary
This pull request introduces chat functionality and socket integration into the application, along with significant improvements to classroom management and error handling. The changes include new utility functions, socket configuration, API endpoints for chat operations, and updates to existing schemas.
Changes
Chat and Socket Integration
chatUtils.js
to handle finding common classrooms and managing errors.socketConfig.js
to initialize and define socket events.socketIo.js
to configure socket connections based on JWT authentication.configureSocket
andhandleSocketConnection
functions intoserver.js
for managing socket connections.socketIo.js
forjoinRoom
,leaveRoom
,messageRoom
,chat message
, andchat activity
events.Backend Enhancements
chatRoutes.js
.chatRoutes
into the main router viarouter.js
.classroomModel.js
to includename
andchat
fields for better chat management.chatModel.js
schema with fields for sender, receiver, text, classroom, and timestamp.sendMessage
,joinClassroom
,getMessages
,getUserClassrooms
, andleaveClassroom
thunks inchatSlice.js
for handling asynchronous chat operations.chatService.js
with API calls for sending messages, joining/leaving classrooms, and fetching messages and user classrooms.chatService.js
with authentication tokens.chatService.js
to effectively manage API errors.API Endpoints and Error Handling
joinClassroom
endpoint to allow users to join classrooms, create a chat entry, and handle errors.getClassroomMessages
endpoint to retrieve messages from a classroom, with validation for user membership.leaveClassroom
endpoint to enable users to leave a classroom, delete associated messages, and handle errors.findCommonClassroom
utility to manage chat message distribution based on shared classrooms.Testing
Additional Information