2025-01-31 14:15:36 +01:00
|
|
|
import { model, Schema, Types } from "mongoose";
|
|
|
|
import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
|
|
|
|
import { typeCountSchema } from "@/src/models/inventoryModels/inventoryModel";
|
|
|
|
import { IMongoDate, IOid } from "@/src/types/commonTypes";
|
|
|
|
import { ITypeCount } from "@/src/types/inventoryTypes/inventoryTypes";
|
|
|
|
|
2025-04-07 05:30:29 -07:00
|
|
|
export interface IMessageClient
|
2025-04-10 07:16:30 -07:00
|
|
|
extends Omit<IMessageDatabase, "_id" | "date" | "startDate" | "endDate" | "ownerId" | "attVisualOnly" | "expiry"> {
|
2025-01-31 14:15:36 +01:00
|
|
|
_id?: IOid;
|
|
|
|
date: IMongoDate;
|
|
|
|
startDate?: IMongoDate;
|
|
|
|
endDate?: IMongoDate;
|
|
|
|
messageId: IOid;
|
|
|
|
}
|
|
|
|
|
2025-01-31 17:24:42 +01:00
|
|
|
export interface IMessageDatabase extends IMessage {
|
2025-01-31 14:15:36 +01:00
|
|
|
ownerId: Types.ObjectId;
|
2025-01-31 17:24:42 +01:00
|
|
|
date: Date; //created at
|
2025-04-10 07:16:30 -07:00
|
|
|
attVisualOnly?: boolean;
|
|
|
|
expiry?: Date;
|
2025-01-31 14:15:36 +01:00
|
|
|
_id: Types.ObjectId;
|
2025-01-31 17:24:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface IMessage {
|
2025-01-31 14:15:36 +01:00
|
|
|
sndr: string;
|
|
|
|
msg: string;
|
|
|
|
sub: string;
|
2025-01-31 17:24:42 +01:00
|
|
|
icon?: string;
|
2025-01-31 14:15:36 +01:00
|
|
|
highPriority?: boolean;
|
|
|
|
lowPrioNewPlayers?: boolean;
|
|
|
|
startDate?: Date;
|
|
|
|
endDate?: Date;
|
|
|
|
att?: string[];
|
|
|
|
countedAtt?: ITypeCount[];
|
|
|
|
transmission?: string;
|
|
|
|
arg?: Arg[];
|
2025-03-27 12:57:44 -07:00
|
|
|
gifts?: IGift[];
|
2025-01-31 17:24:42 +01:00
|
|
|
r?: boolean;
|
2025-03-10 16:40:40 -07:00
|
|
|
contextInfo?: string;
|
|
|
|
acceptAction?: string;
|
|
|
|
declineAction?: string;
|
|
|
|
hasAccountAction?: boolean;
|
2025-01-31 14:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Arg {
|
|
|
|
Key: string;
|
2025-03-17 12:23:17 -07:00
|
|
|
Tag: string | number;
|
2025-01-31 14:15:36 +01:00
|
|
|
}
|
|
|
|
|
2025-03-27 12:57:44 -07:00
|
|
|
export interface IGift {
|
|
|
|
GiftType: string;
|
|
|
|
}
|
|
|
|
|
2025-01-31 14:15:36 +01:00
|
|
|
//types are wrong
|
|
|
|
// export interface IMessageDatabase {
|
|
|
|
// _id: Types.ObjectId;
|
|
|
|
// messageId: string;
|
|
|
|
// sub: string;
|
|
|
|
// sndr: string;
|
|
|
|
// msg: string;
|
|
|
|
// startDate: Date;
|
|
|
|
// endDate: Date;
|
|
|
|
// date: Date;
|
|
|
|
// contextInfo: string;
|
|
|
|
// icon: string;
|
|
|
|
// att: string[];
|
|
|
|
// modPacks: string[];
|
|
|
|
// countedAtt: string[];
|
|
|
|
// attSpecial: string[];
|
|
|
|
// transmission: string;
|
|
|
|
// ordisReactionTransmission: string;
|
|
|
|
// arg: string[];
|
|
|
|
// r: string;
|
|
|
|
// acceptAction: string;
|
|
|
|
// declineAction: string;
|
|
|
|
// highPriority: boolean;
|
|
|
|
// lowPrioNewPlayers: boolean
|
|
|
|
// gifts: string[];
|
|
|
|
// teleportLoc: string;
|
|
|
|
// RegularCredits: string;
|
|
|
|
// PremiumCredits: string;
|
|
|
|
// PrimeTokens: string;
|
|
|
|
// Coupons: string[];
|
|
|
|
// syndicateAttachment: string[];
|
|
|
|
// tutorialTag: string;
|
|
|
|
// url: string;
|
|
|
|
// urlButtonText: string;
|
|
|
|
// cinematic: string;
|
|
|
|
// requiredLevel: string;
|
|
|
|
// }
|
2025-03-27 12:57:44 -07:00
|
|
|
|
|
|
|
const giftSchema = new Schema<IGift>(
|
|
|
|
{
|
|
|
|
GiftType: String
|
|
|
|
},
|
|
|
|
{ _id: false }
|
|
|
|
);
|
|
|
|
|
2025-01-31 14:15:36 +01:00
|
|
|
const messageSchema = new Schema<IMessageDatabase>(
|
|
|
|
{
|
|
|
|
ownerId: Schema.Types.ObjectId,
|
|
|
|
sndr: String,
|
|
|
|
msg: String,
|
|
|
|
sub: String,
|
|
|
|
icon: String,
|
|
|
|
highPriority: Boolean,
|
|
|
|
lowPrioNewPlayers: Boolean,
|
|
|
|
startDate: Date,
|
|
|
|
endDate: Date,
|
|
|
|
r: Boolean,
|
|
|
|
att: { type: [String], default: undefined },
|
2025-03-27 12:57:44 -07:00
|
|
|
gifts: { type: [giftSchema], default: undefined },
|
2025-01-31 14:15:36 +01:00
|
|
|
countedAtt: { type: [typeCountSchema], default: undefined },
|
2025-04-07 05:30:29 -07:00
|
|
|
attVisualOnly: Boolean,
|
2025-01-31 14:15:36 +01:00
|
|
|
transmission: String,
|
|
|
|
arg: {
|
|
|
|
type: [
|
|
|
|
{
|
|
|
|
Key: String,
|
2025-03-17 12:23:17 -07:00
|
|
|
Tag: Schema.Types.Mixed,
|
2025-01-31 14:15:36 +01:00
|
|
|
_id: false
|
|
|
|
}
|
|
|
|
],
|
|
|
|
default: undefined
|
2025-03-10 16:40:40 -07:00
|
|
|
},
|
|
|
|
contextInfo: String,
|
|
|
|
acceptAction: String,
|
|
|
|
declineAction: String,
|
|
|
|
hasAccountAction: Boolean
|
2025-01-31 14:15:36 +01:00
|
|
|
},
|
|
|
|
{ timestamps: { createdAt: "date", updatedAt: false }, id: false }
|
|
|
|
);
|
|
|
|
|
|
|
|
messageSchema.virtual("messageId").get(function (this: IMessageDatabase) {
|
|
|
|
return toOid(this._id);
|
|
|
|
});
|
|
|
|
|
|
|
|
messageSchema.set("toJSON", {
|
|
|
|
virtuals: true,
|
|
|
|
transform(_document, returnedObject) {
|
|
|
|
const messageDatabase = returnedObject as IMessageDatabase;
|
|
|
|
const messageClient = returnedObject as IMessageClient;
|
|
|
|
|
|
|
|
delete returnedObject._id;
|
|
|
|
delete returnedObject.__v;
|
2025-04-10 07:16:30 -07:00
|
|
|
delete returnedObject.ownerId;
|
2025-04-07 05:30:29 -07:00
|
|
|
delete returnedObject.attVisualOnly;
|
2025-04-10 07:16:30 -07:00
|
|
|
delete returnedObject.expiry;
|
2025-01-31 14:15:36 +01:00
|
|
|
|
|
|
|
messageClient.date = toMongoDate(messageDatabase.date);
|
|
|
|
|
|
|
|
if (messageDatabase.startDate && messageDatabase.endDate) {
|
|
|
|
messageClient.startDate = toMongoDate(messageDatabase.startDate);
|
|
|
|
|
|
|
|
messageClient.endDate = toMongoDate(messageDatabase.endDate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2025-03-16 08:46:02 -07:00
|
|
|
messageSchema.index({ ownerId: 1 });
|
2025-04-10 07:16:30 -07:00
|
|
|
messageSchema.index({ expiry: 1 }, { expireAfterSeconds: 0 });
|
2025-03-16 08:46:02 -07:00
|
|
|
|
2025-01-31 14:15:36 +01:00
|
|
|
export const Inbox = model<IMessageDatabase>("Inbox", messageSchema, "inbox");
|