Fix inbox migration and common notification component (#4348)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina 2024-01-12 20:47:59 +04:00 committed by GitHub
parent 573bfd062d
commit 5d2f274089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 114 additions and 39 deletions

View File

@ -238,6 +238,7 @@ export class TActivityInboxNotification extends TInboxNotification implements Ac
@Model(notification.class.CommonInboxNotification, notification.class.InboxNotification)
export class TCommonInboxNotification extends TInboxNotification implements CommonInboxNotification {
header?: IntlString
@Prop(TypeIntlString(), notification.string.Message)
message!: IntlString

View File

@ -32,10 +32,10 @@ import {
tryMigrate
} from '@hcengineering/model'
import notification, {
type ActivityInboxNotification,
type DocNotifyContext,
type DocUpdates,
type DocUpdateTx,
type InboxNotification,
notificationId
} from '@hcengineering/notification'
import activity, { type ActivityMessage, type DocUpdateMessage } from '@hcengineering/activity'
@ -44,7 +44,7 @@ import { DOMAIN_NOTIFICATION } from './index'
interface InboxData {
context: DocNotifyContext
notifications: InboxNotification[]
notifications: ActivityInboxNotification[]
}
const DOMAIN_ACTIVITY = 'activity' as Domain
@ -105,7 +105,7 @@ async function getInboxNotifications (
client: MigrationClient,
tx: DocUpdateTx,
context: DocNotifyContext
): Promise<InboxNotification[]> {
): Promise<ActivityInboxNotification[]> {
const messages = await getActivityMessages(client, tx, context)
if (messages.length === 0) {
@ -114,7 +114,7 @@ async function getInboxNotifications (
return messages.map((message) => ({
_id: generateId(),
_class: notification.class.InboxNotification,
_class: notification.class.ActivityInboxNotification,
space: context.space,
user: context.user,
isViewed: !tx.isNew,

View File

@ -0,0 +1,42 @@
<!--
// Copyright © 2023 Hardcore Engineering Inc.
//
// 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.
-->
<script lang="ts">
import { Doc } from '@hcengineering/core'
import { type AnyComponent, Label } from '@hcengineering/ui'
import { DocNavLink } from '@hcengineering/view-resources'
import { IntlString } from '@hcengineering/platform'
export let object: Doc
export let title: string = ''
export let panelComponent: AnyComponent | undefined
export let preposition: IntlString | undefined = undefined
</script>
{#if preposition}
<span class="text-sm lower"><Label label={preposition} /></span>
{/if}
<span class="text-sm">
<DocNavLink {object} component={panelComponent} shrink={0}>
<span class="overflow-label select-text">{title}</span>
</DocNavLink>
</span>
<style lang="scss">
span {
margin-left: 0.25rem;
font-weight: 400;
line-height: 1.25rem;
}
</style>

View File

@ -16,12 +16,13 @@
import { ActivityMessage } from '@hcengineering/activity'
import { Person } from '@hcengineering/contact'
import { Doc } from '@hcengineering/core'
import notification from '../../plugin'
import { Label } from '@hcengineering/ui'
import { DocNavLink } from '@hcengineering/view-resources'
import { LinkData, getLinkData } from '../../activityMessagesUtils'
import { IntlString } from '@hcengineering/platform'
import { LinkData, getLinkData } from '../../activityMessagesUtils'
import ActivityDocLink from '../ActivityDocLink.svelte'
import notification from '../../plugin'
export let message: ActivityMessage
export let person: Person | undefined
export let object: Doc | undefined
@ -43,15 +44,16 @@
</span>
{#if linkData}
<span class="text-sm lower"><Label label={linkData.preposition} /></span>
<span class="text-sm">
<DocNavLink {object} component={linkData.panelComponent} shrink={0}>
<span class="overflow-label select-text">{linkData.title}</span>
</DocNavLink>
</span>
{#if isEdited}
<span class="text-sm lower"><Label label={notification.string.Edited} /></span>
{/if}
<ActivityDocLink
preposition={linkData.preposition}
title={linkData.title}
object={linkData.object}
panelComponent={linkData.panelComponent}
/>
{/if}
{#if isEdited}
<span class="text-sm lower"><Label label={notification.string.Edited} /></span>
{/if}
<style lang="scss">

View File

@ -13,7 +13,6 @@
// limitations under the License.
-->
<script lang="ts">
import { DocNavLink } from '@hcengineering/view-resources'
import { Doc } from '@hcengineering/core'
import { Label } from '@hcengineering/ui'
import { IntlString } from '@hcengineering/platform'
@ -22,6 +21,7 @@
import { Person } from '@hcengineering/contact'
import { LinkData, getLinkData } from '../../activityMessagesUtils'
import ActivityDocLink from '../ActivityDocLink.svelte'
export let message: DisplayDocUpdateMessage
export let viewlet: DocUpdateMessageViewlet | undefined
@ -90,14 +90,12 @@
{/if}
{#if linkData}
{#if !isOwn || message.action === 'update'}
<span class="text-sm lower"><Label label={linkData.preposition} /></span>
{/if}
<span class="text-sm">
<DocNavLink object={linkData.object} component={linkData.panelComponent} shrink={0}>
<span class="overflow-label select-text">{linkData.title}</span>
</DocNavLink>
</span>
<ActivityDocLink
preposition={!isOwn || message.action === 'update' ? linkData.preposition : undefined}
object={linkData.object}
panelComponent={linkData.panelComponent}
title={linkData.title}
/>
{/if}
<style lang="scss">

View File

@ -33,6 +33,7 @@ export { default as ActivityMessagePresenter } from './components/activity-messa
export { default as ActivityExtension } from './components/ActivityExtension.svelte'
export { default as ActivityScrolledView } from './components/ActivityScrolledView.svelte'
export { default as ActivityMessageHeader } from './components/activity-message/ActivityMessageHeader.svelte'
export { default as ActivityDocLink } from './components/ActivityDocLink.svelte'
export default async (): Promise<Resources> => ({
component: {

View File

@ -13,12 +13,11 @@
// limitations under the License.
-->
<script lang="ts">
import { DocNavLink } from '@hcengineering/view-resources'
import { Doc } from '@hcengineering/core'
import { Label } from '@hcengineering/ui'
import { Person } from '@hcengineering/contact'
import { ChatMessage, ChatMessageViewlet } from '@hcengineering/chunter'
import { getLinkData, LinkData } from '@hcengineering/activity-resources'
import { getLinkData, LinkData, ActivityDocLink } from '@hcengineering/activity-resources'
import notification from '@hcengineering/notification'
import chunter from '../../plugin'
@ -41,12 +40,12 @@
<span class="text-sm lower"> <Label label={viewlet?.label ?? chunter.string.SentMessage} /></span>
{#if linkData}
<span class="text-sm lower"><Label label={linkData.preposition} /></span>
<span class="text-sm">
<DocNavLink object={linkData.object} component={linkData.panelComponent} shrink={0}>
<span class="overflow-label select-text">{linkData.title}</span>
</DocNavLink>
</span>
<ActivityDocLink
preposition={linkData.preposition}
object={linkData.object}
panelComponent={linkData.panelComponent}
title={linkData.title}
/>
{/if}
{/if}
{#if message.editedOn}

View File

@ -22,16 +22,29 @@
personByIdStore,
EmployeePresenter
} from '@hcengineering/contact-resources'
import core, { getDisplayTime, Ref } from '@hcengineering/core'
import core, { Doc, getDisplayTime, Ref } from '@hcengineering/core'
import { translate } from '@hcengineering/platform'
import { MessageViewer } from '@hcengineering/presentation'
import { createQuery, getClient, MessageViewer } from '@hcengineering/presentation'
import notification, { CommonInboxNotification } from '@hcengineering/notification'
import { ActionIcon, IconMoreH, Label, showPopup } from '@hcengineering/ui'
import { Menu } from '@hcengineering/view-resources'
import { getDocLinkTitle, Menu } from '@hcengineering/view-resources'
import { ActivityDocLink } from '@hcengineering/activity-resources'
import activity from '@hcengineering/activity'
import view from '@hcengineering/view'
import { InboxNotificationsClientImpl } from '../../inboxNotificationsClient'
export let value: CommonInboxNotification
const objectQuery = createQuery()
const client = getClient()
const hierarchy = client.getHierarchy()
const inboxClient = InboxNotificationsClientImpl.getClient()
const docNotifyContextsStore = inboxClient.docNotifyContexts
let isActionMenuOpened = false
let content = ''
let object: Doc | undefined = undefined
$: personAccount = $personAccountByIdStore.get((value.createdBy ?? value.modifiedBy) as Ref<PersonAccount>)
$: person =
@ -39,7 +52,12 @@
? $employeeByIdStore.get(personAccount.person as Ref<Employee>) ?? $personByIdStore.get(personAccount.person)
: undefined
let content = ''
$: context = $docNotifyContextsStore.find(({ _id }) => _id === value.docNotifyContext)
$: context &&
objectQuery.query(context.attachedToClass, { _id: context.attachedTo }, (result) => {
object = result[0]
})
$: void translate(value.message, value.props)
.then((message) => {
@ -91,6 +109,19 @@
<Label label={core.string.System} />
</div>
{/if}
{#if value.header}
<span class="text-sm lower"><Label label={value.header} /></span>
{/if}
{#if object}
{#await getDocLinkTitle(client, object._id, object._class, object) then linkTitle}
<ActivityDocLink
{object}
title={linkTitle}
panelComponent={hierarchy.classHierarchyMixin(object._class, view.mixin.ObjectPanel)?.component}
/>
{/await}
{/if}
<span class="text-sm">{getDisplayTime(value.createdOn ?? 0)}</span>
</div>

View File

@ -230,7 +230,7 @@ export interface ActivityInboxNotification extends InboxNotification {
}
export interface CommonInboxNotification extends InboxNotification {
title?: IntlString
header?: IntlString
message: IntlString
props?: Record<string, any>
icon?: Asset

View File

@ -385,7 +385,7 @@ export async function getDocCollaborators (
return Array.from(collaborators.values())
}
async function pushInboxNotifications (
export async function pushInboxNotifications (
control: TriggerControl,
res: Tx[],
targetUser: Ref<Account>,
@ -1014,6 +1014,7 @@ async function OnActivityNotificationViewed (
}
export * from './types'
export * from './utils'
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default async () => ({