mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-03 17:05:16 +03:00
UBERF-6509: fix reading mention notifications (#5323)
This commit is contained in:
parent
e6fc2fd12b
commit
6832c9c848
@ -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)
|
||||
}
|
||||
|
@ -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) => {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user