import Column from "@entity-access/entity-access/dist/decorators/Column.js"; import Table from "@entity-access/entity-access/dist/decorators/Table.js"; import { RelateTo, RelateToOne } from "@entity-access/entity-access/dist/decorators/Relate.js"; import type UserMailbox from "./UserMailbox.js"; import EmailAddress from "./EmailAddress.js"; import type MailboxContact from "./MailboxContact.js"; import type MailboxContactEmail from "./MailboxContactEmail.js"; import type ChannelEmail from "./ChannelEmail.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; import type UserPin from "./UserPin.js"; import type Contact from "./Contact.js"; import type MailboxSyncTarget from "./MailboxSyncTarget.js"; import AppFile from "./AppFile.js"; import Sql from "@entity-access/entity-access/dist/sql/Sql.js"; import type SubscriberActivity from "./SubscriberActivity.js"; import { IgnoreJsonProperty, JsonProperty, ReadOnlyJsonProperty } from "@entity-access/server-pages/dist/services/ModelService.js"; import type ChannelConfig from "./ChannelConfig.js"; import type { WebSiteChannel } from "./WebSiteChannel.js"; import Domain from "./Domain.js"; import type MailboxFolder from "./MailboxFolder.js"; import type MailboxTag from "./MailboxTag.js"; import Index from "@entity-access/entity-access/dist/decorators/Index.js"; import type MailboxContactEvent from "./MailboxContactEvent.js"; import type WebHook from "./WebHook.js"; import { subscriptionType, subscriptionTypes } from "./SubscriptionType.js"; import type Signature from "./Signature.js"; /** * MailBox ID is number because foreign key on Email will * require less storage compared to long email addresses. * Average number of bytes used in email address would be * roughly 40 bytes. BTree for 40 bytes would be large * compared to 8 bytes of bigint for MailBoxID. And each * related entities will also require less storage compared to * actual email address, as MailboxThread, MailboxThreadEmail * tables will be frequently accessed and BTree indexes on those * tables will grow exponentially in time. */ @Table("Mailboxes") @Index({ name: "UX_Mailbox_UniqueAddress", columns: [ { name: (x) => x.uniqueAddress, descending: false } ], unique: true, filter: (x) => x.uniqueAddress !== null }) @Index({ name: "UX_Mailbox_Moderation_Queue_Count", columns: [ { name: (x) => x.pendingModerationCount, descending: true } ], filter: (x) => x.isChannel === true }) @Index({ name: "IX_Mailbox_AutoDeleteMails", columns: [ { name: (x) => x.autoDeleteAfterDays, descending: true }, ], filter: (x) => x.autoDeleteAfterDays !== null }) export default class Mailbox { @Column({ key: true }) @RelateToOne(EmailAddress, { property: (mb) => mb.emailAddress, inverseProperty: (ea) => ea.mailbox }) public mailboxID: number; @Column({ dataType: "BigInt"}) @RelateTo(Domain, { property: (mb) => mb.domain, inverseProperty: (d) => d.mailboxes }) public domainID: number; @Column({ dataType: "BigInt", default: () => 0, }) public storage: number; @Column({ dataType: "BigInt", default: () => 250*1024*1024}) public maxStorage: number; /** * Be careful, this will increase the database search size. */ @Column({ default: () => false }) public indexAttachments: boolean; /** * Be careful, this will increase the database search size. */ @Column({ default: () => false }) public indexImageAttachments: boolean; @Column({ dataType: "BigInt", nullable: true }) @IgnoreJsonProperty public firstID: number; @Column({ dataType: "BigInt", nullable: true }) @IgnoreJsonProperty public recentID: number; /** * When set, this will make sure that the address is unique, * this is important when we want to create email address * that are separated by dot and dashes. */ @Column({ dataType: "Char", length: 400, nullable: true}) @IgnoreJsonProperty public uniqueAddress: string; // @Column({ dataType: "Int", default: () => 0}) // @ReadOnlyJsonProperty // public openContacts: number; // @Column({ dataType: "Int", default: () => 0}) // @ReadOnlyJsonProperty // public totalContacts: number; @Column({ dataType: "Int", default: () => 0}) @ReadOnlyJsonProperty public openThreads: number; @Column({ dataType: "Int", default: () => 0}) @ReadOnlyJsonProperty public totalThreads: number; @Column({ dataType: "Int", default: () => 0}) @ReadOnlyJsonProperty public pendingModerationCount: number; @Column({ dataType: "Int", default: () => 0}) @ReadOnlyJsonProperty public unread: number; @Column({ dataType: "BigInt", nullable: true}) @RelateTo(AppFile, { property: (x) => x.logo, inverseProperty: (x) => x.mailboxLogos, foreignKeyConstraint: { onDelete: "set-null" } }) public logoID: number; @Column({ dataType: "Boolean", default: () => false }) public isExternal: boolean; @Column({ dataType: "Decimal", default: () => 1/15}) public maxSendPerSecond: number; @Column({ dataType: "Char", nullable: true }) public description: string; @Column({ dataType: "DateTime", default: () => Sql.date.now()}) public dateCreated: DateTime; @Column({ dataType: "DateTime", default: () => Sql.date.now()}) public dateUpdated: DateTime; @Column({ dataType: "Boolean", default: () => false }) public isChannel: boolean; @Column({ dataType: "Boolean", default: () => false }) public isPrivateChannel: boolean; @Column({ dataType: "Boolean", default: () => false }) public membersCanPostTopLevel: boolean; @Column({ dataType: "Boolean", default: () => false }) public nonMembersCanPost: boolean; @Column({ dataType: "Boolean", default: () => true }) public nonMembersCanComment: boolean; @Column({ dataType: "Boolean", default: () => true }) public nonMembersCanReact: boolean; @Column({ dataType: "Boolean", default: () => true }) public requiresMembershipApproval: boolean; @Column({ dataType: "Boolean", default: () => true }) public requiresPostModeration: boolean; @Column({ dataType: "Boolean", default: () => true }) public requiresCommentModeration: boolean; @Column({ dataType: "Boolean", default: () => true }) public requiresSignup: boolean; @Column({ dataType: "Int", default: () => 0 }) public subscriberCount: number; @Column({ dataType: "AsciiChar", length: 20, nullable: true, enum: subscriptionTypes}) public subscriptionType: subscriptionType; @Column({ dataType: "Char", length: 200, nullable: true}) public channelVideoWatermark: string; /** * Date of recent email published on channel either on private or public */ @Column({ dataType: "DateTime", nullable: true }) public datePublished: DateTime; /** * Date of recent email engagement on channel either on private or public */ @Column({ dataType: "DateTime", nullable: true}) public dateEngaged: DateTime; /** Enable Lead Management, opens folder after save and send */ @Column( {dataType: "Boolean", default: () => false }) public enableLeads: boolean; /** * This is utilized internally to track, some of related actions * such as subscribe/unsubscribe of channel mailbox. */ @Column({ dataType: "BigInt", nullable: true}) @IgnoreJsonProperty public parentID: number; @Column({ dataType: "Int", nullable: true}) public autoDeleteAfterDays: number; public logo: AppFile; /** * Used for creating the mailbox */ @JsonProperty() public username: string; /** * Used for creating external email address, when domainID cannot be created by user */ @JsonProperty() public externalEmailAddress: string; @JsonProperty() public name: string; /** * Used at client end ... */ @JsonProperty() public notify: boolean; @JsonProperty() public deleteVerificationID: string; @JsonProperty() public authorName: string; @JsonProperty() public authorEmail: string; @JsonProperty() public addSubscribers: string; public channelConfig: ChannelConfig; public domain: Domain; public emails: ChannelEmail[]; public userMailboxes: UserMailbox[]; public emailAddress: EmailAddress; public mailboxContacts: MailboxContact[]; public threadEmails: MailboxContactEmail[]; public userPins: UserPin[]; public contacts: Contact[]; public syncTargets: MailboxSyncTarget[]; public subscriberActivities: SubscriberActivity[]; public websiteChannels: WebSiteChannel[]; folders: MailboxFolder[]; tags: MailboxTag[]; mailboxEvents: MailboxContactEvent[]; webHooks: WebHook[]; signatures: Signature[]; // [GraphService.init](sp) { // const su = ServiceProvider.resolve(sp, SessionUser); // if (ScopeVars.fromScope(su).fromWebSite) { // this.channelConfig = void 0; // this.contacts = void 0; // this.deleteVerificationID = void 0; // this.externalEmailAddress = void 0; // this.storage = void 0; // this.indexAttachments = void 0; // this.indexImageAttachments = void 0; // this.maxSendPerSecond = void 0; // this.nonMembersCanComment = void 0; // this.nonMembersCanPost = void 0; // this.nonMembersCanReact = void 0; // this.threadEmails = void 0; // this.totalThreads = void 0; // } // } }