UBERF-6509: fix reading mention notifications (#5323)

This commit is contained in:
Kristina 2024-04-11 16:03:47 +04:00 committed by GitHub
parent e6fc2fd12b
commit 6832c9c848
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 67 additions and 13 deletions

View File

@ -594,3 +594,11 @@ export function isReactionMessage (message?: ActivityMessage): boolean {
return message.objectClass === activity.class.Reaction
}
export function isActivityMessageClass (_class?: Ref<Class<Doc>>): boolean {
if (_class === undefined) {
return false
}
return getClient().getHierarchy().isDerived(_class, activity.class.ActivityMessage)
}

View File

@ -18,7 +18,12 @@
import { getClient } from '@hcengineering/presentation'
import { Action, IconEdit } from '@hcengineering/ui'
import { getActions } from '@hcengineering/view-resources'
import { getNotificationsCount, InboxNotificationsClientImpl } from '@hcengineering/notification-resources'
import {
getNotificationsCount,
InboxNotificationsClientImpl,
isActivityNotification,
isMentionNotification
} from '@hcengineering/notification-resources'
import { createEventDispatcher } from 'svelte'
import NavItem from './NavItem.svelte'
@ -38,9 +43,7 @@
let actions: Action[] = []
notificationClient.inboxNotificationsByContext.subscribe((res) => {
notifications = (res.get(context._id) ?? []).filter(
({ _class }) => _class === notification.class.ActivityInboxNotification
)
notifications = (res.get(context._id) ?? []).filter((n) => isMentionNotification(n) || isActivityNotification(n))
})
$: void getNotificationsCount(context, notifications).then((res) => {

View File

@ -52,7 +52,11 @@ import activity, {
type DisplayDocUpdateMessage,
type DocUpdateMessage
} from '@hcengineering/activity'
import { deleteContextNotifications, InboxNotificationsClientImpl } from '@hcengineering/notification-resources'
import {
deleteContextNotifications,
InboxNotificationsClientImpl,
isMentionNotification
} from '@hcengineering/notification-resources'
import notification, { type DocNotifyContext, notificationId } from '@hcengineering/notification'
import { get, type Unsubscriber } from 'svelte/store'
@ -479,6 +483,9 @@ export async function readChannelMessages (
return [message._id, ...(combined ?? [])]
})
.flat()
const relatedMentions = get(inboxClient.otherInboxNotifications).filter(
(n) => !n.isViewed && isMentionNotification(n) && allIds.includes(n.mentionedIn as Ref<ActivityMessage>)
)
const ops = getClient().apply(generateId())
@ -486,6 +493,11 @@ export async function readChannelMessages (
void ops.commit()
})
void inboxClient.readNotifications(
client,
relatedMentions.map((n) => n._id)
)
if (context === undefined) {
return
}

View File

@ -13,7 +13,11 @@
// limitations under the License.
-->
<script lang="ts">
import notification, { DocNotifyContext, InboxNotification } from '@hcengineering/notification'
import notification, {
ActivityInboxNotification,
DocNotifyContext,
InboxNotification
} from '@hcengineering/notification'
import { ActionContext, getClient } from '@hcengineering/presentation'
import view from '@hcengineering/view'
import {
@ -33,13 +37,21 @@
import chunter, { ThreadMessage } from '@hcengineering/chunter'
import { IdMap, Ref } from '@hcengineering/core'
import activity, { ActivityMessage } from '@hcengineering/activity'
import { isReactionMessage } from '@hcengineering/activity-resources'
import { isActivityMessageClass, isReactionMessage } from '@hcengineering/activity-resources'
import { get } from 'svelte/store'
import { translate } from '@hcengineering/platform'
import { InboxNotificationsClientImpl } from '../../inboxNotificationsClient'
import Filter from '../Filter.svelte'
import { archiveAll, getDisplayInboxData, openInboxDoc, readAll, resolveLocation, unreadAll } from '../../utils'
import {
archiveAll,
getDisplayInboxData,
isMentionNotification,
openInboxDoc,
readAll,
resolveLocation,
unreadAll
} from '../../utils'
import { InboxData, InboxNotificationsFilter } from '../../types'
import InboxGroupedListView from './InboxGroupedListView.svelte'
@ -161,7 +173,19 @@
return
}
if (hierarchy.isDerived(selectedContext.attachedToClass, activity.class.ActivityMessage)) {
const selectedNotification: InboxNotification | undefined = event?.detail?.notification
if (isMentionNotification(selectedNotification) && isActivityMessageClass(selectedNotification.mentionedInClass)) {
const selectedMsg = selectedNotification.mentionedIn as Ref<ActivityMessage>
openInboxDoc(
selectedContext._id,
isActivityMessageClass(selectedContext.attachedToClass)
? (selectedContext.attachedTo as Ref<ActivityMessage>)
: undefined,
selectedMsg
)
} else if (hierarchy.isDerived(selectedContext.attachedToClass, activity.class.ActivityMessage)) {
const message = event?.detail?.notification?.$lookup?.attachedTo
if (selectedContext.attachedToClass === chunter.class.ThreadMessage) {
@ -172,7 +196,7 @@
} else if (isReactionMessage(message)) {
openInboxDoc(selectedContext._id, undefined, selectedContext.attachedTo as Ref<ActivityMessage>)
} else {
const selectedMsg = event?.detail?.notification?.attachedTo
const selectedMsg = (selectedNotification as ActivityInboxNotification)?.attachedTo
openInboxDoc(
selectedContext._id,
@ -181,7 +205,7 @@
)
}
} else {
openInboxDoc(selectedContext._id, undefined, event?.detail?.notification?.attachedTo)
openInboxDoc(selectedContext._id, undefined, (selectedNotification as ActivityInboxNotification)?.attachedTo)
}
}

View File

@ -35,7 +35,8 @@ import notification, {
type Collaborators,
type DisplayInboxNotification,
type DocNotifyContext,
type InboxNotification
type InboxNotification,
type MentionInboxNotification
} from '@hcengineering/notification'
import { MessageBox, getClient } from '@hcengineering/presentation'
import { getLocation, navigate, showPopup, type Location, type ResolvedLocation } from '@hcengineering/ui'
@ -274,10 +275,16 @@ export async function unreadAll (): Promise<void> {
await client.unreadAllNotifications()
}
export function isActivityNotification (doc: InboxNotification): doc is ActivityInboxNotification {
export function isActivityNotification (doc?: InboxNotification): doc is ActivityInboxNotification {
if (doc === undefined) return false
return doc._class === notification.class.ActivityInboxNotification
}
export function isMentionNotification (doc?: InboxNotification): doc is MentionInboxNotification {
if (doc === undefined) return false
return doc._class === notification.class.MentionInboxNotification
}
export async function getDisplayInboxNotifications (
notifications: Array<WithLookup<InboxNotification>>,
filter: InboxNotificationsFilter = 'all',