Default notifications settings (#1129)

Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov 2022-03-11 15:06:33 +06:00 committed by GitHub
parent b9291eb647
commit e63274efb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 6 deletions

View File

@ -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, {

View File

@ -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>

View File

@ -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
} }
/** /**

View File

@ -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