Skip to content

Commit a97ad11

Browse files
Fix collaborators tests (#9331)
Signed-off-by: Kristina Fefelova <[email protected]>
1 parent 36d2c04 commit a97ad11

File tree

2 files changed

+46
-37
lines changed

2 files changed

+46
-37
lines changed

plugins/tracker-resources/src/components/myissues/MyIssues.svelte

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
-->
1515
<script lang="ts">
1616
import { getCurrentEmployee } from '@hcengineering/contact'
17-
import { Doc, DocumentQuery, getCurrentAccount, Ref } from '@hcengineering/core'
17+
import core, { DocumentQuery, getCurrentAccount, Ref } from '@hcengineering/core'
1818
import type { IntlString, Asset } from '@hcengineering/platform'
19-
import { createQuery } from '@hcengineering/presentation'
19+
import { createQuery, getClient } from '@hcengineering/presentation'
2020
import type { Issue, IssueStatus } from '@hcengineering/tracker'
2121
import { IModeSelector, resolvedLocationStore } from '@hcengineering/ui'
2222
import { createEventDispatcher } from 'svelte'
@@ -28,6 +28,8 @@
2828
export let config: [string, IntlString, object][] = []
2929
export let icon: Asset | undefined = undefined
3030
31+
const client = getClient()
32+
const hierarchy = client.getHierarchy()
3133
const socialIds = getCurrentAccount().socialIds
3234
const acc = getCurrentAccount().uuid
3335
const dispatch = createEventDispatcher()
@@ -64,16 +66,16 @@
6466
6567
const subscribedQuery = createQuery()
6668
$: subscribedQuery.query(
67-
tracker.class.Issue,
68-
{ 'notification:mixin:Collaborators.collaborators': acc },
69-
(result) => {
70-
const newSub = result.map((p) => p._id as Ref<Doc> as Ref<Issue>)
69+
core.class.Collaborator,
70+
{ collaborator: acc, attachedToClass: { $in: hierarchy.getDescendants(tracker.class.Issue) } },
71+
(collaborators) => {
72+
const newSub = collaborators.map((it) => it.attachedTo as Ref<Issue>)
7173
const curSub = subscribed._id.$in
7274
if (curSub.length !== newSub.length || curSub.some((id, i) => newSub[i] !== id)) {
7375
subscribed = { _id: { $in: newSub } }
7476
}
7577
},
76-
{ sort: { _id: 1 }, projection: { _id: 1 } }
78+
{ sort: { attachedTo: 1 }, projection: { attachedTo: 1 } }
7779
)
7880
7981
$: queries = { assigned, active, backlog, created, subscribed }

server-plugins/notification-resources/src/index.ts

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ async function getTxCollabs (
853853
(await control.findAll(ctx, core.class.Collaborator, {
854854
attachedTo: doc._id
855855
}))
856+
cache.set(doc._id, collaborators)
856857
const collabs = collaborators.map((c) => c.collaborator)
857858
const ops = isMixinTx(tx) ? tx.attributes : (tx as TxUpdateDoc<Doc>).operations
858859
const newCollaborators = (await getNewCollaborators(ops, mixin, doc._class, control)).filter(
@@ -1375,45 +1376,51 @@ async function updateCollaborators (
13751376
tx: TxCUD<Doc>,
13761377
cache: Map<Ref<Doc>, Collaborator[]>
13771378
): Promise<Tx[]> {
1378-
if (tx._class !== core.class.TxCreateDoc && tx._class !== core.class.TxRemoveDoc) return []
1379-
if (tx.objectClass !== core.class.Collaborator) return []
1379+
if (tx._class !== core.class.TxUpdateDoc && tx._class !== core.class.TxMixin) return []
13801380

13811381
const hierarchy = control.hierarchy
13821382

1383+
if (hierarchy.classHierarchyMixin(tx.objectClass, activity.mixin.ActivityDoc) === undefined) return []
1384+
13831385
const mixin = getClassCollaborators(control.modelDb, hierarchy, tx.objectClass)
1384-
if (mixin === undefined || tx.attachedToClass === undefined || tx.attachedTo === undefined) return []
1386+
if (mixin === undefined) return []
13851387

1386-
if (hierarchy.classHierarchyMixin(tx.attachedToClass, activity.mixin.ActivityDoc) === undefined) return []
1388+
const doc = (await control.findAll(ctx, tx.objectClass, { _id: tx.objectId }, { limit: 1 }))[0]
1389+
if (doc === undefined) return []
1390+
1391+
const collabsResult = await getTxCollabs(ctx, tx, control, cache, doc)
1392+
if (collabsResult.added.length === 0 && collabsResult.removed.length === 0) return []
13871393

1388-
const contexts = await control.findAll(control.ctx, notification.class.DocNotifyContext, { objectId: tx.attachedTo })
13891394
const res: Tx[] = []
1390-
if (tx._class === core.class.TxCreateDoc) {
1391-
const collab = TxProcessor.createDoc2Doc(tx as TxCreateDoc<Collaborator>)
1392-
const addedInfo = await getReceiversInfo(ctx, [collab.collaborator], control)
1393-
1394-
for (const info of addedInfo.values()) {
1395-
const context = getDocNotifyContext(control, contexts, tx.attachedTo, info.account)
1396-
if (context !== undefined) {
1397-
if (context.hidden) {
1398-
res.push(control.txFactory.createTxUpdateDoc(context._class, context.space, context._id, { hidden: false }))
1399-
}
1395+
1396+
const { txes: collabTxes } = await createSyncCollaboratorsTxes(
1397+
ctx,
1398+
control,
1399+
cache,
1400+
doc._id,
1401+
doc._class,
1402+
doc.space,
1403+
collabsResult.added,
1404+
collabsResult.removed
1405+
)
1406+
1407+
res.push(...collabTxes)
1408+
1409+
const contexts = await control.findAll(control.ctx, notification.class.DocNotifyContext, { objectId: tx.attachedTo })
1410+
const addedInfo = collabsResult.added.length > 0 ? await getReceiversInfo(ctx, collabsResult.added, control) : []
1411+
1412+
for (const info of addedInfo) {
1413+
const context = getDocNotifyContext(control, contexts, doc._id, info.account)
1414+
if (context !== undefined) {
1415+
if (context.hidden) {
1416+
res.push(control.txFactory.createTxUpdateDoc(context._class, context.space, context._id, { hidden: false }))
14001417
}
1401-
await createNotifyContext(
1402-
ctx,
1403-
control,
1404-
tx.attachedTo,
1405-
tx.attachedToClass,
1406-
tx.objectSpace,
1407-
info,
1408-
tx.modifiedBy,
1409-
undefined,
1410-
tx
1411-
)
14121418
}
1413-
} else {
1414-
const removed = control.removedMap.get(tx.objectId) as Collaborator
1415-
if (removed === undefined) return []
1416-
await removeContexts(ctx, contexts, [removed.collaborator], control)
1419+
await createNotifyContext(ctx, control, doc._id, doc._class, doc.space, info, tx.modifiedBy, undefined, tx)
1420+
}
1421+
1422+
if (collabsResult.removed.length > 0) {
1423+
await removeContexts(ctx, contexts, collabsResult.removed, control)
14171424
}
14181425

14191426
return res

0 commit comments

Comments
 (0)