// // Copyright © 2022 Hardcore Engineering Inc. // // Licensed under the Eclipse Public License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. You may // obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // // See the License for the specific language governing permissions and // limitations under the License. // import { Account, AnyAttribute, AttachedDoc, Class, Doc, DocumentQuery, Mixin, Ref, Space, Timestamp, Tx, TxCUD } from '@hcengineering/core' import type { Asset, IntlString, Plugin, Resource } from '@hcengineering/platform' import { plugin } from '@hcengineering/platform' import { Preference } from '@hcengineering/preference' import { IntegrationType } from '@hcengineering/setting' import { AnyComponent } from '@hcengineering/ui' import { Writable } from './types' export * from './types' /** * @public */ export interface Notification extends AttachedDoc { tx: Ref> status: NotificationStatus text: string type: Ref } /** * @public */ export enum NotificationStatus { New, Notified, Read } /** * @public */ export interface NotificationGroup extends Doc { label: IntlString icon: Asset // using for autogenerated settings objectClass?: Ref> } /** * @public */ export interface NotificationPreferencesGroup extends Doc { label: IntlString icon: Asset presenter: AnyComponent } /** * @public */ export interface NotificationTemplate { textTemplate: string htmlTemplate: string subjectTemplate: string } /** * @public */ export interface NotificationContent { title: IntlString body: IntlString intlParams: Record intlParamsNotLocalized?: Record } /** * @public */ export interface NotificationType extends Doc { // For show/hide with attributes attribute?: Ref // Is autogenerated generated: boolean // allowed to to change setting (probably we should show it, but disable toggle??) hidden: boolean label: IntlString group: Ref txClasses: Ref>[] objectClass: Ref> // not allowed to parent doc onlyOwn?: boolean // check parent doc class attachedToClass?: Ref> // use for update/mixin txes field?: string txMatch?: DocumentQuery // use for space collaborators, not object spaceSubscribe?: boolean // allowed providers and default value for it providers: Record, boolean> // templates for email (and browser/push?) templates?: NotificationTemplate // when true notification will be created for user which trigger it (default - false) allowedForAuthor?: boolean } /** * @public */ export interface NotificationProvider extends Doc { label: IntlString } /** * @public */ export interface NotificationSetting extends Preference { attachedTo: Ref type: Ref enabled: boolean } /** * @public */ export interface ClassCollaborators extends Class { fields: string[] // Ref | Ref | Ref[] | Ref[] } /** * @public */ export interface NotificationObjectPresenter extends Class { presenter: AnyComponent } /** * @public */ export interface Collaborators extends Doc { collaborators: Ref[] } /** * @public */ export interface DocUpdateTx { _id: Ref> modifiedBy: Ref modifiedOn: Timestamp isNew: boolean title?: IntlString body?: IntlString intlParams?: Record intlParamsNotLocalized?: Record } /** * @public */ export interface DocUpdates extends Doc { user: Ref attachedTo: Ref attachedToClass: Ref> hidden: boolean lastTxTime?: Timestamp txes: DocUpdateTx[] } /** * @public */ export const notificationId = 'notification' as Plugin /** * @public */ export interface NotificationClient { docUpdatesStore: Writable, DocUpdates>> docUpdates: Writable read: (_id: Ref) => Promise forceRead: (_id: Ref, _class: Ref>, space: Ref) => Promise } /** * @public */ export interface NotificationPreview extends Class { presenter: AnyComponent } /** * @public */ export type NotificationClientFactoy = () => NotificationClient /** * @public */ const notification = plugin(notificationId, { mixin: { ClassCollaborators: '' as Ref>, Collaborators: '' as Ref>, NotificationObjectPresenter: '' as Ref>, NotificationPreview: '' as Ref> }, class: { Notification: '' as Ref>, NotificationType: '' as Ref>, NotificationProvider: '' as Ref>, NotificationSetting: '' as Ref>, DocUpdates: '' as Ref>, NotificationGroup: '' as Ref>, NotificationPreferencesGroup: '' as Ref> }, ids: { NotificationSettings: '' as Ref, NotificationGroup: '' as Ref, CollaboratoAddNotification: '' as Ref }, providers: { PlatformNotification: '' as Ref, BrowserNotification: '' as Ref, EmailNotification: '' as Ref }, integrationType: { MobileApp: '' as Ref }, component: { Inbox: '' as AnyComponent, NotificationPresenter: '' as AnyComponent }, icon: { Notifications: '' as Asset, Inbox: '' as Asset, Track: '' as Asset, DontTrack: '' as Asset, Hide: '' as Asset }, space: { Notifications: '' as Ref }, string: { Notification: '' as IntlString, Notifications: '' as IntlString, DontTrack: '' as IntlString, Inbox: '' as IntlString, CommonNotificationTitle: '' as IntlString, CommonNotificationBody: '' as IntlString }, function: { GetNotificationClient: '' as Resource } }) export default notification