Legt de bestaande wijzigingen in de hoofdworktree vast voordat de laatste worktree wordt gemerged.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
const UserRepository = require("../repositories/UserRepository");
|
|
|
|
module.exports = function(io) {
|
|
|
|
io.on("connection", (socket) => {
|
|
|
|
const userId = socket.request.session?.userId;
|
|
const user = userId && UserRepository.findById(userId);
|
|
|
|
if (!user || !user.household_id) {
|
|
socket.disconnect(true);
|
|
return;
|
|
}
|
|
|
|
socket.join(`household:${user.household_id}`);
|
|
|
|
console.log("🔌 Gebruiker verbonden:", socket.id);
|
|
|
|
socket.on("join:household", () => {
|
|
// The room is derived from the authenticated session above.
|
|
});
|
|
|
|
socket.on("list:updated", (data) => {
|
|
|
|
io.to(`household:${data.householdId}`).emit("list:updated", data);
|
|
|
|
});
|
|
|
|
socket.on("item:added", (data) => {
|
|
|
|
io.to(`household:${data.householdId}`).emit("item:added", data);
|
|
|
|
});
|
|
|
|
socket.on("item:toggled", (data) => {
|
|
|
|
io.to(`household:${data.householdId}`).emit("item:toggled", data);
|
|
|
|
});
|
|
|
|
socket.on("item:removed", (data) => {
|
|
|
|
io.to(`household:${data.householdId}`).emit("item:removed", data);
|
|
|
|
});
|
|
|
|
socket.on("disconnect", () => {
|
|
|
|
console.log("❌ Gebruiker verbroken:", socket.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|