From ad48cce336fdb152d9bef3dd7faa70bcc1a66b47 Mon Sep 17 00:00:00 2001 From: Troplo Date: Sat, 30 Jul 2022 18:38:11 +1000 Subject: [PATCH] fix --- backend/routes/communications.js | 27 ++++++++++++++++----------- frontend/src/components/Header.vue | 4 ++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/backend/routes/communications.js b/backend/routes/communications.js index 97e7a2f..fb6c5b1 100644 --- a/backend/routes/communications.js +++ b/backend/routes/communications.js @@ -1555,28 +1555,33 @@ router.post("/create", auth, async (req, res, next) => { } }) if (type === "direct") { - const chats = await Chat.findAll({ + const chats = await ChatAssociation.findAll({ where: { - userId: req.user.id, - type: "direct" + userId: req.user.id }, include: [ { - model: ChatAssociation, - as: "associations" + model: Chat, + as: "chat", + where: { + type: "direct" + }, + include: [ + { + model: User, + as: "users" + } + ] } ] }) const chat = chats.find((chat) => { - return chat.associations.find((association) => { - return association.userId === req.body.users[0] - }) + const users = chat.chat.users.map((user) => user.id) + return users.includes(req.body.users[0]) && users.includes(req.user.id) }) if (chat) { res.json({ - ...chat.associations.find((association) => { - return association.userId === req.user.id - }).dataValues, + ...chat.dataValues, existing: true }) return diff --git a/frontend/src/components/Header.vue b/frontend/src/components/Header.vue index 7b7429e..9453ffe 100644 --- a/frontend/src/components/Header.vue +++ b/frontend/src/components/Header.vue @@ -953,6 +953,10 @@ export default { this.searchUsers() this.searchUsersForGroupAdmin() }) + this.$socket.on("siteState", () => { + this.searchUsers() + this.searchUsersForGroupAdmin() + }) this.$socket.on("userSettings", () => { this.$store.dispatch("getChats") })