mirror of
https://github.com/Troplo/Colubrina.git
synced 2024-11-22 19:27:55 +11:00
1.0.7
This commit is contained in:
parent
ad48cce336
commit
ef4345c53f
4 changed files with 165 additions and 153 deletions
|
@ -38,7 +38,8 @@ let Errors = {
|
||||||
"Registrations are currently disabled on this instance. Please try again later.",
|
"Registrations are currently disabled on this instance. Please try again later.",
|
||||||
400
|
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) {
|
function processErrors(errorName) {
|
||||||
|
|
|
@ -2,12 +2,16 @@ const express = require("express")
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
const Errors = require("../lib/errors.js")
|
const Errors = require("../lib/errors.js")
|
||||||
const auth = require("../lib/authorize.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(
|
router.delete("/:id/:associationId", auth, async (req, res, next) => {
|
||||||
"/association/:id/:associationId",
|
|
||||||
auth,
|
|
||||||
async (req, res, next) => {
|
|
||||||
try {
|
try {
|
||||||
const io = req.app.get("io")
|
const io = req.app.get("io")
|
||||||
const chat = await ChatAssociation.findOne({
|
const chat = await ChatAssociation.findOne({
|
||||||
|
@ -49,8 +53,7 @@ router.delete(
|
||||||
if (!association) {
|
if (!association) {
|
||||||
throw Errors.chatNotFoundOrNotAdmin
|
throw Errors.chatNotFoundOrNotAdmin
|
||||||
}
|
}
|
||||||
if(association.chat)
|
if (association.chat) await association.destroy()
|
||||||
await association.destroy()
|
|
||||||
res.sendStatus(204)
|
res.sendStatus(204)
|
||||||
const message = await Message.create({
|
const message = await Message.create({
|
||||||
userId: 0,
|
userId: 0,
|
||||||
|
@ -146,9 +149,8 @@ router.delete(
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err)
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
router.put("/:id/:associationId", auth, async (req, res, next) => {
|
||||||
router.put("/association/:id/:associationId", auth, async (req, res, next) => {
|
|
||||||
try {
|
try {
|
||||||
const chat = await ChatAssociation.findOne({
|
const chat = await ChatAssociation.findOne({
|
||||||
where: {
|
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 {
|
try {
|
||||||
const io = req.app.get("io")
|
const io = req.app.get("io")
|
||||||
const chat = await ChatAssociation.findOne({
|
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 {
|
try {
|
||||||
const io = req.app.get("io")
|
const io = req.app.get("io")
|
||||||
const chat = await ChatAssociation.findOne({
|
const chat = await ChatAssociation.findOne({
|
||||||
where: {
|
where: {
|
||||||
userId: req.user.id,
|
userId: req.user.id,
|
||||||
id: req.params.id
|
id: req.params.id
|
||||||
|
},
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Chat,
|
||||||
|
as: "chat"
|
||||||
}
|
}
|
||||||
|
]
|
||||||
})
|
})
|
||||||
if (chat) {
|
if (chat) {
|
||||||
|
if (chat.chat.type === "direct") {
|
||||||
|
throw Errors.leavingDirectChat
|
||||||
|
}
|
||||||
await chat.destroy()
|
await chat.destroy()
|
||||||
res.sendStatus(204)
|
res.sendStatus(204)
|
||||||
const message = await Message.create({
|
const message = await Message.create({
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "colubrina-chat",
|
"name": "colubrina-chat",
|
||||||
"version": "1.0.6",
|
"version": "1.0.7",
|
||||||
"private": true,
|
"private": true,
|
||||||
"author": "Troplo <troplo@troplo.com>",
|
"author": "Troplo <troplo@troplo.com>",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|
|
@ -743,7 +743,7 @@ export default {
|
||||||
},
|
},
|
||||||
removeUserFromGroup(user) {
|
removeUserFromGroup(user) {
|
||||||
this.axios
|
this.axios
|
||||||
.delete("/api/v1/association/" + this.settings.item.id + "/" + user.id)
|
.delete("/api/v1/associations/" + this.settings.item.id + "/" + user.id)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.$toast.success("User has been removed from the group.")
|
this.$toast.success("User has been removed from the group.")
|
||||||
})
|
})
|
||||||
|
@ -753,7 +753,7 @@ export default {
|
||||||
},
|
},
|
||||||
giveUserAdmin(user) {
|
giveUserAdmin(user) {
|
||||||
this.axios
|
this.axios
|
||||||
.put("/api/v1/association/" + this.settings.item.id + "/" + user.id, {
|
.put("/api/v1/associations/" + this.settings.item.id + "/" + user.id, {
|
||||||
rank: "admin"
|
rank: "admin"
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
@ -788,7 +788,7 @@ export default {
|
||||||
},
|
},
|
||||||
addMembersToGroup() {
|
addMembersToGroup() {
|
||||||
this.axios
|
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
|
users: this.settings.addMembers.users
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
@ -805,7 +805,7 @@ export default {
|
||||||
},
|
},
|
||||||
leaveGroup() {
|
leaveGroup() {
|
||||||
this.axios
|
this.axios
|
||||||
.delete("/api/v1/association/" + this.leave.item.id)
|
.delete("/api/v1/associations/" + this.leave.item.id)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.leave.dialog = false
|
this.leave.dialog = false
|
||||||
this.$store.state.chats = this.$store.state.chats.filter(
|
this.$store.state.chats = this.$store.state.chats.filter(
|
||||||
|
|
Loading…
Reference in a new issue