mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-29 19:55:20 +00:00
Default notifications settings (#1129)
Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
parent
b9291eb647
commit
e63274efb5
@ -71,6 +71,7 @@ export class TNotificationType extends TDoc implements NotificationType {
|
|||||||
@Model(notification.class.NotificationProvider, core.class.Doc, DOMAIN_MODEL)
|
@Model(notification.class.NotificationProvider, core.class.Doc, DOMAIN_MODEL)
|
||||||
export class TNotificationProvider extends TDoc implements NotificationProvider {
|
export class TNotificationProvider extends TDoc implements NotificationProvider {
|
||||||
label!: IntlString
|
label!: IntlString
|
||||||
|
default!: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@Model(notification.class.NotificationSetting, core.class.Doc, DOMAIN_NOTIFICATION)
|
@Model(notification.class.NotificationSetting, core.class.Doc, DOMAIN_NOTIFICATION)
|
||||||
@ -88,11 +89,13 @@ export function createModel (builder: Builder): void {
|
|||||||
}, notification.ids.MentionNotification)
|
}, notification.ids.MentionNotification)
|
||||||
|
|
||||||
builder.createDoc(notification.class.NotificationProvider, core.space.Model, {
|
builder.createDoc(notification.class.NotificationProvider, core.space.Model, {
|
||||||
label: notification.string.PlatformNotification
|
label: notification.string.PlatformNotification,
|
||||||
|
default: true
|
||||||
}, notification.ids.PlatformNotification)
|
}, notification.ids.PlatformNotification)
|
||||||
|
|
||||||
builder.createDoc(notification.class.NotificationProvider, core.space.Model, {
|
builder.createDoc(notification.class.NotificationProvider, core.space.Model, {
|
||||||
label: notification.string.EmailNotification
|
label: notification.string.EmailNotification,
|
||||||
|
default: false
|
||||||
}, notification.ids.EmailNotification)
|
}, notification.ids.EmailNotification)
|
||||||
|
|
||||||
builder.createDoc(setting.class.SettingsCategory, core.space.Model, {
|
builder.createDoc(setting.class.SettingsCategory, core.space.Model, {
|
||||||
|
@ -95,6 +95,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$: column = providers.length + 1
|
$: column = providers.length + 1
|
||||||
|
|
||||||
|
function getStatus (map: Map<Ref<NotificationType>, Map<Ref<NotificationProvider>, NotificationSetting>>, type: Ref<NotificationType>, provider: Ref<NotificationProvider>): boolean {
|
||||||
|
const setting = getSetting(map, type, provider)
|
||||||
|
if (setting !== undefined) return setting.enabled
|
||||||
|
const prov = providers.find((p) => p._id === provider)
|
||||||
|
if (prov === undefined) return false
|
||||||
|
return prov.default
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="antiComponent">
|
<div class="antiComponent">
|
||||||
@ -109,7 +117,7 @@
|
|||||||
{#each types as type (type._id)}
|
{#each types as type (type._id)}
|
||||||
<Label label={type.label} />
|
<Label label={type.label} />
|
||||||
{#each providers as provider (provider._id)}
|
{#each providers as provider (provider._id)}
|
||||||
<ToggleWithLabel label={provider.label} on={getSetting(settings, type._id, provider._id)?.enabled} on:change={(e) => change(type._id, provider._id, e.detail)} />
|
<ToggleWithLabel label={provider.label} on={getStatus(settings, type._id, provider._id)} on:change={(e) => change(type._id, provider._id, e.detail)} />
|
||||||
{/each}
|
{/each}
|
||||||
{/each}
|
{/each}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -67,6 +67,7 @@ export interface NotificationType extends Doc {
|
|||||||
*/
|
*/
|
||||||
export interface NotificationProvider extends Doc {
|
export interface NotificationProvider extends Doc {
|
||||||
label: IntlString
|
label: IntlString
|
||||||
|
default: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,14 +60,20 @@ async function getPlatformNotificationTx (ptx: TxCollectionCUD<Doc, Backlink>, c
|
|||||||
const attached = (await control.modelDb.findAll(contact.class.EmployeeAccount, {
|
const attached = (await control.modelDb.findAll(contact.class.EmployeeAccount, {
|
||||||
employee: ptx.objectId as Ref<Employee>
|
employee: ptx.objectId as Ref<Employee>
|
||||||
}, { limit: 1 }))[0]
|
}, { limit: 1 }))[0]
|
||||||
if (attached === undefined) return undefined
|
if (attached === undefined) return
|
||||||
|
|
||||||
const setting = (await control.findAll(notification.class.NotificationSetting, {
|
const setting = (await control.findAll(notification.class.NotificationSetting, {
|
||||||
provider: notification.ids.PlatformNotification,
|
provider: notification.ids.PlatformNotification,
|
||||||
type: notification.ids.MentionNotification,
|
type: notification.ids.MentionNotification,
|
||||||
space: attached._id as unknown as Ref<Space>
|
space: attached._id as unknown as Ref<Space>
|
||||||
}, { limit: 1 }))[0]
|
}, { limit: 1 }))[0]
|
||||||
if (setting === undefined || !setting.enabled) return
|
if (setting === undefined) {
|
||||||
|
const provider = (await control.modelDb.findAll(notification.class.NotificationProvider, {
|
||||||
|
_id: notification.ids.PlatformNotification
|
||||||
|
}))[0]
|
||||||
|
if (provider === undefined) return
|
||||||
|
if (!provider.default) return
|
||||||
|
}
|
||||||
|
|
||||||
const createTx: TxCreateDoc<Notification> = {
|
const createTx: TxCreateDoc<Notification> = {
|
||||||
objectClass: notification.class.Notification,
|
objectClass: notification.class.Notification,
|
||||||
@ -113,7 +119,13 @@ async function getEmailTx (ptx: TxCollectionCUD<Doc, Backlink>, control: Trigger
|
|||||||
type: notification.ids.MentionNotification,
|
type: notification.ids.MentionNotification,
|
||||||
space: attached._id as unknown as Ref<Space>
|
space: attached._id as unknown as Ref<Space>
|
||||||
}, { limit: 1 }))[0]
|
}, { limit: 1 }))[0]
|
||||||
if (setting === undefined || !setting.enabled) return
|
if (setting === undefined) {
|
||||||
|
const provider = (await control.modelDb.findAll(notification.class.NotificationProvider, {
|
||||||
|
_id: notification.ids.PlatformNotification
|
||||||
|
}))[0]
|
||||||
|
if (provider === undefined) return
|
||||||
|
if (!provider.default) return
|
||||||
|
}
|
||||||
|
|
||||||
const receiver = attached.email
|
const receiver = attached.email
|
||||||
let doc: Doc | undefined
|
let doc: Doc | undefined
|
||||||
|
Loading…
Reference in New Issue
Block a user