2022-02-07 09:03:14 +00:00
|
|
|
//
|
2022-06-19 16:28:31 +00:00
|
|
|
// Copyright © 2022 Hardcore Engineering Inc.
|
2022-02-07 09:03:14 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
|
2023-04-25 08:34:38 +00:00
|
|
|
import {
|
|
|
|
Account,
|
|
|
|
AnyAttribute,
|
|
|
|
AttachedDoc,
|
|
|
|
Class,
|
|
|
|
Doc,
|
2023-06-01 05:48:36 +00:00
|
|
|
DocumentQuery,
|
2023-04-25 08:34:38 +00:00
|
|
|
Mixin,
|
|
|
|
Ref,
|
|
|
|
Space,
|
|
|
|
Timestamp,
|
|
|
|
Tx,
|
|
|
|
TxCUD
|
|
|
|
} from '@hcengineering/core'
|
2022-09-21 08:08:25 +00:00
|
|
|
import type { Asset, IntlString, Plugin, Resource } from '@hcengineering/platform'
|
|
|
|
import { plugin } from '@hcengineering/platform'
|
2023-03-29 09:18:59 +00:00
|
|
|
import { IntegrationType } from '@hcengineering/setting'
|
2022-09-21 08:08:25 +00:00
|
|
|
import { AnyComponent } from '@hcengineering/ui'
|
|
|
|
import { Writable } from './types'
|
2023-04-25 08:34:38 +00:00
|
|
|
import { Preference } from '@hcengineering/preference'
|
2022-09-21 08:08:25 +00:00
|
|
|
export * from './types'
|
2022-02-07 09:03:14 +00:00
|
|
|
|
2022-02-11 09:18:55 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface Notification extends AttachedDoc {
|
|
|
|
tx: Ref<TxCUD<Doc>>
|
|
|
|
status: NotificationStatus
|
2022-06-30 11:24:19 +00:00
|
|
|
text: string
|
|
|
|
type: Ref<NotificationType>
|
2022-02-11 09:18:55 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 09:09:13 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface EmailNotification extends Doc {
|
|
|
|
sender: string
|
|
|
|
receivers: string[]
|
|
|
|
subject: string
|
|
|
|
text: string
|
|
|
|
html?: string
|
2023-03-09 11:05:08 +00:00
|
|
|
status: 'new' | 'sent' | 'error'
|
|
|
|
error?: string
|
2022-02-22 09:09:13 +00:00
|
|
|
}
|
|
|
|
|
2022-02-11 09:18:55 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export enum NotificationStatus {
|
|
|
|
New,
|
2022-09-20 06:42:24 +00:00
|
|
|
Notified,
|
2022-02-11 09:18:55 +00:00
|
|
|
Read
|
|
|
|
}
|
|
|
|
|
2022-02-22 09:09:13 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2023-04-25 08:34:38 +00:00
|
|
|
export interface NotificationGroup extends Doc {
|
2022-02-22 09:09:13 +00:00
|
|
|
label: IntlString
|
2023-04-25 08:34:38 +00:00
|
|
|
icon: Asset
|
|
|
|
// using for autogenerated settings
|
|
|
|
objectClass?: Ref<Class<Doc>>
|
|
|
|
}
|
|
|
|
|
2023-09-05 05:31:09 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface NotificationPreferencesGroup extends Doc {
|
|
|
|
label: IntlString
|
|
|
|
icon: Asset
|
|
|
|
presenter: AnyComponent
|
|
|
|
}
|
|
|
|
|
2023-04-25 08:34:38 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface NotificationTemplate {
|
2022-10-26 10:24:39 +00:00
|
|
|
textTemplate: string
|
|
|
|
htmlTemplate: string
|
|
|
|
subjectTemplate: string
|
2022-02-22 09:09:13 +00:00
|
|
|
}
|
|
|
|
|
2023-04-25 08:34:38 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface NotificationType extends Doc {
|
|
|
|
// For show/hide with attributes
|
|
|
|
attribute?: Ref<AnyAttribute>
|
|
|
|
// Is autogenerated
|
|
|
|
generated: boolean
|
|
|
|
// allowed to to change setting (probably we should show it, but disable toggle??)
|
|
|
|
hidden: boolean
|
|
|
|
label: IntlString
|
|
|
|
group: Ref<NotificationGroup>
|
|
|
|
txClasses: Ref<Class<Tx>>[]
|
|
|
|
objectClass: Ref<Class<Doc>>
|
2023-09-22 06:10:35 +00:00
|
|
|
// not allowed to parent doc
|
|
|
|
onlyOwn?: boolean
|
2023-04-25 08:34:38 +00:00
|
|
|
// check parent doc class
|
|
|
|
attachedToClass?: Ref<Class<Doc>>
|
|
|
|
// use for update/mixin txes
|
|
|
|
field?: string
|
2023-06-01 05:48:36 +00:00
|
|
|
txMatch?: DocumentQuery<Tx>
|
2023-04-28 08:22:39 +00:00
|
|
|
// use for space collaborators, not object
|
|
|
|
spaceSubscribe?: boolean
|
2023-04-25 08:34:38 +00:00
|
|
|
// allowed providers and default value for it
|
|
|
|
providers: Record<Ref<NotificationProvider>, boolean>
|
|
|
|
// templates for email (and browser/push?)
|
|
|
|
templates?: NotificationTemplate
|
2023-05-05 09:37:01 +00:00
|
|
|
// when true notification will be created for user which trigger it (default - false)
|
|
|
|
allowedForAuthor?: boolean
|
2023-04-25 08:34:38 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 09:09:13 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface NotificationProvider extends Doc {
|
|
|
|
label: IntlString
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2023-04-25 08:34:38 +00:00
|
|
|
export interface NotificationSetting extends Preference {
|
|
|
|
attachedTo: Ref<NotificationProvider>
|
2022-02-22 09:09:13 +00:00
|
|
|
type: Ref<NotificationType>
|
|
|
|
enabled: boolean
|
|
|
|
}
|
|
|
|
|
2023-03-29 09:18:59 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface ClassCollaborators extends Class<Doc> {
|
|
|
|
fields: string[] // Ref<Account> | Ref<Employee> | Ref<Account>[] | Ref<Employee>[]
|
|
|
|
}
|
2022-06-10 17:59:09 +00:00
|
|
|
|
2023-04-05 07:12:06 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface NotificationObjectPresenter extends Class<Doc> {
|
|
|
|
presenter: AnyComponent
|
|
|
|
}
|
|
|
|
|
2023-03-29 09:18:59 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface Collaborators extends Doc {
|
|
|
|
collaborators: Ref<Account>[]
|
2022-06-10 17:59:09 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 06:35:48 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface DocUpdateTx {
|
|
|
|
_id: Ref<TxCUD<Doc>>
|
|
|
|
modifiedBy: Ref<Account>
|
|
|
|
modifiedOn: Timestamp
|
|
|
|
isNew: boolean
|
|
|
|
}
|
|
|
|
|
2023-04-05 07:12:06 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface DocUpdates extends Doc {
|
|
|
|
user: Ref<Account>
|
|
|
|
attachedTo: Ref<Doc>
|
|
|
|
attachedToClass: Ref<Class<Doc>>
|
2023-04-06 14:25:58 +00:00
|
|
|
hidden: boolean
|
2023-04-29 15:46:13 +00:00
|
|
|
lastTxTime?: Timestamp
|
2023-05-24 06:35:48 +00:00
|
|
|
txes: DocUpdateTx[]
|
2023-04-05 07:12:06 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 09:03:14 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export const notificationId = 'notification' as Plugin
|
|
|
|
|
2022-02-28 03:42:06 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface NotificationClient {
|
2023-04-20 07:27:02 +00:00
|
|
|
docUpdatesStore: Writable<Map<Ref<Doc>, DocUpdates>>
|
2023-04-29 15:46:13 +00:00
|
|
|
docUpdates: Writable<DocUpdates[]>
|
|
|
|
read: (_id: Ref<Doc>) => Promise<void>
|
|
|
|
forceRead: (_id: Ref<Doc>, _class: Ref<Class<Doc>>, space: Ref<Space>) => Promise<void>
|
2022-02-28 03:42:06 +00:00
|
|
|
}
|
|
|
|
|
2023-08-22 04:52:10 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface NotificationPreview extends Class<Doc> {
|
|
|
|
presenter: AnyComponent
|
|
|
|
}
|
|
|
|
|
2022-02-28 03:42:06 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export type NotificationClientFactoy = () => NotificationClient
|
|
|
|
|
2022-02-07 09:03:14 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
const notification = plugin(notificationId, {
|
2022-04-06 05:35:52 +00:00
|
|
|
mixin: {
|
2023-03-29 09:18:59 +00:00
|
|
|
ClassCollaborators: '' as Ref<Mixin<ClassCollaborators>>,
|
|
|
|
Collaborators: '' as Ref<Mixin<Collaborators>>,
|
2023-08-22 04:52:10 +00:00
|
|
|
NotificationObjectPresenter: '' as Ref<Mixin<NotificationObjectPresenter>>,
|
|
|
|
NotificationPreview: '' as Ref<Mixin<NotificationPreview>>
|
2022-04-06 05:35:52 +00:00
|
|
|
},
|
2022-02-07 09:03:14 +00:00
|
|
|
class: {
|
2022-02-22 09:09:13 +00:00
|
|
|
Notification: '' as Ref<Class<Notification>>,
|
|
|
|
EmailNotification: '' as Ref<Class<EmailNotification>>,
|
|
|
|
NotificationType: '' as Ref<Class<NotificationType>>,
|
|
|
|
NotificationProvider: '' as Ref<Class<NotificationProvider>>,
|
2023-04-05 07:12:06 +00:00
|
|
|
NotificationSetting: '' as Ref<Class<NotificationSetting>>,
|
2023-04-25 08:34:38 +00:00
|
|
|
DocUpdates: '' as Ref<Class<DocUpdates>>,
|
2023-09-05 05:31:09 +00:00
|
|
|
NotificationGroup: '' as Ref<Class<NotificationGroup>>,
|
|
|
|
NotificationPreferencesGroup: '' as Ref<Class<NotificationPreferencesGroup>>
|
2022-02-22 09:09:13 +00:00
|
|
|
},
|
|
|
|
ids: {
|
2023-05-17 05:18:05 +00:00
|
|
|
NotificationSettings: '' as Ref<Doc>,
|
|
|
|
NotificationGroup: '' as Ref<NotificationGroup>,
|
|
|
|
CollaboratoAddNotification: '' as Ref<NotificationType>
|
2023-04-25 08:34:38 +00:00
|
|
|
},
|
|
|
|
providers: {
|
2022-02-22 09:09:13 +00:00
|
|
|
PlatformNotification: '' as Ref<NotificationProvider>,
|
2022-06-30 11:24:19 +00:00
|
|
|
BrowserNotification: '' as Ref<NotificationProvider>,
|
2023-04-25 08:34:38 +00:00
|
|
|
EmailNotification: '' as Ref<NotificationProvider>
|
2022-02-11 09:18:55 +00:00
|
|
|
},
|
2022-10-26 10:25:04 +00:00
|
|
|
integrationType: {
|
|
|
|
MobileApp: '' as Ref<IntegrationType>
|
|
|
|
},
|
2022-02-11 09:18:55 +00:00
|
|
|
component: {
|
2023-04-05 07:12:06 +00:00
|
|
|
Inbox: '' as AnyComponent,
|
2023-03-29 09:18:59 +00:00
|
|
|
NotificationPresenter: '' as AnyComponent
|
2022-02-11 09:18:55 +00:00
|
|
|
},
|
|
|
|
icon: {
|
2022-02-25 09:04:57 +00:00
|
|
|
Notifications: '' as Asset,
|
2023-05-22 03:50:44 +00:00
|
|
|
Inbox: '' as Asset,
|
2022-02-25 09:04:57 +00:00
|
|
|
Track: '' as Asset,
|
2023-04-06 14:25:58 +00:00
|
|
|
DontTrack: '' as Asset,
|
|
|
|
Hide: '' as Asset
|
2022-02-07 09:03:14 +00:00
|
|
|
},
|
|
|
|
space: {
|
|
|
|
Notifications: '' as Ref<Space>
|
2022-02-11 09:18:55 +00:00
|
|
|
},
|
|
|
|
string: {
|
|
|
|
Notification: '' as IntlString,
|
2023-04-05 07:12:06 +00:00
|
|
|
Notifications: '' as IntlString,
|
2023-04-06 14:25:58 +00:00
|
|
|
DontTrack: '' as IntlString,
|
2023-04-05 07:12:06 +00:00
|
|
|
Inbox: '' as IntlString
|
2022-02-28 03:42:06 +00:00
|
|
|
},
|
|
|
|
function: {
|
|
|
|
GetNotificationClient: '' as Resource<NotificationClientFactoy>
|
2022-02-07 09:03:14 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export default notification
|