initialize contact again when added to group or left
This commit is contained in:
@@ -221,29 +221,47 @@ function initializeSocket(io) {
|
||||
});
|
||||
|
||||
socket.on("remove user from group", async (msg, callback) => {
|
||||
const { conversation_id, user_id } = msg;
|
||||
if (!conversation_id) {
|
||||
const { group_id, user_id } = msg;
|
||||
|
||||
if (!group_id || !user_id) {
|
||||
return callback({
|
||||
status: "error",
|
||||
message: "No conversation id provided",
|
||||
message: "Missing required parameters",
|
||||
});
|
||||
}
|
||||
if (!user_id) {
|
||||
return callback({ status: "error", message: "No user id provided" });
|
||||
|
||||
try {
|
||||
const result = await removeUserFromGroupById(group_id, user_id);
|
||||
|
||||
if (result?.message) {
|
||||
return callback({ status: "error", message: result.message });
|
||||
}
|
||||
|
||||
// Get all sockets in the room
|
||||
const socketsInRoom = await io.in(group_id).fetchSockets();
|
||||
|
||||
for (const socketInstance of socketsInRoom) {
|
||||
if (socketInstance.user_id === user_id) {
|
||||
socketInstance.leave(group_id);
|
||||
}
|
||||
}
|
||||
|
||||
io.to(group_id).to(user_id).emit("left group", {
|
||||
group_id,
|
||||
user_id,
|
||||
});
|
||||
|
||||
return callback({
|
||||
status: "ok",
|
||||
message: "Successfully removed user from group",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to remove user from group:", error);
|
||||
return callback({
|
||||
status: "error",
|
||||
message: "Internal server error",
|
||||
});
|
||||
}
|
||||
|
||||
const result = await removeUserFromGroupById(conversation_id, user_id);
|
||||
|
||||
if (result?.message) {
|
||||
return callback({ status: "error", messsage: result.message });
|
||||
}
|
||||
|
||||
io.to(conversation_id).emit("left group", { conversation_id, user_id });
|
||||
|
||||
return callback({
|
||||
status: "ok",
|
||||
message: "Successfully removed user from group",
|
||||
});
|
||||
});
|
||||
|
||||
socket.on("disconnect", (reason) => {
|
||||
|
||||
Reference in New Issue
Block a user