From 7653c1cf838962ff83ac932dead5cc0f87129eeb Mon Sep 17 00:00:00 2001 From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> Date: Thu, 30 Jun 2022 17:24:19 +0600 Subject: [PATCH] Browser notification (#2178) Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> --- changelog.md | 1 + models/notification/src/index.ts | 14 ++ models/notification/src/migration.ts | 51 ++++- models/notification/src/plugin.ts | 1 + plugins/notification-assets/lang/en.json | 3 +- plugins/notification-assets/lang/ru.json | 3 +- .../components/BrowserNotificatator.svelte | 119 ++++++++++ .../components/NotificationSettings.svelte | 11 +- plugins/notification-resources/src/index.ts | 2 + plugins/notification/src/index.ts | 3 + .../src/components/Workbench.svelte | 6 +- .../notification-resources/src/index.ts | 208 ++++++++++-------- 12 files changed, 322 insertions(+), 100 deletions(-) create mode 100644 plugins/notification-resources/src/components/BrowserNotificatator.svelte diff --git a/changelog.md b/changelog.md index 068f338168..665748398f 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,7 @@ Core: - Allow to leave workspace - Allow to kick employee +- Browser notifications - Allow to create employee HR: diff --git a/models/notification/src/index.ts b/models/notification/src/index.ts index 76ce6e4b40..29f6dd6199 100644 --- a/models/notification/src/index.ts +++ b/models/notification/src/index.ts @@ -51,6 +51,10 @@ export class TNotification extends TAttachedDoc implements Notification { @Prop(TypeString(), 'Status' as IntlString) status!: NotificationStatus + + text!: string + + type!: Ref } @Model(notification.class.EmailNotification, core.class.Doc, DOMAIN_NOTIFICATION) @@ -137,6 +141,16 @@ export function createModel (builder: Builder): void { notification.ids.PlatformNotification ) + builder.createDoc( + notification.class.NotificationProvider, + core.space.Model, + { + label: notification.string.BrowserNotification, + default: false + }, + notification.ids.BrowserNotification + ) + builder.createDoc( notification.class.NotificationProvider, core.space.Model, diff --git a/models/notification/src/migration.ts b/models/notification/src/migration.ts index 643c7a5d6a..bf6fbbee68 100644 --- a/models/notification/src/migration.ts +++ b/models/notification/src/migration.ts @@ -13,9 +13,56 @@ // limitations under the License. // +import core, { DOMAIN_TX, Ref, TxCreateDoc, TxOperations } from '@anticrm/core' import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' +import notification, { Notification, NotificationType } from '@anticrm/notification' +import { DOMAIN_NOTIFICATION } from '.' + +async function fillNotificationText (client: MigrationClient): Promise { + await client.update( + DOMAIN_NOTIFICATION, + { _class: notification.class.Notification, text: { $exists: false } }, + { + text: '' + } + ) + await client.update( + DOMAIN_TX, + { + _class: core.class.TxCreateDoc, + objectClass: notification.class.Notification, + 'attributes.text': { $exists: false } + }, + { + 'attributes.text': '' + } + ) +} + +async function fillNotificationType (client: MigrationUpgradeClient): Promise { + const notifications = await client.findAll(notification.class.Notification, { type: { $exists: false } }) + const txOp = new TxOperations(client, core.account.System) + const promises = notifications.map(async (doc) => { + const tx = await client.findOne(core.class.TxCUD, { _id: doc.tx }) + if (tx === undefined) return + const type = + tx._class === core.class.TxMixin + ? ('calendar:ids:ReminderNotification' as Ref) + : notification.ids.MentionNotification + const objectTx = txOp.update(doc, { type }) + const ctx = await client.findOne>(core.class.TxCreateDoc, { objectId: doc._id }) + if (ctx === undefined) return await objectTx + const updateTx = txOp.update(ctx, { 'attributes.type': type } as any) + return await Promise.all([objectTx, updateTx]) + }) + await Promise.all(promises) +} export const notificationOperation: MigrateOperation = { - async migrate (client: MigrationClient): Promise {}, - async upgrade (client: MigrationUpgradeClient): Promise {} + async migrate (client: MigrationClient): Promise { + await fillNotificationText(client) + }, + async upgrade (client: MigrationUpgradeClient): Promise { + await fillNotificationType(client) + } } diff --git a/models/notification/src/plugin.ts b/models/notification/src/plugin.ts index ba81088122..4d90fb72eb 100644 --- a/models/notification/src/plugin.ts +++ b/models/notification/src/plugin.ts @@ -23,6 +23,7 @@ export default mergeIds(notificationId, notification, { LastView: '' as IntlString, MentionNotification: '' as IntlString, PlatformNotification: '' as IntlString, + BrowserNotification: '' as IntlString, EmailNotification: '' as IntlString }, component: { diff --git a/plugins/notification-assets/lang/en.json b/plugins/notification-assets/lang/en.json index b3dae1168a..74064664d1 100644 --- a/plugins/notification-assets/lang/en.json +++ b/plugins/notification-assets/lang/en.json @@ -8,6 +8,7 @@ "EmailNotification": "by email", "PlatformNotification": "in platform", "Track": "Track", - "DontTrack": "Don't track" + "DontTrack": "Don't track", + "BrowserNotification": "in browser" } } \ No newline at end of file diff --git a/plugins/notification-assets/lang/ru.json b/plugins/notification-assets/lang/ru.json index c773ab0590..37d64f395f 100644 --- a/plugins/notification-assets/lang/ru.json +++ b/plugins/notification-assets/lang/ru.json @@ -8,6 +8,7 @@ "EmailNotification": "по email", "PlatformNotification": "в системе", "Track": "Отслеживать", - "DontTrack": "Не отслеживать" + "DontTrack": "Не отслеживать", + "BrowserNotification": "в браузере" } } \ No newline at end of file diff --git a/plugins/notification-resources/src/components/BrowserNotificatator.svelte b/plugins/notification-resources/src/components/BrowserNotificatator.svelte new file mode 100644 index 0000000000..f9abd69007 --- /dev/null +++ b/plugins/notification-resources/src/components/BrowserNotificatator.svelte @@ -0,0 +1,119 @@ + + diff --git a/plugins/notification-resources/src/components/NotificationSettings.svelte b/plugins/notification-resources/src/components/NotificationSettings.svelte index bbaf3c693e..b28f1d73c6 100644 --- a/plugins/notification-resources/src/components/NotificationSettings.svelte +++ b/plugins/notification-resources/src/components/NotificationSettings.svelte @@ -26,6 +26,8 @@ const client = getClient() const space = accountId as string as Ref + let disabled = true + let types: NotificationType[] = [] let providers: NotificationProvider[] = [] let settings: Map, Map, NotificationSetting>> = new Map< @@ -67,6 +69,7 @@ } else { current.enabled = value } + disabled = false } function getSetting ( @@ -92,6 +95,7 @@ } async function save (): Promise { + disabled = true const promises: Promise[] = [] for (const type of settings.values()) { for (const setting of type.values()) { @@ -107,7 +111,11 @@ } } } - await Promise.all(promises) + try { + await Promise.all(promises) + } catch (e) { + console.log(e) + } } $: column = providers.length + 1 @@ -152,6 +160,7 @@