This commit is contained in:
Troplo 2022-07-30 18:38:11 +10:00
parent fd174f7355
commit ad48cce336
2 changed files with 20 additions and 11 deletions

View file

@ -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
},
include: [
{
model: Chat,
as: "chat",
where: {
userId: req.user.id,
type: "direct"
},
include: [
{
model: ChatAssociation,
as: "associations"
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

View file

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