diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2023-11-29 20:30:45 +1100 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2023-11-29 20:30:45 +1100 |
commit | fed9c79bec6eeb01bf297f1154f89ddb0e364a43 (patch) | |
tree | 6ca78f75b297938cf351dbbb6321514098f84648 | |
parent | fix sorting (diff) | |
download | server-fix/channel_ordering.tar.xz |
whatever the fuck this is fix/channel_ordering
-rw-r--r-- | src/api/routes/channels/#channel_id/index.ts | 15 | ||||
-rw-r--r-- | src/api/routes/guilds/#guild_id/channels.ts | 55 | ||||
-rw-r--r-- | src/util/entities/Channel.ts | 5 |
3 files changed, 18 insertions, 57 deletions
diff --git a/src/api/routes/channels/#channel_id/index.ts b/src/api/routes/channels/#channel_id/index.ts index 567c7c92..a67b1f4b 100644 --- a/src/api/routes/channels/#channel_id/index.ts +++ b/src/api/routes/channels/#channel_id/index.ts @@ -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, + ), + }, + ); + })(), ]); } diff --git a/src/api/routes/guilds/#guild_id/channels.ts b/src/api/routes/guilds/#guild_id/channels.ts index 68208fee..2676cb12 100644 --- a/src/api/routes/guilds/#guild_id/channels.ts +++ b/src/api/routes/guilds/#guild_id/channels.ts @@ -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 }, diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts index 169eab3d..b28bfed0 100644 --- a/src/util/entities/Channel.ts +++ b/src/util/entities/Channel.ts @@ -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, |