diff --git a/backend/models/users.js b/backend/models/users.js index 7ab4243..8b894d9 100644 --- a/backend/models/users.js +++ b/backend/models/users.js @@ -41,8 +41,8 @@ module.exports = (sequelize, DataTypes) => { msg: "Username is required" }, len: { - args: [2, 12], - msg: "Username must be between 2 and 12 characters" + args: [2, 16], + msg: "Username must be between 2 and 16 characters" }, regex: { args: /^[a-z0-9_-]+$/i, diff --git a/backend/routes/communications.js b/backend/routes/communications.js index da59021..9b40c76 100644 --- a/backend/routes/communications.js +++ b/backend/routes/communications.js @@ -378,6 +378,10 @@ router.delete( chatId: chat.chat.id }, include: [ + { + model: Chat, + as: "chat" + }, { model: User, as: "user", @@ -391,6 +395,9 @@ router.delete( if (!association) { throw Errors.chatNotFoundOrNotAdmin } + if(association.chat.type === "direct") { + throw Errors.invalidParameter("association id", "You cannot leave direct messages") + } await association.destroy() res.sendStatus(204) const message = await Message.create({ diff --git a/frontend/package.json b/frontend/package.json index 6731f4e..00b3281 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "colubrina-chat", - "version": "1.0.3", + "version": "1.0.4", "private": true, "author": "Troplo ", "license": "GPL-3.0", diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 14c0422..588ee31 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -534,7 +534,7 @@ export default { ).unread += 1 if ( (message.userId !== this.$store.state.user.id && - this.$route.params?.id !== message.associationId && + parseInt(this.$route.params?.id) !== message.associationId && this.$store.state.user?.storedStatus !== "busy") || (message.userId !== this.$store.state.user.id && this.$store.state.user?.storedStatus !== "busy" && diff --git a/frontend/src/components/CommsInput.vue b/frontend/src/components/CommsInput.vue index 0629578..636920e 100644 --- a/frontend/src/components/CommsInput.vue +++ b/frontend/src/components/CommsInput.vue @@ -29,7 +29,7 @@ outlined append-outer-icon="mdi-send" auto-grow - @keyup.up="editLastMessage" + @keyup.up="handleEditMessage" @keyup.esc="handleEsc" @click:append-outer="handleMessage()" @keydown.enter.exact.prevent="handleMessage()" @@ -111,6 +111,11 @@ export default { } }, methods: { + handleEditMessage() { + if(!this.message?.length) { + this.editLastMessage() + } + }, handleMessage() { if (this.edit) { this.editMessage() @@ -134,7 +139,6 @@ export default { .then(() => { this.edit.editing = false this.edit.id = null - this.edit.content = "" this.focusInput() this.endEdit() // response will be handled via WebSocket @@ -234,7 +238,6 @@ export default { ) .then(() => { this.focusInput() - this.message = "" this.autoScroll() this.endSend() }) @@ -264,7 +267,6 @@ export default { ) .then(() => { this.focusInput() - this.message = "" this.autoScroll() this.endSend() this.file = null diff --git a/frontend/src/components/Header.vue b/frontend/src/components/Header.vue index b9e89e7..0c8bddf 100644 --- a/frontend/src/components/Header.vue +++ b/frontend/src/components/Header.vue @@ -26,10 +26,7 @@ Group Settings Leave Group @@ -679,6 +676,12 @@ export default { ) this.settings.dialog = true }, + groupLeave(id) { + this.leave.item = this.$store.state.chats.find( + (chat) => chat.id === id + ) + this.leave.dialog = true + }, show(e, context, item, id) { e.preventDefault() this.context[context].value = false @@ -817,9 +820,11 @@ export default { .delete("/api/v1/communications/association/" + this.leave.item.id) .then(() => { this.leave.dialog = false + this.$store.state.chats = this.$store.state.chats.filter( + (chat) => chat.id !== this.leave.item.id + ) + this.$router.push("/communications/friends") this.leave.item = null - this.getChats() - this.$router.push("/communications/home") }) .catch((e) => { AjaxErrorHandler(this.$store)(e)