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-03-29 09:18:59 +00:00
|
|
|
import { Account, AttachedDoc, Class, Doc, Mixin, Ref, Space, Timestamp, 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'
|
|
|
|
export * from './types'
|
2022-02-07 09:03:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2023-03-29 09:18:59 +00:00
|
|
|
export interface LastView extends Doc {
|
2022-02-07 09:03:14 +00:00
|
|
|
user: Ref<Account>
|
2023-03-29 09:18:59 +00:00
|
|
|
[key: string]: any
|
2022-10-26 10:24:39 +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
|
|
|
|
*/
|
|
|
|
export interface NotificationType extends Doc {
|
2023-03-05 17:36:12 +00:00
|
|
|
hidden: boolean
|
2022-02-22 09:09:13 +00:00
|
|
|
label: IntlString
|
2022-10-26 10:24:39 +00:00
|
|
|
textTemplate: string
|
|
|
|
htmlTemplate: string
|
|
|
|
subjectTemplate: string
|
2022-02-22 09:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface NotificationProvider extends Doc {
|
|
|
|
label: IntlString
|
2022-03-11 09:06:33 +00:00
|
|
|
default: boolean
|
2022-02-22 09:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface NotificationSetting extends Doc {
|
|
|
|
type: Ref<NotificationType>
|
|
|
|
provider: Ref<NotificationProvider>
|
|
|
|
enabled: boolean
|
|
|
|
}
|
|
|
|
|
2022-04-06 05:35:52 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface SpaceLastEdit extends Class<Doc> {
|
|
|
|
lastEditField: string
|
|
|
|
}
|
|
|
|
|
2022-06-10 17:59:09 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2023-03-29 09:18:59 +00:00
|
|
|
export interface AnotherUserNotifications extends Class<Doc> {
|
|
|
|
fields: string[]
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2023-03-29 09:18:59 +00:00
|
|
|
export interface TrackedDoc extends Class<Doc> {}
|
|
|
|
|
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-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
|
|
|
|
lastTx: Ref<TxCUD<Doc>>
|
|
|
|
lastTxTime: Timestamp
|
2023-04-05 07:12:06 +00:00
|
|
|
txes: [Ref<TxCUD<Doc>>, Timestamp][]
|
|
|
|
}
|
|
|
|
|
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-03-29 09:18:59 +00:00
|
|
|
getLastViews: () => Writable<LastView>
|
2022-02-28 03:42:06 +00:00
|
|
|
updateLastView: (_id: Ref<Doc>, _class: Ref<Class<Doc>>, time?: Timestamp, force?: boolean) => Promise<void>
|
2022-04-06 05:35:52 +00:00
|
|
|
unsubscribe: (_id: Ref<Doc>) => Promise<void>
|
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: {
|
2022-06-10 17:59:09 +00:00
|
|
|
SpaceLastEdit: '' as Ref<Mixin<SpaceLastEdit>>,
|
|
|
|
AnotherUserNotifications: '' as Ref<Mixin<AnotherUserNotifications>>,
|
2023-03-29 09:18:59 +00:00
|
|
|
ClassCollaborators: '' as Ref<Mixin<ClassCollaborators>>,
|
|
|
|
Collaborators: '' as Ref<Mixin<Collaborators>>,
|
2023-04-05 07:12:06 +00:00
|
|
|
TrackedDoc: '' as Ref<Mixin<TrackedDoc>>,
|
|
|
|
NotificationObjectPresenter: '' as Ref<Mixin<NotificationObjectPresenter>>
|
2022-04-06 05:35:52 +00:00
|
|
|
},
|
2022-02-07 09:03:14 +00:00
|
|
|
class: {
|
2022-02-11 09:18:55 +00:00
|
|
|
LastView: '' as Ref<Class<LastView>>,
|
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>>,
|
|
|
|
DocUpdates: '' as Ref<Class<DocUpdates>>
|
2022-02-22 09:09:13 +00:00
|
|
|
},
|
|
|
|
ids: {
|
|
|
|
MentionNotification: '' as Ref<NotificationType>,
|
2023-03-01 09:23:42 +00:00
|
|
|
DMNotification: '' as Ref<NotificationType>,
|
2022-02-22 09:09:13 +00:00
|
|
|
PlatformNotification: '' as Ref<NotificationProvider>,
|
2022-06-30 11:24:19 +00:00
|
|
|
BrowserNotification: '' as Ref<NotificationProvider>,
|
2022-02-22 09:09:13 +00:00
|
|
|
EmailNotification: '' as Ref<NotificationProvider>,
|
|
|
|
NotificationSettings: '' as Ref<Doc>
|
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,
|
|
|
|
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
|