diff --git a/backend/routes/associations.js b/backend/routes/associations.js index 4bbba5c..bacaaf1 100644 --- a/backend/routes/associations.js +++ b/backend/routes/associations.js @@ -65,7 +65,7 @@ router.delete("/:id/:associationId", auth, async (req, res, next) => { if (!association) { throw Errors.chatNotFoundOrNotAdmin } - if (association.chat) await association.destroy() + await association.destroy() res.sendStatus(204) const message = await Message.create({ userId: 0, @@ -169,6 +169,9 @@ router.delete("/:id/:associationId", auth, async (req, res, next) => { associationId: association.id, keyId: `${message.id}-${message.updatedAt.toISOString()}` }) + io.to(association.userId).emit("memberListUpdate", { + chatId: chat.chatId + }) }) } catch (err) { next(err) @@ -215,6 +218,31 @@ router.put("/:id/:associationId", auth, async (req, res, next) => { rank: req.body.rank }) res.sendStatus(204) + const io = req.app.get("io") + const associations = await ChatAssociation.findAll({ + where: { + chatId: chat.chat.id + }, + include: [ + { + model: User, + as: "user", + attributes: [ + "username", + "name", + "avatar", + "id", + "createdAt", + "updatedAt" + ] + } + ] + }) + associations.forEach((association) => { + io.to(association.userId).emit("memberListUpdate", { + chatId: chat.chatId + }) + }) } catch (err) { next(err) } @@ -427,6 +455,9 @@ router.post("/:id", auth, async (req, res, next) => { associationId: association.id, keyId: `${message.id}-${message.updatedAt.toISOString()}` }) + io.to(association.userId).emit("memberListUpdate", { + chatId: chat.chatId + }) }) } res.sendStatus(204) @@ -561,6 +592,9 @@ router.delete("/:id", auth, async (req, res, next) => { associationId: association.id, keyId: `${message.id}-${message.updatedAt.toISOString()}` }) + io.to(association.userId).emit("memberListUpdate", { + chatId: chat.chatId + }) }) } else { throw Errors.invalidParameter("chat association id") diff --git a/frontend/package.json b/frontend/package.json index f17af02..59ecc31 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "colubrina", - "version": "1.0.28", + "version": "1.0.29", "description": "Simple instant communication.", "private": true, "author": "Troplo ", diff --git a/frontend/src/views/Communications/Communications.vue b/frontend/src/views/Communications/Communications.vue index 90c674e..4550858 100644 --- a/frontend/src/views/Communications/Communications.vue +++ b/frontend/src/views/Communications/Communications.vue @@ -24,6 +24,9 @@ export default { } }, mounted() { + this.$socket.on("memberListUpdate", () => { + this.$store.dispatch("getChats") + }) if (!this.$route.params.id) { this.$router.push("/communications/friends") }