This commit is contained in:
Troplo 2022-07-30 18:41:18 +10:00
parent ad48cce336
commit ef4345c53f
4 changed files with 165 additions and 153 deletions

View file

@ -38,7 +38,8 @@ let Errors = {
"Registrations are currently disabled on this instance. Please try again later.",
400
],
banned: ["You are banned from this instance.", 400]
banned: ["You are banned from this instance.", 400],
leavingDirectChat: ["You cannot leave a direct message.", 400]
}
function processErrors(errorName) {

View file

@ -2,12 +2,16 @@ const express = require("express")
const router = express.Router()
const Errors = require("../lib/errors.js")
const auth = require("../lib/authorize.js")
const { User, Message, ChatAssociation, Chat, Attachment, Friend} = require("../models")
const {
User,
Message,
ChatAssociation,
Chat,
Attachment,
Friend
} = require("../models")
router.delete(
"/association/:id/:associationId",
auth,
async (req, res, next) => {
router.delete("/:id/:associationId", auth, async (req, res, next) => {
try {
const io = req.app.get("io")
const chat = await ChatAssociation.findOne({
@ -49,8 +53,7 @@ router.delete(
if (!association) {
throw Errors.chatNotFoundOrNotAdmin
}
if(association.chat)
await association.destroy()
if (association.chat) await association.destroy()
res.sendStatus(204)
const message = await Message.create({
userId: 0,
@ -146,9 +149,8 @@ router.delete(
} catch (err) {
next(err)
}
}
)
router.put("/association/:id/:associationId", auth, async (req, res, next) => {
})
router.put("/:id/:associationId", auth, async (req, res, next) => {
try {
const chat = await ChatAssociation.findOne({
where: {
@ -194,7 +196,7 @@ router.put("/association/:id/:associationId", auth, async (req, res, next) => {
}
})
router.post("/association/:id", auth, async (req, res, next) => {
router.post("/:id", auth, async (req, res, next) => {
try {
const io = req.app.get("io")
const chat = await ChatAssociation.findOne({
@ -400,16 +402,25 @@ router.post("/association/:id", auth, async (req, res, next) => {
}
})
router.delete("/association/:id", auth, async (req, res, next) => {
router.delete("/:id", auth, async (req, res, next) => {
try {
const io = req.app.get("io")
const chat = await ChatAssociation.findOne({
where: {
userId: req.user.id,
id: req.params.id
},
include: [
{
model: Chat,
as: "chat"
}
]
})
if (chat) {
if (chat.chat.type === "direct") {
throw Errors.leavingDirectChat
}
await chat.destroy()
res.sendStatus(204)
const message = await Message.create({

View file

@ -1,6 +1,6 @@
{
"name": "colubrina-chat",
"version": "1.0.6",
"version": "1.0.7",
"private": true,
"author": "Troplo <troplo@troplo.com>",
"license": "GPL-3.0",

View file

@ -743,7 +743,7 @@ export default {
},
removeUserFromGroup(user) {
this.axios
.delete("/api/v1/association/" + this.settings.item.id + "/" + user.id)
.delete("/api/v1/associations/" + this.settings.item.id + "/" + user.id)
.then(() => {
this.$toast.success("User has been removed from the group.")
})
@ -753,7 +753,7 @@ export default {
},
giveUserAdmin(user) {
this.axios
.put("/api/v1/association/" + this.settings.item.id + "/" + user.id, {
.put("/api/v1/associations/" + this.settings.item.id + "/" + user.id, {
rank: "admin"
})
.then(() => {
@ -788,7 +788,7 @@ export default {
},
addMembersToGroup() {
this.axios
.post("/api/v1/association/" + this.settings.item.chat.id, {
.post("/api/v1/associations/" + this.settings.item.chat.id, {
users: this.settings.addMembers.users
})
.then(() => {
@ -805,7 +805,7 @@ export default {
},
leaveGroup() {
this.axios
.delete("/api/v1/association/" + this.leave.item.id)
.delete("/api/v1/associations/" + this.leave.item.id)
.then(() => {
this.leave.dialog = false
this.$store.state.chats = this.$store.state.chats.filter(