// // 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 { ActivityMessage } from '@hcengineering/activity' import { Account, AnyAttribute, AttachedDoc, Class, Doc, DocumentQuery, Mixin, Ref, Space, Timestamp, Tx, TxCUD, TxOperations } 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, Location, ResolvedLocation } from '@hcengineering/ui' import { Action, Viewlet, ViewletDescriptor } from '@hcengineering/view' import { Readable, 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 } export interface BaseNotificationType extends Doc { label: IntlString // Is autogenerated generated: boolean // allowed to change setting (probably we should show it, but disable toggle??) hidden: boolean group: Ref // allowed providers and default value for it providers: Record, boolean> // templates for email (and browser/push?) templates?: NotificationTemplate } /** * @public */ export interface NotificationType extends BaseNotificationType { // For show/hide with attributes attribute?: 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 // when true notification will be created for user which trigger it (default - false) allowedForAuthor?: boolean } export interface CommonNotificationType extends BaseNotificationType {} /** * @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 * @deprecated */ export interface DocUpdateTx { _id: Ref> modifiedBy: Ref modifiedOn: Timestamp isNew: boolean title?: IntlString body?: IntlString intlParams?: Record intlParamsNotLocalized?: Record } /** * @public * @deprecated */ 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 NotificationPreview extends Class { presenter: AnyComponent } /** * @public */ export interface NotificationContextPresenter extends Class { labelPresenter?: AnyComponent } /** * @public */ export interface InboxNotification extends Doc { user: Ref isViewed: boolean docNotifyContext: Ref // For browser notifications title?: IntlString body?: IntlString intlParams?: Record intlParamsNotLocalized?: Record } export interface ActivityInboxNotification extends InboxNotification { attachedTo: Ref attachedToClass: Ref> } export interface CommonInboxNotification extends InboxNotification { header?: IntlString message?: IntlString messageHtml?: string props?: Record icon?: Asset iconProps?: Record } export interface DisplayActivityInboxNotification extends ActivityInboxNotification { combinedIds: Ref[] } export type DisplayInboxNotification = DisplayActivityInboxNotification | InboxNotification /** * @public */ export interface DocNotifyContext extends Doc { user: Ref // Context attachedTo: Ref attachedToClass: Ref> hidden: boolean isPinned?: boolean lastViewedTimestamp?: Timestamp lastUpdateTimestamp?: Timestamp } /** * @public */ export interface InboxNotificationsClient { docNotifyContextByDoc: Writable, DocNotifyContext>> docNotifyContexts: Writable inboxNotifications: Readable activityInboxNotifications: Writable inboxNotificationsByContext: Readable, InboxNotification[]>> readDoc: (client: TxOperations, _id: Ref) => Promise forceReadDoc: (client: TxOperations, _id: Ref, _class: Ref>) => Promise readMessages: (client: TxOperations, ids: Ref[]) => Promise readNotifications: (client: TxOperations, ids: Array>) => Promise unreadNotifications: (client: TxOperations, ids: Array>) => Promise deleteNotifications: (client: TxOperations, ids: Array>) => Promise deleteAllNotifications: () => Promise readAllNotifications: () => Promise } /** * @public */ export type InboxNotificationsClientFactory = () => InboxNotificationsClient /** * @public */ export interface ActivityNotificationViewlet extends Doc { messageMatch: DocumentQuery presenter: AnyComponent } /** * @public */ const notification = plugin(notificationId, { mixin: { ClassCollaborators: '' as Ref>, Collaborators: '' as Ref>, NotificationObjectPresenter: '' as Ref>, NotificationPreview: '' as Ref>, NotificationContextPresenter: '' as Ref> }, class: { Notification: '' as Ref>, BaseNotificationType: '' as Ref>, NotificationType: '' as Ref>, CommonNotificationType: '' as Ref>, NotificationProvider: '' as Ref>, NotificationSetting: '' as Ref>, DocUpdates: '' as Ref>, NotificationGroup: '' as Ref>, NotificationPreferencesGroup: '' as Ref>, DocNotifyContext: '' as Ref>, InboxNotification: '' as Ref>, ActivityInboxNotification: '' as Ref>, CommonInboxNotification: '' as Ref>, ActivityNotificationViewlet: '' as Ref> }, ids: { NotificationSettings: '' as Ref, NotificationGroup: '' as Ref, CollaboratoAddNotification: '' as Ref, MentionCommonNotificationType: '' as Ref }, providers: { PlatformNotification: '' as Ref, BrowserNotification: '' as Ref, EmailNotification: '' as Ref }, integrationType: { MobileApp: '' as Ref }, component: { Inbox: '' as AnyComponent, NotificationPresenter: '' as AnyComponent, NotificationCollaboratorsChanged: '' as AnyComponent, DocNotifyContextPresenter: '' as AnyComponent, InboxFlatListView: '' as AnyComponent, InboxGroupedListView: '' as AnyComponent }, activity: { TxCollaboratorsChange: '' as AnyComponent }, viewlet: { FlatList: '' as Ref, InboxFlatList: '' as Ref, GroupedList: '' as Ref, InboxGroupedList: '' as Ref }, action: { MarkAsUnreadInboxNotification: '' as Ref, MarkAsReadInboxNotification: '' as Ref, DeleteInboxNotification: '' as Ref, PinDocNotifyContext: '' as Ref, UnpinDocNotifyContext: '' as Ref, HideDocNotifyContext: '' as Ref, UnHideDocNotifyContext: '' as Ref, UnReadNotifyContext: '' as Ref, ReadNotifyContext: '' as Ref, DeleteContextNotifications: '' as Ref }, 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, ChangedCollaborators: '' as IntlString, NewCollaborators: '' as IntlString, RemovedCollaborators: '' as IntlString, Edited: '' as IntlString, Pinned: '' as IntlString, FlatList: '' as IntlString, GroupedList: '' as IntlString, All: '' as IntlString, ArchiveAll: '' as IntlString, ReadAll: '' as IntlString, ArchiveAllConfirmationTitle: '' as IntlString, ArchiveAllConfirmationMessage: '' as IntlString }, function: { GetInboxNotificationsClient: '' as Resource, HasHiddenDocNotifyContext: '' as Resource<(doc: Doc[]) => Promise>, IsDocNotifyContextHidden: '' as Resource<(doc?: Doc | Doc[]) => Promise>, IsDocNotifyContextTracked: '' as Resource<(doc?: Doc | Doc[]) => Promise>, HasInboxNotifications: '' as Resource< (notificationsByContext: Map, InboxNotification[]>) => Promise > }, resolver: { Location: '' as Resource<(loc: Location) => Promise> } }) export default notification