mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-24 16:45:16 +00:00
Removed ChannelService, more fixes
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Channel, ChannelDeleteEvent, ChannelPermissionOverwriteType, ChannelService, ChannelType, ChannelUpdateEvent, emitEvent, Recipient } from "@fosscord/util";
|
||||
import { Channel, ChannelDeleteEvent, ChannelPermissionOverwriteType, ChannelType, ChannelUpdateEvent, emitEvent, Recipient } from "@fosscord/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { handleFile, route } from "@fosscord/api";
|
||||
|
||||
@@ -28,7 +28,7 @@ router.delete("/", route({ permission: "MANAGE_CHANNELS" }), async (req: Request
|
||||
]);
|
||||
|
||||
} else if (channel.type === ChannelType.GROUP_DM) {
|
||||
await ChannelService.removeRecipientFromChannel(channel, req.user_id)
|
||||
await Channel.removeRecipientFromChannel(channel, req.user_id)
|
||||
} else {
|
||||
//TODO messages in this channel should be deleted before deleting the channel
|
||||
await Promise.all([
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import { Attachment, Channel, ChannelType, DmChannelDTO, Embed, emitEvent, getPermission, Message, MessageCreateEvent } from "@fosscord/util";
|
||||
import { Attachment, Channel, ChannelType, DmChannelDTO, Embed, emitEvent, getPermission, Message, MessageCreateEvent, Recipient } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { handleMessage, postHandleMessage, route } from "@fosscord/api";
|
||||
import multer from "multer";
|
||||
@@ -150,7 +150,6 @@ router.post(
|
||||
return res.status(400).json(error);
|
||||
}
|
||||
}
|
||||
//TODO querying the DB at every message post should be avoided, caching maybe?
|
||||
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients", "recipients.user"] })
|
||||
|
||||
const embeds = [];
|
||||
@@ -184,7 +183,8 @@ router.post(
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(channel.recipients!.map(async r => {
|
||||
//Only one recipients should be closed here, since in group DMs the recipient is deleted not closed
|
||||
await Promise.all(channel.recipients!.filter(r => r.closed).map(async r => {
|
||||
r.closed = false;
|
||||
return await r.save()
|
||||
}));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { Channel, ChannelRecipientAddEvent, ChannelService, ChannelType, DiscordApiErrors, DmChannelDTO, emitEvent, PublicUserProjection, Recipient, User } from "@fosscord/util";
|
||||
import { Channel, ChannelRecipientAddEvent, ChannelType, DiscordApiErrors, DmChannelDTO, emitEvent, PublicUserProjection, Recipient, User } from "@fosscord/util";
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
@@ -13,7 +13,7 @@ router.put("/:user_id", async (req: Request, res: Response) => {
|
||||
user_id
|
||||
].unique()
|
||||
|
||||
const new_channel = await ChannelService.createDMChannel(recipients, req.user_id)
|
||||
const new_channel = await Channel.createDMChannel(recipients, req.user_id)
|
||||
return res.status(201).json(new_channel);
|
||||
} else {
|
||||
if (channel.recipients!.map(r => r.user_id).includes(user_id)) {
|
||||
@@ -49,7 +49,7 @@ router.delete("/:user_id", async (req: Request, res: Response) => {
|
||||
throw DiscordApiErrors.INVALID_RECIPIENT //TODO is this the right error?
|
||||
}
|
||||
|
||||
await ChannelService.removeRecipientFromChannel(channel, user_id)
|
||||
await Channel.removeRecipientFromChannel(channel, user_id)
|
||||
|
||||
return res.sendStatus(204);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { Recipient, ChannelService, DmChannelDTO } from "@fosscord/util";
|
||||
import { Recipient, DmChannelDTO, Channel } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
|
||||
const router: Router = Router();
|
||||
@@ -16,7 +16,7 @@ export interface DmChannelCreateSchema {
|
||||
|
||||
router.post("/", route({ body: "DmChannelCreateSchema" }), async (req: Request, res: Response) => {
|
||||
const body = req.body as DmChannelCreateSchema;
|
||||
res.json(await ChannelService.createDMChannel(body.recipients, req.user_id, body.name));
|
||||
res.json(await Channel.createDMChannel(body.recipients, req.user_id, body.name));
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user