// // 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, SortingOrder, Space, Timestamp, Tx, TxCUD } from '@hcengineering/core' import type { Asset, IntlString, Plugin, Resource } from '@hcengineering/platform' import { plugin } from '@hcengineering/platform' import { IntegrationType } from '@hcengineering/setting' import { AnyComponent, Location, ResolvedLocation } from '@hcengineering/ui' import { Readable, Writable } from './types' import { Preference } from '@hcengineering/preference' import { Action } from '@hcengineering/view' 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 const inboxId = 'inbox' 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 */ export interface ActivityMessage extends AttachedDoc { modifiedBy: Ref modifiedOn: Timestamp isPinned?: boolean reactions?: number } export type DisplayActivityMessage = DisplayDocUpdateMessage | ChatMessage export interface DisplayDocUpdateMessage extends DocUpdateMessage { previousMessages?: DocUpdateMessage[] combinedMessagesIds?: Ref[] } export type ActivityMessageExtensionKind = 'action' | 'footer' /** * @public */ export interface ActivityMessageExtension extends Doc { ofMessage: Ref> components: { kind: ActivityMessageExtensionKind, component: AnyComponent }[] } /** * @public */ export interface DocUpdateMessage extends ActivityMessage { objectId: Ref objectClass: Ref> txId: Ref> action: DocUpdateAction updateCollection?: string attributeUpdates?: DocAttributeUpdates } /** * @public */ export interface DocAttributeUpdates { attrKey: string attrClass: Ref> set: (string | number | null)[] prevValue?: any // Need for description diff added: (string | number | null)[] removed: (string | number | null)[] isMixin: boolean } export type DocUpdateAction = 'create' | 'update' | 'remove' /** * @public */ export interface ChatMessage extends ActivityMessage { message: string attachments?: number isEdited?: boolean } /** * @public */ export interface InboxNotification extends Doc { user: Ref isViewed: boolean attachedTo: Ref attachedToClass: Ref> docNotifyContext: Ref } /** * @public */ export interface DocNotifyContext extends Doc { user: Ref // Context attachedTo: Ref attachedToClass: Ref> hidden: boolean lastViewedTimestamp?: Timestamp lastUpdateTimestamp?: Timestamp } /** * @public */ export interface InboxNotificationsClient { docNotifyContextByDoc: Writable, DocNotifyContext>> docNotifyContexts: Writable inboxNotifications: Writable inboxNotificationsByContext: Readable> readDoc: (_id: Ref) => Promise readMessages: (ids: Ref[]) => Promise unreadMessages: (ids: Array>) => Promise deleteMessagesNotifications: (ids: Array>) => Promise } export type DocUpdateMessageViewletAttributesConfig = Record< string, { presenter?: AnyComponent icon?: Asset iconPresenter?: AnyComponent } > /** * @public */ export interface DocUpdateMessageViewlet extends Doc { objectClass: Ref> action: DocUpdateAction valueAttr?: string label?: IntlString labelComponent?: AnyComponent icon?: Asset component?: AnyComponent config?: DocUpdateMessageViewletAttributesConfig hideIfRemoved?: boolean onlyWithParent?: boolean } /** * @public */ export interface ChatMessageViewlet extends Doc { objectClass: Ref> label?: IntlString hidden?: boolean onlyWithParent?: boolean } /** * @public */ export interface ActivityMessagesFilter extends Doc { label: IntlString filter: Resource<(message: ActivityMessage, _class?: Ref) => boolean> } /** * @public */ export interface ActivityDoc extends Class { ignoreCollections?: string[] } /** * @public */ export type InboxNotificationsClientFactory = () => InboxNotificationsClient /** * @public */ export interface NotificationObjectPreposition extends Class { preposition: IntlString } /** * @public */ export interface NotificationAttributePresenter extends Class { presenter: AnyComponent } /** * @public */ const notification = plugin(notificationId, { mixin: { ClassCollaborators: '' as Ref>, Collaborators: '' as Ref>, NotificationObjectPresenter: '' as Ref>, NotificationPreview: '' as Ref>, ActivityDoc: '' as Ref>, NotificationObjectPreposition: '' as Ref>, NotificationAttributePresenter: '' as Ref> }, class: { Notification: '' as Ref>, NotificationType: '' as Ref>, NotificationProvider: '' as Ref>, NotificationSetting: '' as Ref>, DocUpdates: '' as Ref>, NotificationGroup: '' as Ref>, NotificationPreferencesGroup: '' as Ref>, DocNotifyContext: '' as Ref>, DocUpdateMessage: '' as Ref>, ChatMessage: '' as Ref>, ActivityMessage: '' as Ref>, InboxNotification: '' as Ref>, DocUpdateMessageViewlet: '' as Ref>, ChatMessageViewlet: '' as Ref>, ActivityMessageExtension: '' as Ref>, ActivityMessagesFilter: '' 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, NewInbox: '' as AnyComponent, NotificationPresenter: '' as AnyComponent, ActivityMessagePresenter: '' as AnyComponent, ChatMessageInput: '' as AnyComponent, NotificationCollaboratorsChanged: '' as AnyComponent, ChatMessagesPresenter: '' as AnyComponent }, activity: { TxCollaboratorsChange: '' as AnyComponent }, action: { MarkAsUnreadInboxNotification: '' as Ref, MarkAsReadInboxNotification: '' as Ref, DeleteInboxNotification: '' as Ref, DeleteChatMessage: '' as Ref }, icon: { Notifications: '' as Asset, Inbox: '' as Asset, Track: '' as Asset, DontTrack: '' as Asset, Hide: '' as Asset, Activity: '' as Asset, Emoji: '' as Asset, Thread: '' 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, Created: '' as IntlString, Changed: '' as IntlString, To: '' as IntlString, Unset: '' as IntlString, Set: '' as IntlString, Updated: '' as IntlString, UpdatedCollection: '' as IntlString, Added: '' as IntlString, Removed: '' as IntlString, From: '' as IntlString, Attributes: '' as IntlString, In: '' as IntlString, New: '' as IntlString, For: '' as IntlString, Edit: '' as IntlString, Update: '' as IntlString, Edited: '' as IntlString, ChangedCollaborators: '' as IntlString, NewCollaborators: '' as IntlString, RemovedCollaborators: '' as IntlString, Comments: '' as IntlString, NewestFirst: '' as IntlString, LeftComment: '' as IntlString, Pinned: '' as IntlString }, function: { GetNotificationClient: '' as Resource, GetInboxNotificationsClient: '' as Resource, CombineActivityMessages: '' as Resource< (messages: ActivityMessage[], order: SortingOrder) => DisplayActivityMessage[] >, SortActivityMessages: '' as Resource<(messages: ActivityMessage[], order: SortingOrder) => ActivityMessage[]> }, resolver: { Location: '' as Resource<(loc: Location) => Promise> }, filter: { AttributesFilter: '' as Resource<(message: ActivityMessage, _class?: Ref) => boolean>, ChatMessagesFilter: '' as Resource<(message: ActivityMessage, _class?: Ref) => boolean>, PinnedFilter: '' as Resource<(message: ActivityMessage, _class?: Ref) => boolean> } }) export default notification