mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-30 15:54:24 +00:00
whatever the fuck this is
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
||||
ChannelModifySchema,
|
||||
ChannelType,
|
||||
ChannelUpdateEvent,
|
||||
Guild,
|
||||
Recipient,
|
||||
emitEvent,
|
||||
handleFile,
|
||||
@@ -97,6 +98,20 @@ router.delete(
|
||||
data: channel,
|
||||
channel_id,
|
||||
} as ChannelDeleteEvent),
|
||||
(async () => {
|
||||
const guild = await Guild.findOneOrFail({
|
||||
where: { id: channel.guild_id },
|
||||
select: { channel_ordering: true },
|
||||
});
|
||||
await Guild.update(
|
||||
{ id: guild.id },
|
||||
{
|
||||
channel_ordering: guild.channel_ordering.remove(
|
||||
channel.id,
|
||||
),
|
||||
},
|
||||
);
|
||||
})(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,7 @@ import {
|
||||
Channel,
|
||||
ChannelModifySchema,
|
||||
ChannelReorderSchema,
|
||||
ChannelUpdateEvent,
|
||||
Guild,
|
||||
emitEvent,
|
||||
} from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
const router = Router();
|
||||
@@ -106,59 +104,6 @@ router.patch(
|
||||
(x) => !body.find((c) => c.id == x),
|
||||
);
|
||||
|
||||
const withParents = body.filter((x) => x.parent_id != undefined);
|
||||
const withPositions = body.filter((x) => x.position != undefined);
|
||||
|
||||
await Promise.all(
|
||||
withPositions.map(async (opt) => {
|
||||
const channel = await Channel.findOneOrFail({
|
||||
where: { id: opt.id },
|
||||
});
|
||||
|
||||
channel.position = opt.position as number;
|
||||
notMentioned.splice(opt.position as number, 0, channel.id);
|
||||
|
||||
await emitEvent({
|
||||
event: "CHANNEL_UPDATE",
|
||||
data: channel,
|
||||
channel_id: channel.id,
|
||||
guild_id,
|
||||
} as ChannelUpdateEvent);
|
||||
}),
|
||||
);
|
||||
|
||||
// have to do the parents after the positions
|
||||
await Promise.all(
|
||||
withParents.map(async (opt) => {
|
||||
const [channel, parent] = await Promise.all([
|
||||
Channel.findOneOrFail({
|
||||
where: { id: opt.id },
|
||||
}),
|
||||
Channel.findOneOrFail({
|
||||
where: { id: opt.parent_id as string },
|
||||
select: { permission_overwrites: true },
|
||||
}),
|
||||
]);
|
||||
|
||||
if (opt.lock_permissions)
|
||||
await Channel.update(
|
||||
{ id: channel.id },
|
||||
{ permission_overwrites: parent.permission_overwrites },
|
||||
);
|
||||
|
||||
const parentPos = notMentioned.indexOf(parent.id);
|
||||
notMentioned.splice(parentPos + 1, 0, channel.id);
|
||||
channel.position = (parentPos + 1) as number;
|
||||
|
||||
await emitEvent({
|
||||
event: "CHANNEL_UPDATE",
|
||||
data: channel,
|
||||
channel_id: channel.id,
|
||||
guild_id,
|
||||
} as ChannelUpdateEvent);
|
||||
}),
|
||||
);
|
||||
|
||||
await Guild.update(
|
||||
{ id: guild_id },
|
||||
{ channel_ordering: notMentioned },
|
||||
|
||||
@@ -300,8 +300,9 @@ export class Channel extends BaseClass {
|
||||
// TODO: eagerly auto generate position of all guild channels
|
||||
|
||||
const position =
|
||||
(channel.type === ChannelType.UNHANDLED ? 0 : channel.position) ||
|
||||
0;
|
||||
channel.type == ChannelType.GUILD_CATEGORY
|
||||
? Number.MAX_SAFE_INTEGER // add categories to the bottom
|
||||
: channel.position ?? 0;
|
||||
|
||||
channel = {
|
||||
...channel,
|
||||
|
||||
Reference in New Issue
Block a user