Skip to content

Commit c6b484f

Browse files
committed
Added endpoint for update typing status for the user in chat!
1 parent 519c3c3 commit c6b484f

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/controllers/chat.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const getUserGroupChats = async (req, res, next) => {
2929
}
3030
}
3131

32+
// get group chat details by chatID
3233
export const getGroupChatDetails = async (req, res, next) => {
3334
try {
3435
const { chatID } = req.params;
@@ -40,6 +41,7 @@ export const getGroupChatDetails = async (req, res, next) => {
4041
}
4142
}
4243

44+
// create a group chat with admin email, group name and group description
4345
export const createGroupChat = async (req, res, next) => {
4446
try {
4547
const { adminEmail, groupName, groupDescription } = req.body;
@@ -54,6 +56,7 @@ export const createGroupChat = async (req, res, next) => {
5456
}
5557
}
5658

59+
// add a user to a group chat with admin email, user email and chatID
5760
export const addUserToGroupChat = async (req, res, next) => {
5861
try {
5962
const { adminEmail, userEmail, chatID } = req.body;
@@ -65,6 +68,7 @@ export const addUserToGroupChat = async (req, res, next) => {
6568
}
6669
}
6770

71+
// delete a group chat by chatID
6872
export const deleteGroupChat = async (req, res, next) => {
6973
try {
7074
const { chatID } = req.params;
@@ -75,4 +79,15 @@ export const deleteGroupChat = async (req, res, next) => {
7579
} catch (err) {
7680
next(err)
7781
}
82+
}
83+
84+
// update typing status of a user in a chat
85+
export const updateTypingStatus = async (req, res, next) => {
86+
try {
87+
const { chatID, email, isTyping } = req.body;
88+
await chatService.updateTypingStatus(chatID, email, isTyping);
89+
return res.send({ body: null, message: "Typing status updated successfully!", status: 200 });
90+
} catch (err) {
91+
next(err)
92+
}
7893
}

src/middlewares/validator/schemas/userSchema.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,22 @@ export const markMessageAsSeenURLSchema = Joi.object({
223223
"string.empty": "Message ID cannot be empty",
224224
"any.required": "Message ID is required",
225225
}),
226+
});
227+
228+
export const typingStatusSchema = Joi.object({
229+
chatID: Joi.string().required().messages({
230+
"string.base": "Chat ID must be a string",
231+
"string.empty": "Chat ID cannot be empty",
232+
"any.required": "Chat ID is required",
233+
}),
234+
email: Joi.string().email().required().messages({
235+
"string.base": "Email must be a string",
236+
"string.empty": "Email cannot be empty",
237+
"string.email": "Email must be a valid email",
238+
"any.required": "Email is required",
239+
}),
240+
isTyping: Joi.boolean().required().messages({
241+
"boolean.base": "isTyping must be a boolean",
242+
"any.required": "isTyping is required",
243+
}),
226244
});

src/routes/chat.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,5 +248,12 @@ router.delete(
248248
chatController.deleteGroupChat // Controller to handle the logic
249249
);
250250

251+
// Route to update typing status
252+
router.patch(
253+
"/typing-status",
254+
validate(schemas.typingStatusSchema), // Validate typing status details
255+
chatController.updateTypingStatus // Controller to handle the logic
256+
);
257+
251258
// Export the router to be used in the application
252259
export default router;

0 commit comments

Comments
 (0)