Fixes #5
This commit is contained in:
Troplo 2022-09-04 14:51:19 +10:00
parent 853ea645a8
commit 88012b1930
3 changed files with 39 additions and 2 deletions

View File

@ -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")

View File

@ -1,6 +1,6 @@
{
"name": "colubrina",
"version": "1.0.28",
"version": "1.0.29",
"description": "Simple instant communication.",
"private": true,
"author": "Troplo <troplo@troplo.com>",

View File

@ -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")
}