Add VC Creation via Backend
This commit is contained in:
parent
7bb1e9ac70
commit
a46e08765b
@ -26,6 +26,9 @@ export default class Channels extends DBWrapper<string, ChannelDocument> {
|
||||
public async createText(guildId: string) {
|
||||
return this.create({ guildId }) as Promise<TextChannelDocument>;
|
||||
}
|
||||
public async createVoice(guildId: string) {
|
||||
return this.create({ guildId, type: 'VOICE' }) as Promise<TextChannelDocument>;
|
||||
}
|
||||
|
||||
public async getSystem(guildId: string) {
|
||||
return await Channel.findOne({ guildId, type: 'TEXT' });
|
||||
|
@ -35,9 +35,10 @@ export default class Guilds extends DBWrapper<string, GuildDocument> {
|
||||
public async create(name: string, owner: SelfUserDocument): Promise<GuildDocument> {
|
||||
const guildId = generateSnowflake();
|
||||
|
||||
const [_, __, guild] = await Promise.all([
|
||||
const [_, __, ___, guild] = await Promise.all([
|
||||
this.roles.create(guildId, { name: '@everyone' }),
|
||||
this.channels.createText(guildId),
|
||||
this.channels.createVoice(guildId),
|
||||
Guild.create({ _id: guildId, name, ownerId: owner.id }),
|
||||
]);
|
||||
await this.members.create(guildId, owner);
|
||||
@ -58,7 +59,7 @@ export default class Guilds extends DBWrapper<string, GuildDocument> {
|
||||
return await Role.find({ guildId });
|
||||
}
|
||||
public async getUsers(guildId: string) {
|
||||
const users = await User.find({ guildIds: { $in: guildId } });
|
||||
const users = await User.find({ guildIds: guildId });
|
||||
return users.map(u => this.users.secure(u));
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Socket } from 'socket.io';
|
||||
import Channels from '../../data/channels';
|
||||
import { Channel } from '../../data/models/channel';
|
||||
import { Guild } from '../../data/models/guild';
|
||||
import { generateSnowflake } from '../../data/snowflake-entity';
|
||||
@ -13,18 +14,14 @@ export default class implements WSEvent<'CHANNEL_CREATE'> {
|
||||
on = 'CHANNEL_CREATE' as const;
|
||||
|
||||
constructor(
|
||||
private guard = Deps.get<WSGuard>(WSGuard)
|
||||
private channels = Deps.get<Channels>(Channels),
|
||||
private guard = Deps.get<WSGuard>(WSGuard),
|
||||
) {}
|
||||
|
||||
public async invoke(ws: WebSocket, client: Socket, { name, guildId }: WS.Params.ChannelCreate) {
|
||||
public async invoke(ws: WebSocket, client: Socket, { name, guildId, type }: WS.Params.ChannelCreate) {
|
||||
await this.guard.validateCan(client, guildId, 'MANAGE_CHANNELS');
|
||||
|
||||
const channel = await Channel.create({
|
||||
_id: generateSnowflake(),
|
||||
name,
|
||||
guildId,
|
||||
type: 'TEXT',
|
||||
});
|
||||
const channel = await this.channels.create({ name, guildId, type });
|
||||
|
||||
await Guild.updateOne(
|
||||
{ _id: guildId },
|
||||
@ -32,13 +29,6 @@ export default class implements WSEvent<'CHANNEL_CREATE'> {
|
||||
{ runValidators: true },
|
||||
);
|
||||
|
||||
// add guild members to channel
|
||||
const clientIds = ws.io.sockets.adapter.rooms.get(guildId);
|
||||
for (const id of clientIds ?? [])
|
||||
await ws.io.sockets.sockets
|
||||
.get(id)
|
||||
?.join(channel.id);
|
||||
|
||||
ws.io
|
||||
.to(guildId)
|
||||
.emit('CHANNEL_CREATE', {
|
||||
|
@ -18,7 +18,9 @@ export default class implements WSEvent<'CHANNEL_DELETE'> {
|
||||
const channel = await this.channels.getText(channelId);
|
||||
await this.guard.validateCan(client, channel.guildId, 'MANAGE_CHANNELS');
|
||||
|
||||
await client.leave(channelId);
|
||||
// leave rooms
|
||||
ws.io.sockets.in(channelId).socketsLeave(channelId);
|
||||
|
||||
await channel.deleteOne();
|
||||
|
||||
ws.io
|
||||
|
2
types/ws.d.ts
vendored
2
types/ws.d.ts
vendored
@ -115,7 +115,7 @@ declare namespace WS {
|
||||
/** Name of the channel to create. */
|
||||
name: string;
|
||||
/** Type of the channel to create. */
|
||||
type: string;
|
||||
type: ChannelTypes.Type;
|
||||
}
|
||||
export interface ChannelDelete {
|
||||
/** ID of the channel to delete. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user