mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-25 09:13:07 +03:00
UBERF-5476: Fix archive in inbox (#4618)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
beab7928e0
commit
715193957b
@ -13,7 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Class, Doc, getCurrentAccount, isOtherDay, Ref, Timestamp } from '@hcengineering/core'
|
import { Class, Doc, generateId, getCurrentAccount, isOtherDay, Ref, Timestamp } from '@hcengineering/core'
|
||||||
import { getClient } from '@hcengineering/presentation'
|
import { getClient } from '@hcengineering/presentation'
|
||||||
import activity, {
|
import activity, {
|
||||||
ActivityExtension,
|
ActivityExtension,
|
||||||
@ -239,8 +239,10 @@
|
|||||||
return [message._id, ...(combined ?? [])]
|
return [message._id, ...(combined ?? [])]
|
||||||
})
|
})
|
||||||
.flat()
|
.flat()
|
||||||
|
const ops = getClient().apply(generateId())
|
||||||
inboxClient.readMessages(allIds)
|
inboxClient.readMessages(ops, allIds).then(() => {
|
||||||
|
void ops.commit()
|
||||||
|
})
|
||||||
|
|
||||||
if (notifyContext === undefined) {
|
if (notifyContext === undefined) {
|
||||||
return
|
return
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
{ attachedTo: channelId },
|
{ attachedTo: channelId },
|
||||||
(res) => {
|
(res) => {
|
||||||
plainMessages = res
|
plainMessages = res
|
||||||
inboxClient.readDoc(channelId)
|
inboxClient.readDoc(getClient(), channelId)
|
||||||
},
|
},
|
||||||
{ sort: { sendOn: SortingOrder.Descending } }
|
{ sort: { sendOn: SortingOrder.Descending } }
|
||||||
)
|
)
|
||||||
@ -84,7 +84,7 @@
|
|||||||
messages: convertMessages(object, channel, selectedMessages, $personAccountByIdStore, $employeeByIdStore)
|
messages: convertMessages(object, channel, selectedMessages, $personAccountByIdStore, $employeeByIdStore)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
await inboxClient.readDoc(channel._id)
|
await inboxClient.readDoc(getClient(), channel._id)
|
||||||
clear()
|
clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
let integrations: Integration[] = []
|
let integrations: Integration[] = []
|
||||||
let selectedIntegration: Integration | undefined = undefined
|
let selectedIntegration: Integration | undefined = undefined
|
||||||
|
|
||||||
inboxClient.forceReadDoc(channel._id, channel._class)
|
inboxClient.forceReadDoc(getClient(), channel._id, channel._class)
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
},
|
},
|
||||||
objectId
|
objectId
|
||||||
)
|
)
|
||||||
await inboxClient.forceReadDoc(channel._id, channel._class)
|
await inboxClient.forceReadDoc(getClient(), channel._id, channel._class)
|
||||||
objectId = generateId()
|
objectId = generateId()
|
||||||
dispatch('close')
|
dispatch('close')
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@
|
|||||||
.map((m) => m.trim())
|
.map((m) => m.trim())
|
||||||
.filter((m) => m.length)
|
.filter((m) => m.length)
|
||||||
})
|
})
|
||||||
await inboxClient.forceReadDoc(channel._id, channel._class)
|
await inboxClient.forceReadDoc(getClient(), channel._id, channel._class)
|
||||||
for (const attachment of attachments) {
|
for (const attachment of attachments) {
|
||||||
await client.addCollection(
|
await client.addCollection(
|
||||||
attachmentP.class.Attachment,
|
attachmentP.class.Attachment,
|
||||||
|
@ -213,13 +213,21 @@
|
|||||||
|
|
||||||
const contextNotifications = $notificationsByContextStore.get(selectedContext._id) ?? []
|
const contextNotifications = $notificationsByContextStore.get(selectedContext._id) ?? []
|
||||||
|
|
||||||
|
const doneOp = await getClient().measure('readNotifications')
|
||||||
|
const ops = getClient().apply(selectedContext._id)
|
||||||
|
try {
|
||||||
await inboxClient.readNotifications(
|
await inboxClient.readNotifications(
|
||||||
|
ops,
|
||||||
contextNotifications
|
contextNotifications
|
||||||
.filter(({ _class, isViewed }) =>
|
.filter(({ _class, isViewed }) =>
|
||||||
isChunterChannel ? _class === notification.class.CommonInboxNotification : !isViewed
|
isChunterChannel ? _class === notification.class.CommonInboxNotification : !isViewed
|
||||||
)
|
)
|
||||||
.map(({ _id }) => _id)
|
.map(({ _id }) => _id)
|
||||||
)
|
)
|
||||||
|
} finally {
|
||||||
|
await ops.commit()
|
||||||
|
await doneOp()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterNotifications (
|
function filterNotifications (
|
||||||
|
@ -78,7 +78,7 @@
|
|||||||
|
|
||||||
const context = $notifyContextsStore.find(({ _id }) => _id === displayData[listSelection]?.[0])
|
const context = $notifyContextsStore.find(({ _id }) => _id === displayData[listSelection]?.[0])
|
||||||
|
|
||||||
deleteContextNotifications(context)
|
void deleteContextNotifications(context)
|
||||||
}
|
}
|
||||||
if (key.code === 'Enter') {
|
if (key.code === 'Enter') {
|
||||||
key.preventDefault()
|
key.preventDefault()
|
||||||
|
@ -13,7 +13,15 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
import activity, { type ActivityMessage } from '@hcengineering/activity'
|
import activity, { type ActivityMessage } from '@hcengineering/activity'
|
||||||
import { SortingOrder, getCurrentAccount, type Class, type Doc, type Ref, type WithLookup } from '@hcengineering/core'
|
import {
|
||||||
|
SortingOrder,
|
||||||
|
getCurrentAccount,
|
||||||
|
type Class,
|
||||||
|
type Doc,
|
||||||
|
type Ref,
|
||||||
|
type TxOperations,
|
||||||
|
type WithLookup
|
||||||
|
} from '@hcengineering/core'
|
||||||
import notification, {
|
import notification, {
|
||||||
type ActivityInboxNotification,
|
type ActivityInboxNotification,
|
||||||
type Collaborators,
|
type Collaborators,
|
||||||
@ -21,7 +29,7 @@ import notification, {
|
|||||||
type InboxNotification,
|
type InboxNotification,
|
||||||
type InboxNotificationsClient
|
type InboxNotificationsClient
|
||||||
} from '@hcengineering/notification'
|
} from '@hcengineering/notification'
|
||||||
import { createQuery, getClient } from '@hcengineering/presentation'
|
import { createQuery } from '@hcengineering/presentation'
|
||||||
import { derived, get, writable } from 'svelte/store'
|
import { derived, get, writable } from 'svelte/store'
|
||||||
|
|
||||||
export const inboxMessagesStore = writable<ActivityMessage[]>([])
|
export const inboxMessagesStore = writable<ActivityMessage[]>([])
|
||||||
@ -132,30 +140,28 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
|
|||||||
return InboxNotificationsClientImpl._instance
|
return InboxNotificationsClientImpl._instance
|
||||||
}
|
}
|
||||||
|
|
||||||
async readDoc (_id: Ref<Doc>): Promise<void> {
|
async readDoc (client: TxOperations, _id: Ref<Doc>): Promise<void> {
|
||||||
const client = getClient()
|
|
||||||
const docNotifyContext = this._docNotifyContextByDoc.get(_id)
|
const docNotifyContext = this._docNotifyContextByDoc.get(_id)
|
||||||
|
|
||||||
if (docNotifyContext === undefined) {
|
if (docNotifyContext === undefined) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const inboxNotifications = get(this.inboxNotifications).filter(
|
const inboxNotifications = (get(this.inboxNotifications) ?? []).filter(
|
||||||
(notification) => notification.docNotifyContext === docNotifyContext._id && !notification.isViewed
|
(notification) => notification.docNotifyContext === docNotifyContext._id && !notification.isViewed
|
||||||
)
|
)
|
||||||
|
|
||||||
await Promise.all([
|
for (const notification of inboxNotifications) {
|
||||||
...inboxNotifications.map(async (notification) => await client.update(notification, { isViewed: true })),
|
await client.update(notification, { isViewed: true })
|
||||||
client.update(docNotifyContext, { lastViewedTimestamp: Date.now() })
|
}
|
||||||
])
|
await client.update(docNotifyContext, { lastViewedTimestamp: Date.now() })
|
||||||
}
|
}
|
||||||
|
|
||||||
async forceReadDoc (_id: Ref<Doc>, _class: Ref<Class<Doc>>): Promise<void> {
|
async forceReadDoc (client: TxOperations, _id: Ref<Doc>, _class: Ref<Class<Doc>>): Promise<void> {
|
||||||
const client = getClient()
|
|
||||||
const context = this._docNotifyContextByDoc.get(_id)
|
const context = this._docNotifyContextByDoc.get(_id)
|
||||||
|
|
||||||
if (context !== undefined) {
|
if (context !== undefined) {
|
||||||
await this.readDoc(_id)
|
await this.readDoc(client, _id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,40 +206,38 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async readMessages (ids: Array<Ref<ActivityMessage>>): Promise<void> {
|
async readMessages (client: TxOperations, ids: Array<Ref<ActivityMessage>>): Promise<void> {
|
||||||
const client = getClient()
|
|
||||||
const notificationsToRead = await client.findAll(notification.class.ActivityInboxNotification, {
|
const notificationsToRead = await client.findAll(notification.class.ActivityInboxNotification, {
|
||||||
user: getCurrentAccount()._id,
|
user: getCurrentAccount()._id,
|
||||||
attachedTo: { $in: ids },
|
attachedTo: { $in: ids },
|
||||||
isViewed: { $ne: true }
|
isViewed: { $ne: true }
|
||||||
})
|
})
|
||||||
|
|
||||||
await Promise.all(
|
for (const notification of notificationsToRead) {
|
||||||
notificationsToRead.map(async (notification) => await client.update(notification, { isViewed: true }))
|
await client.update(notification, { isViewed: true })
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async readNotifications (ids: Array<Ref<InboxNotification>>): Promise<void> {
|
async readNotifications (client: TxOperations, ids: Array<Ref<InboxNotification>>): Promise<void> {
|
||||||
const client = getClient()
|
const notificationsToRead = (get(this.inboxNotifications) ?? []).filter(({ _id }) => ids.includes(_id))
|
||||||
const notificationsToRead = get(this.inboxNotifications).filter(({ _id }) => ids.includes(_id))
|
|
||||||
|
for (const notification of notificationsToRead) {
|
||||||
await Promise.all(
|
await client.update(notification, { isViewed: true })
|
||||||
notificationsToRead.map(async (notification) => await client.update(notification, { isViewed: true }))
|
}
|
||||||
)
|
}
|
||||||
}
|
|
||||||
|
async unreadNotifications (client: TxOperations, ids: Array<Ref<InboxNotification>>): Promise<void> {
|
||||||
async unreadNotifications (ids: Array<Ref<InboxNotification>>): Promise<void> {
|
const notificationsToUnread = (get(this.inboxNotifications) ?? []).filter(({ _id }) => ids.includes(_id))
|
||||||
const client = getClient()
|
|
||||||
const notificationsToUnread = get(this.inboxNotifications).filter(({ _id }) => ids.includes(_id))
|
for (const notification of notificationsToUnread) {
|
||||||
|
await client.update(notification, { isViewed: false })
|
||||||
await Promise.all(
|
}
|
||||||
notificationsToUnread.map(async (notification) => await client.update(notification, { isViewed: false }))
|
}
|
||||||
)
|
|
||||||
}
|
async deleteNotifications (client: TxOperations, ids: Array<Ref<InboxNotification>>): Promise<void> {
|
||||||
|
const inboxNotifications = (get(this.inboxNotifications) ?? []).filter(({ _id }) => ids.includes(_id))
|
||||||
async deleteNotifications (ids: Array<Ref<InboxNotification>>): Promise<void> {
|
for (const notification of inboxNotifications) {
|
||||||
const client = getClient()
|
await client.remove(notification)
|
||||||
const inboxNotifications = get(this.inboxNotifications).filter(({ _id }) => ids.includes(_id))
|
}
|
||||||
await Promise.all(inboxNotifications.map(async (notification) => await client.remove(notification)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,37 +13,37 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
import { get } from 'svelte/store'
|
|
||||||
import {
|
|
||||||
type Class,
|
|
||||||
type Doc,
|
|
||||||
type DocumentUpdate,
|
|
||||||
getCurrentAccount,
|
|
||||||
type Ref,
|
|
||||||
SortingOrder,
|
|
||||||
type TxOperations,
|
|
||||||
type WithLookup
|
|
||||||
} from '@hcengineering/core'
|
|
||||||
import notification, {
|
|
||||||
type ActivityInboxNotification,
|
|
||||||
type Collaborators,
|
|
||||||
type DisplayActivityInboxNotification,
|
|
||||||
type DisplayInboxNotification,
|
|
||||||
type DocNotifyContext,
|
|
||||||
inboxId,
|
|
||||||
type InboxNotification
|
|
||||||
} from '@hcengineering/notification'
|
|
||||||
import { getClient } from '@hcengineering/presentation'
|
|
||||||
import { getLocation, navigate, type Location, type ResolvedLocation } from '@hcengineering/ui'
|
|
||||||
import activity, {
|
import activity, {
|
||||||
type ActivityMessage,
|
type ActivityMessage,
|
||||||
type DisplayDocUpdateMessage,
|
type DisplayDocUpdateMessage,
|
||||||
type DocUpdateMessage
|
type DocUpdateMessage
|
||||||
} from '@hcengineering/activity'
|
} from '@hcengineering/activity'
|
||||||
import { activityMessagesComparator, combineActivityMessages } from '@hcengineering/activity-resources'
|
import { activityMessagesComparator, combineActivityMessages } from '@hcengineering/activity-resources'
|
||||||
|
import {
|
||||||
|
SortingOrder,
|
||||||
|
getCurrentAccount,
|
||||||
|
type Class,
|
||||||
|
type Doc,
|
||||||
|
type DocumentUpdate,
|
||||||
|
type Ref,
|
||||||
|
type TxOperations,
|
||||||
|
type WithLookup
|
||||||
|
} from '@hcengineering/core'
|
||||||
|
import notification, {
|
||||||
|
inboxId,
|
||||||
|
type ActivityInboxNotification,
|
||||||
|
type Collaborators,
|
||||||
|
type DisplayActivityInboxNotification,
|
||||||
|
type DisplayInboxNotification,
|
||||||
|
type DocNotifyContext,
|
||||||
|
type InboxNotification
|
||||||
|
} from '@hcengineering/notification'
|
||||||
|
import { getClient } from '@hcengineering/presentation'
|
||||||
|
import { getLocation, navigate, type Location, type ResolvedLocation } from '@hcengineering/ui'
|
||||||
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
import { type InboxNotificationsFilter } from './types'
|
|
||||||
import { InboxNotificationsClientImpl } from './inboxNotificationsClient'
|
import { InboxNotificationsClientImpl } from './inboxNotificationsClient'
|
||||||
|
import { type InboxNotificationsFilter } from './types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
@ -77,13 +77,20 @@ export async function markAsReadInboxNotification (doc: DisplayInboxNotification
|
|||||||
const notificationsClient = InboxNotificationsClientImpl.getClient()
|
const notificationsClient = InboxNotificationsClientImpl.getClient()
|
||||||
const isActivityNotification = doc._class === notification.class.ActivityInboxNotification
|
const isActivityNotification = doc._class === notification.class.ActivityInboxNotification
|
||||||
|
|
||||||
const ids = isActivityNotification ? (doc as DisplayActivityInboxNotification).combinedIds : [doc._id]
|
const ids = (isActivityNotification ? (doc as DisplayActivityInboxNotification).combinedIds : [doc._id]) ?? []
|
||||||
|
|
||||||
if (isActivityNotification) {
|
if (isActivityNotification) {
|
||||||
await updateLastViewedTimestampOnRead(doc as WithLookup<ActivityInboxNotification>, ids)
|
await updateLastViewedTimestampOnRead(doc as WithLookup<ActivityInboxNotification>, ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
await notificationsClient.readNotifications(ids)
|
const doneOp = await getClient().measure('markAsRead')
|
||||||
|
const ops = getClient().apply(doc._id)
|
||||||
|
try {
|
||||||
|
await notificationsClient.readNotifications(ops, ids)
|
||||||
|
} finally {
|
||||||
|
await ops.commit()
|
||||||
|
await doneOp()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateLastViewedTimestampOnRead (
|
async function updateLastViewedTimestampOnRead (
|
||||||
@ -158,7 +165,14 @@ export async function markAsUnreadInboxNotification (doc: DisplayInboxNotificati
|
|||||||
await updateLastViewedOnUnread(doc as WithLookup<ActivityInboxNotification>)
|
await updateLastViewedOnUnread(doc as WithLookup<ActivityInboxNotification>)
|
||||||
}
|
}
|
||||||
|
|
||||||
await inboxNotificationsClient.unreadNotifications(ids)
|
const doneOp = await getClient().measure('unreadNotifications')
|
||||||
|
const ops = getClient().apply(doc._id)
|
||||||
|
try {
|
||||||
|
await inboxNotificationsClient.unreadNotifications(ops, ids)
|
||||||
|
} finally {
|
||||||
|
await ops.commit()
|
||||||
|
await doneOp()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteInboxNotification (doc: DisplayInboxNotification): Promise<void> {
|
export async function deleteInboxNotification (doc: DisplayInboxNotification): Promise<void> {
|
||||||
@ -171,7 +185,14 @@ export async function deleteInboxNotification (doc: DisplayInboxNotification): P
|
|||||||
await updateLastViewedTimestampOnRead(doc as WithLookup<ActivityInboxNotification>, ids)
|
await updateLastViewedTimestampOnRead(doc as WithLookup<ActivityInboxNotification>, ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
await inboxNotificationsClient.deleteNotifications(ids)
|
const doneOp = await getClient().measure('deleteNotifications')
|
||||||
|
const ops = getClient().apply(doc._id)
|
||||||
|
try {
|
||||||
|
await inboxNotificationsClient.deleteNotifications(ops, ids)
|
||||||
|
} finally {
|
||||||
|
await ops.commit()
|
||||||
|
await doneOp()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function hasDocNotifyContextPinAction (docNotifyContext: DocNotifyContext): Promise<boolean> {
|
export async function hasDocNotifyContextPinAction (docNotifyContext: DocNotifyContext): Promise<boolean> {
|
||||||
@ -235,19 +256,27 @@ export async function canUnReadNotifyContext (doc: DocNotifyContext): Promise<bo
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export async function readNotifyContext (doc: DocNotifyContext): Promise<void> {
|
export async function readNotifyContext (doc: DocNotifyContext): Promise<void> {
|
||||||
const client = getClient()
|
|
||||||
const inboxClient = InboxNotificationsClientImpl.getClient()
|
const inboxClient = InboxNotificationsClientImpl.getClient()
|
||||||
const inboxNotifications = get(inboxClient.inboxNotificationsByContext).get(doc._id) ?? []
|
const inboxNotifications = get(inboxClient.inboxNotificationsByContext).get(doc._id) ?? []
|
||||||
|
|
||||||
await inboxClient.readNotifications(inboxNotifications.map(({ _id }) => _id))
|
const doneOp = await getClient().measure('readNotifyContext')
|
||||||
await client.update(doc, { lastViewedTimestamp: Date.now() })
|
const ops = getClient().apply(doc._id)
|
||||||
|
try {
|
||||||
|
await inboxClient.readNotifications(
|
||||||
|
ops,
|
||||||
|
inboxNotifications.map(({ _id }) => _id)
|
||||||
|
)
|
||||||
|
await ops.update(doc, { lastViewedTimestamp: Date.now() })
|
||||||
|
} finally {
|
||||||
|
await ops.commit()
|
||||||
|
await doneOp()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export async function unReadNotifyContext (doc: DocNotifyContext): Promise<void> {
|
export async function unReadNotifyContext (doc: DocNotifyContext): Promise<void> {
|
||||||
const client = getClient()
|
|
||||||
const inboxClient = InboxNotificationsClientImpl.getClient()
|
const inboxClient = InboxNotificationsClientImpl.getClient()
|
||||||
const inboxNotifications = get(inboxClient.inboxNotificationsByContext).get(doc._id) ?? []
|
const inboxNotifications = get(inboxClient.inboxNotificationsByContext).get(doc._id) ?? []
|
||||||
const notificationToUnread = inboxNotifications[0]
|
const notificationToUnread = inboxNotifications[0]
|
||||||
@ -256,7 +285,11 @@ export async function unReadNotifyContext (doc: DocNotifyContext): Promise<void>
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await inboxClient.unreadNotifications([notificationToUnread._id])
|
const doneOp = await getClient().measure('unReadNotifyContext')
|
||||||
|
const ops = getClient().apply(doc._id)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await inboxClient.unreadNotifications(ops, [notificationToUnread._id])
|
||||||
|
|
||||||
if (notificationToUnread._class === notification.class.ActivityInboxNotification) {
|
if (notificationToUnread._class === notification.class.ActivityInboxNotification) {
|
||||||
const activityNotification = notificationToUnread as WithLookup<ActivityInboxNotification>
|
const activityNotification = notificationToUnread as WithLookup<ActivityInboxNotification>
|
||||||
@ -266,7 +299,11 @@ export async function unReadNotifyContext (doc: DocNotifyContext): Promise<void>
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await client.diffUpdate(doc, { lastViewedTimestamp: createdOn - 1 })
|
await ops.diffUpdate(doc, { lastViewedTimestamp: createdOn - 1 })
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
await ops.commit()
|
||||||
|
await doneOp()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,12 +315,21 @@ export async function deleteContextNotifications (doc?: DocNotifyContext): Promi
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = getClient()
|
|
||||||
const inboxClient = InboxNotificationsClientImpl.getClient()
|
const inboxClient = InboxNotificationsClientImpl.getClient()
|
||||||
const inboxNotifications = get(inboxClient.inboxNotificationsByContext).get(doc._id) ?? []
|
const inboxNotifications = get(inboxClient.inboxNotificationsByContext).get(doc._id) ?? []
|
||||||
|
|
||||||
await inboxClient.deleteNotifications(inboxNotifications.map(({ _id }) => _id))
|
const doneOp = await getClient().measure('deleteContextNotifications')
|
||||||
await client.update(doc, { lastViewedTimestamp: Date.now() })
|
const ops = getClient().apply(doc._id)
|
||||||
|
try {
|
||||||
|
await inboxClient.deleteNotifications(
|
||||||
|
ops,
|
||||||
|
inboxNotifications.map(({ _id }) => _id)
|
||||||
|
)
|
||||||
|
await ops.update(doc, { lastViewedTimestamp: Date.now() })
|
||||||
|
} finally {
|
||||||
|
await ops.commit()
|
||||||
|
await doneOp()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum OpWithMe {
|
enum OpWithMe {
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import { ActivityMessage } from '@hcengineering/activity'
|
||||||
import {
|
import {
|
||||||
Account,
|
Account,
|
||||||
AnyAttribute,
|
AnyAttribute,
|
||||||
@ -25,16 +26,16 @@ import {
|
|||||||
Space,
|
Space,
|
||||||
Timestamp,
|
Timestamp,
|
||||||
Tx,
|
Tx,
|
||||||
TxCUD
|
TxCUD,
|
||||||
|
TxOperations
|
||||||
} from '@hcengineering/core'
|
} from '@hcengineering/core'
|
||||||
import type { Asset, IntlString, Plugin, Resource } from '@hcengineering/platform'
|
import type { Asset, IntlString, Plugin, Resource } from '@hcengineering/platform'
|
||||||
import { plugin } from '@hcengineering/platform'
|
import { plugin } from '@hcengineering/platform'
|
||||||
|
import { Preference } from '@hcengineering/preference'
|
||||||
import { IntegrationType } from '@hcengineering/setting'
|
import { IntegrationType } from '@hcengineering/setting'
|
||||||
import { AnyComponent, Location, ResolvedLocation } from '@hcengineering/ui'
|
import { AnyComponent, Location, ResolvedLocation } from '@hcengineering/ui'
|
||||||
import { Readable, Writable } from './types'
|
|
||||||
import { Preference } from '@hcengineering/preference'
|
|
||||||
import { Action, Viewlet, ViewletDescriptor } from '@hcengineering/view'
|
import { Action, Viewlet, ViewletDescriptor } from '@hcengineering/view'
|
||||||
import { ActivityMessage } from '@hcengineering/activity'
|
import { Readable, Writable } from './types'
|
||||||
|
|
||||||
export * from './types'
|
export * from './types'
|
||||||
|
|
||||||
@ -275,12 +276,12 @@ export interface InboxNotificationsClient {
|
|||||||
inboxNotifications: Readable<InboxNotification[]>
|
inboxNotifications: Readable<InboxNotification[]>
|
||||||
activityInboxNotifications: Writable<ActivityInboxNotification[]>
|
activityInboxNotifications: Writable<ActivityInboxNotification[]>
|
||||||
inboxNotificationsByContext: Readable<Map<Ref<DocNotifyContext>, InboxNotification[]>>
|
inboxNotificationsByContext: Readable<Map<Ref<DocNotifyContext>, InboxNotification[]>>
|
||||||
readDoc: (_id: Ref<Doc>) => Promise<void>
|
readDoc: (client: TxOperations, _id: Ref<Doc>) => Promise<void>
|
||||||
forceReadDoc: (_id: Ref<Doc>, _class: Ref<Class<Doc>>) => Promise<void>
|
forceReadDoc: (client: TxOperations, _id: Ref<Doc>, _class: Ref<Class<Doc>>) => Promise<void>
|
||||||
readMessages: (ids: Ref<ActivityMessage>[]) => Promise<void>
|
readMessages: (client: TxOperations, ids: Ref<ActivityMessage>[]) => Promise<void>
|
||||||
readNotifications: (ids: Array<Ref<InboxNotification>>) => Promise<void>
|
readNotifications: (client: TxOperations, ids: Array<Ref<InboxNotification>>) => Promise<void>
|
||||||
unreadNotifications: (ids: Array<Ref<InboxNotification>>) => Promise<void>
|
unreadNotifications: (client: TxOperations, ids: Array<Ref<InboxNotification>>) => Promise<void>
|
||||||
deleteNotifications: (ids: Array<Ref<InboxNotification>>) => Promise<void>
|
deleteNotifications: (client: TxOperations, ids: Array<Ref<InboxNotification>>) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
const inboxClient = getResource(notification.function.GetInboxNotificationsClient).then((res) => res())
|
const inboxClient = getResource(notification.function.GetInboxNotificationsClient).then((res) => res())
|
||||||
|
|
||||||
onDestroy(async () => {
|
onDestroy(async () => {
|
||||||
void inboxClient.then((client) => client.readDoc(_id))
|
void inboxClient.then((client) => client.readDoc(getClient(), _id))
|
||||||
})
|
})
|
||||||
|
|
||||||
const client = getClient()
|
const client = getClient()
|
||||||
@ -57,7 +57,7 @@
|
|||||||
const prev = lastId
|
const prev = lastId
|
||||||
lastId = _id
|
lastId = _id
|
||||||
if (prev !== undefined) {
|
if (prev !== undefined) {
|
||||||
void inboxClient.then((client) => client.readDoc(prev))
|
void inboxClient.then((client) => client.readDoc(getClient(), prev))
|
||||||
}
|
}
|
||||||
query.query(recruit.class.Vacancy, { _id }, (result) => {
|
query.query(recruit.class.Vacancy, { _id }, (result) => {
|
||||||
object = result[0] as Required<Vacancy>
|
object = result[0] as Required<Vacancy>
|
||||||
|
@ -78,12 +78,12 @@
|
|||||||
if (lastId !== _id) {
|
if (lastId !== _id) {
|
||||||
const prev = lastId
|
const prev = lastId
|
||||||
lastId = _id
|
lastId = _id
|
||||||
void inboxClient.then((client) => client.readDoc(prev))
|
void inboxClient.then((client) => client.readDoc(getClient(), prev))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy(async () => {
|
onDestroy(async () => {
|
||||||
void inboxClient.then((client) => client.readDoc(_id))
|
void inboxClient.then((client) => client.readDoc(getClient(), _id))
|
||||||
})
|
})
|
||||||
|
|
||||||
$: _id !== undefined &&
|
$: _id !== undefined &&
|
||||||
|
@ -54,12 +54,12 @@
|
|||||||
if (lastId !== _id) {
|
if (lastId !== _id) {
|
||||||
const prev = lastId
|
const prev = lastId
|
||||||
lastId = _id
|
lastId = _id
|
||||||
void inboxClient.then((client) => client.readDoc(prev))
|
void inboxClient.then((client) => client.readDoc(getClient(), prev))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy(async () => {
|
onDestroy(async () => {
|
||||||
void inboxClient.then((client) => client.readDoc(_id))
|
void inboxClient.then((client) => client.readDoc(getClient(), _id))
|
||||||
})
|
})
|
||||||
|
|
||||||
$: _id !== undefined &&
|
$: _id !== undefined &&
|
||||||
|
@ -45,24 +45,24 @@
|
|||||||
let lastId: Ref<Doc> = _id
|
let lastId: Ref<Doc> = _id
|
||||||
let object: Doc
|
let object: Doc
|
||||||
|
|
||||||
const client = getClient()
|
const pClient = getClient()
|
||||||
const hierarchy = client.getHierarchy()
|
const hierarchy = pClient.getHierarchy()
|
||||||
const inboxClient = getResource(notification.function.GetInboxNotificationsClient).then((res) => res())
|
const inboxClient = getResource(notification.function.GetInboxNotificationsClient).then((res) => res())
|
||||||
|
|
||||||
$: read(_id)
|
$: read(_id)
|
||||||
function read (_id: Ref<Doc>) {
|
function read (_id: Ref<Doc>): void {
|
||||||
if (lastId !== _id) {
|
if (lastId !== _id) {
|
||||||
const prev = lastId
|
const prev = lastId
|
||||||
lastId = _id
|
lastId = _id
|
||||||
inboxClient.then(async (client) => {
|
void inboxClient.then(async (client) => {
|
||||||
await client.readDoc(prev)
|
await client.readDoc(pClient, prev)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy(async () => {
|
onDestroy(async () => {
|
||||||
await inboxClient.then(async (client) => {
|
await inboxClient.then(async (client) => {
|
||||||
await client.readDoc(_id)
|
await client.readDoc(pClient, _id)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -195,7 +195,7 @@
|
|||||||
let rawTitle: string = ''
|
let rawTitle: string = ''
|
||||||
|
|
||||||
$: if (object !== undefined) {
|
$: if (object !== undefined) {
|
||||||
getDocLabel(client, object).then((t) => {
|
getDocLabel(pClient, object).then((t) => {
|
||||||
if (t) {
|
if (t) {
|
||||||
rawTitle = t
|
rawTitle = t
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user