diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-05-30 23:34:07 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-05-30 23:34:07 +0200 |
commit | 2fa12784a1f6a49a858bd263308a7d2f890034a0 (patch) | |
tree | bfc4a092c2fd81b6f9e57751178b3d144bc8f0da /src | |
parent | 1.3.14 (diff) | |
download | server-2fa12784a1f6a49a858bd263308a7d2f890034a0.tar.xz |
:sparkles: Channel recipients
Diffstat (limited to 'src')
-rw-r--r-- | src/models/Channel.ts | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/models/Channel.ts b/src/models/Channel.ts index 19d5c32b..d96a80dc 100644 --- a/src/models/Channel.ts +++ b/src/models/Channel.ts @@ -1,6 +1,7 @@ import { Schema, model, Types, Document } from "mongoose"; import db from "../util/Database"; import toBigInt from "../util/toBigInt"; +import { UserModel } from "./User"; // @ts-ignore export interface AnyChannel extends Channel, DMChannel, TextChannel, VoiceChannel { @@ -14,12 +15,12 @@ export interface ChannelDocument extends Document, AnyChannel { export const ChannelSchema = new Schema({ id: String, created_at: { type: Schema.Types.Date, required: true }, - name: { type: String, required: true }, + name: String, // can't be required for dm channels type: { type: Number, required: true }, guild_id: String, owner_id: String, parent_id: String, - recipients: [String], + recipient_ids: [String], position: Number, last_message_id: String, last_pin_timestamp: Date, @@ -36,6 +37,13 @@ export const ChannelSchema = new Schema({ ], }); +ChannelSchema.virtual("recipients", { + ref: UserModel, + localField: "recipient_ids", + foreignField: "id", + justOne: false, + autopopulate: true, +}); // @ts-ignore export const ChannelModel = db.model<ChannelDocument>("Channel", ChannelSchema, "channels"); @@ -49,7 +57,6 @@ export interface Channel { export interface TextBasedChannel { last_message_id?: string; last_pin_timestamp?: number; - recipients: null; } export interface GuildChannel extends Channel { @@ -85,7 +92,7 @@ export interface TextChannel extends GuildChannel, TextBasedChannel { // @ts-ignore export interface DMChannel extends Channel, TextBasedChannel { owner_id: string; - recipients: string[]; + recipient_ids: string[]; } export enum ChannelType { |