UBER-564: Add sound notification and settings (#3655)

This commit is contained in:
Maksim Karmatskikh 2023-09-05 11:31:09 +06:00 committed by GitHub
parent 3d2e2a762a
commit 436a0442c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 4 deletions

View File

@ -41,6 +41,7 @@ import {
EmailNotification, EmailNotification,
Notification, Notification,
NotificationGroup, NotificationGroup,
NotificationPreferencesGroup,
notificationId, notificationId,
NotificationObjectPresenter, NotificationObjectPresenter,
NotificationPreview, NotificationPreview,
@ -118,6 +119,13 @@ export class TNotificationGroup extends TDoc implements NotificationGroup {
objectClass?: Ref<Class<Doc>> objectClass?: Ref<Class<Doc>>
} }
@Model(notification.class.NotificationPreferencesGroup, core.class.Doc, DOMAIN_MODEL)
export class TNotificationPreferencesGroup extends TDoc implements NotificationPreferencesGroup {
label!: IntlString
icon!: Asset
presenter!: AnyComponent
}
@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
@ -178,6 +186,7 @@ export function createModel (builder: Builder): void {
TNotificationProvider, TNotificationProvider,
TNotificationSetting, TNotificationSetting,
TNotificationGroup, TNotificationGroup,
TNotificationPreferencesGroup,
TClassCollaborators, TClassCollaborators,
TCollaborators, TCollaborators,
TDocUpdates, TDocUpdates,

View File

@ -14,7 +14,13 @@
--> -->
<script lang="ts"> <script lang="ts">
import { Ref } from '@hcengineering/core' import { Ref } from '@hcengineering/core'
import type { NotificationGroup, NotificationSetting, NotificationType } from '@hcengineering/notification' import { getResource } from '@hcengineering/platform'
import type {
NotificationGroup,
NotificationPreferencesGroup,
NotificationSetting,
NotificationType
} from '@hcengineering/notification'
import { createQuery, getClient } from '@hcengineering/presentation' import { createQuery, getClient } from '@hcengineering/presentation'
import { Label } from '@hcengineering/ui' import { Label } from '@hcengineering/ui'
import notification from '../plugin' import notification from '../plugin'
@ -23,9 +29,10 @@
const client = getClient() const client = getClient()
let groups: NotificationGroup[] = [] let groups: NotificationGroup[] = []
let preferencesGroups: NotificationPreferencesGroup[] = []
client.findAll(notification.class.NotificationGroup, {}).then((res) => { client.findAll(notification.class.NotificationGroup, {}).then((res) => {
groups = res groups = res
group = res[0]._id
}) })
let settings: Map<Ref<NotificationType>, NotificationSetting[]> = new Map() let settings: Map<Ref<NotificationType>, NotificationSetting[]> = new Map()
@ -33,7 +40,6 @@
const query = createQuery() const query = createQuery()
query.query(notification.class.NotificationSetting, {}, (res) => { query.query(notification.class.NotificationSetting, {}, (res) => {
console.log('settings updated')
settings = new Map() settings = new Map()
for (const value of res) { for (const value of res) {
const arr = settings.get(value.type) ?? [] const arr = settings.get(value.type) ?? []
@ -44,6 +50,19 @@
}) })
let group: Ref<NotificationGroup> | undefined = undefined let group: Ref<NotificationGroup> | undefined = undefined
let currentPreferenceGroup: NotificationPreferencesGroup | undefined = undefined
client.findAll(notification.class.NotificationPreferencesGroup, {}).then((res) => {
preferencesGroups = res
})
$: if (!group && !currentPreferenceGroup) {
if (preferencesGroups.length > 0) {
currentPreferenceGroup = preferencesGroups[0]
} else if (groups.length > 0) {
group = groups[0]._id
}
}
</script> </script>
<div class="flex h-full"> <div class="flex h-full">
@ -53,6 +72,20 @@
<Label label={notification.string.Notifications} /> <Label label={notification.string.Notifications} />
</span> </span>
</div> </div>
{#each preferencesGroups as preferenceGroup}
<GroupElement
icon={preferenceGroup.icon}
label={preferenceGroup.label}
selected={preferenceGroup === currentPreferenceGroup}
on:click={() => {
currentPreferenceGroup = preferenceGroup
group = undefined
}}
/>
{/each}
{#if preferencesGroups.length > 0 && groups.length > 0}
<div class="antiNav-divider short line" />
{/if}
{#each groups as gr} {#each groups as gr}
<GroupElement <GroupElement
icon={gr.icon} icon={gr.icon}
@ -60,6 +93,7 @@
selected={gr._id === group} selected={gr._id === group}
on:click={() => { on:click={() => {
group = gr._id group = gr._id
currentPreferenceGroup = undefined
}} }}
/> />
{/each} {/each}
@ -69,5 +103,10 @@
{#if group} {#if group}
<NotificationGroupSetting {group} {settings} /> <NotificationGroupSetting {group} {settings} />
{/if} {/if}
{#if currentPreferenceGroup}
{#await getResource(currentPreferenceGroup.presenter) then presenter}
<svelte:component this={presenter} />
{/await}
{/if}
</div> </div>
</div> </div>

View File

@ -77,6 +77,15 @@ export interface NotificationGroup extends Doc {
objectClass?: Ref<Class<Doc>> objectClass?: Ref<Class<Doc>>
} }
/**
* @public
*/
export interface NotificationPreferencesGroup extends Doc {
label: IntlString
icon: Asset
presenter: AnyComponent
}
/** /**
* @public * @public
*/ */
@ -218,7 +227,8 @@ const notification = plugin(notificationId, {
NotificationProvider: '' as Ref<Class<NotificationProvider>>, NotificationProvider: '' as Ref<Class<NotificationProvider>>,
NotificationSetting: '' as Ref<Class<NotificationSetting>>, NotificationSetting: '' as Ref<Class<NotificationSetting>>,
DocUpdates: '' as Ref<Class<DocUpdates>>, DocUpdates: '' as Ref<Class<DocUpdates>>,
NotificationGroup: '' as Ref<Class<NotificationGroup>> NotificationGroup: '' as Ref<Class<NotificationGroup>>,
NotificationPreferencesGroup: '' as Ref<Class<NotificationPreferencesGroup>>
}, },
ids: { ids: {
NotificationSettings: '' as Ref<Doc>, NotificationSettings: '' as Ref<Doc>,