import Column from "@entity-access/entity-access/dist/decorators/Column.js"; import { RelateTo } from "@entity-access/entity-access/dist/decorators/Relate.js"; import Table from "@entity-access/entity-access/dist/decorators/Table.js"; import Mailbox from "./Mailbox.js"; import EmailAddress from "./EmailAddress.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; import { Email } from "./Email.js"; import Index from "@entity-access/entity-access/dist/decorators/Index.js"; import Sql from "@entity-access/entity-access/dist/sql/Sql.js"; import { JsonProperty, ReadOnlyJsonProperty } from "@entity-access/server-pages/dist/services/ModelService.js"; import type MailboxContactTag from "./MailboxContactTag.js"; import type MailboxContactEmail from "./MailboxContactEmail.js"; import type MailboxContactEvent from "./MailboxContactEvent.js"; import type WebHook from "./WebHook.js"; import { subscriptionType, subscriptionTypes } from "./SubscriptionType.js"; import type DeliveryStatus from "./DeliveryActivity.js"; import Tag from "./Tag.js"; import Contact from "./Contact.js"; export const subscriberStatus = ["invited", "added", "active", "unsubscribed", "blocked"] as const; export type subscriberStatusType = typeof subscriberStatus[number]; /** * The reason this table exist is to simply avoid Materialized views. * As the SocialMail plans to be independent of underlying Database system. * We do not want to complicate setting up views and refreshing views. * Eternity Workflows will do the job of deferring the updates. */ @Table("MailboxContacts") @Index({ name: "IX_MailBox_Thread_Tagged_DateUpdated", columns: [ { name: (x) => x.mailboxID, descending: false }, { name: (x) => x.folderTagID, descending: false }, { name: (x) => x.dateUpdated, descending: true } ] }) @Index({ name: "IX_MailBox_Thread_DateUpdated_Active", columns: [ { name: (x) => x.mailboxID, descending: false }, { name: (x) => x.priority, descending: false }, { name: (x) => x.dateUpdated, descending: true }, ], filter: (x) => x.blocked === false && x.priority !== 0 }) @Index({ name: "IX_Mailbox_Moderators", columns: [ { name: (x) => x.mailboxID, descending: false}, { name: (x) => x.emailAddressID, descending: false}, { name: (x) => x.isModerator, descending: false}, { name: (x) => x.isOwner, descending: false} ], filter: (x) => x.isModerator === true || x.isOwner === true }) export default class MailboxContact { @Column({ key: true, dataType: "BigInt", order: 1 }) @RelateTo(Mailbox,{ property: (mt) => mt.mailbox, inverseProperty: (mb) => mb.mailboxContacts, foreignKeyConstraint: { onDelete: "restrict" } }) public mailboxID: number; @Column({ key: true, dataType: "BigInt", order: 2}) @RelateTo(EmailAddress, { property: (mt) => mt.emailAddress, inverseProperty: (e) => e.threads }) public emailAddressID: number; @Column({ dataType: "BigInt", nullable: true }) @RelateTo(Tag, { property: (x) => x.folderTag, inverseProperty: (x) => x.mailboxContacts }) public folderTagID: number; @Column({ dataType: "BigInt", nullable: true}) @RelateTo(Email, { property: (mt) => mt.lastEmail, inverseProperty: (e) => e.lastEmailThreads, foreignKeyConstraint: { onDelete: "set-null" } }) public lastEmailID: number; @Column({ default: () => Sql.date.now()}) public dateCreated: DateTime; @Column({ default: () => Sql.date.now()}) public dateUpdated: DateTime; @Column({ dataType: "Int", default: () => 0}) public unread: number; // @Column({ nullable: true }) // @ReadOnlyJsonProperty // public closed: DateTime; @Column({ dataType: "Int", default: () => 0}) @ReadOnlyJsonProperty public openThreads: number; @Column({ dataType: "Int", default: () => 0}) @ReadOnlyJsonProperty public totalThreads: number; /** * We will set autoClose to true for no-reply, they will not show up on open threads. * This can be set by users. */ @Column({ default: () => false}) public autoClose: boolean; @Column({ dataType: "Int", default: () => 0}) public total: number; @Column({ nullable: true, default: () => false }) public doNotIndex: boolean; @Column({ nullable: true }) public doNotIndexAttachments: boolean; @Column({ dataType: "Boolean", default: () => false}) public isOwner: boolean; @Column({ dataType: "Boolean", default: () => false}) public isModerator: boolean; @Column({ dataType: "Boolean", default: () => false}) public canContribute: boolean; @Column({ dataType: "Int", default: () => 0}) public priority: number; @Column({ dataType: "Boolean", default: () => false}) public blocked: boolean; @Column({ dataType: "Boolean", default: () => false}) public newRequest: boolean; @Column({ dataType: "Boolean", default: () => false}) public spam: boolean; @Column({ dataType: "Boolean", default: () => false}) public mute: boolean; @Column({ dataType: "Boolean", default: () => false}) public archived: boolean; @Column({ dataType: "Boolean", default: () => false}) public alwaysArchived: boolean; @JsonProperty({}) public closeAllConversations: boolean; @Column({ dataType: "Double", default: () => 0}) public deliveryFailureRate: number; @Column({ dataType: "BigInt", nullable: true}) @RelateTo(Contact, { property: (x) => x.contact, inverseProperty: (x) => x.mailboxContacts }) public contactID: number; /** * Used at client end ... */ @JsonProperty() public notify: boolean; @Column({ dataType: "Char", length: 15, default: () => "invited", enum: subscriberStatus }) public status: subscriberStatusType; @Column({ dataType: "AsciiChar", length: 10, nullable: true, enum: subscriptionTypes }) public subscriptionType: subscriptionType; public mailbox: Mailbox; public folderTag: Tag; public emailAddress: EmailAddress; public lastEmail: Email; @JsonProperty() public emailAddressText: string; @JsonProperty() public name: string; @JsonProperty() public folderTagText: string; public tags: MailboxContactTag[]; contact: Contact; contactEmails: MailboxContactEmail[]; contactEvents: MailboxContactEvent[]; webHooks: WebHook[]; deliveryStatuses: DeliveryStatus[]; }