@@ -853,6 +853,7 @@ async function getTxCollabs (
853
853
( await control . findAll ( ctx , core . class . Collaborator , {
854
854
attachedTo : doc . _id
855
855
} ) )
856
+ cache . set ( doc . _id , collaborators )
856
857
const collabs = collaborators . map ( ( c ) => c . collaborator )
857
858
const ops = isMixinTx ( tx ) ? tx . attributes : ( tx as TxUpdateDoc < Doc > ) . operations
858
859
const newCollaborators = ( await getNewCollaborators ( ops , mixin , doc . _class , control ) ) . filter (
@@ -1375,45 +1376,51 @@ async function updateCollaborators (
1375
1376
tx : TxCUD < Doc > ,
1376
1377
cache : Map < Ref < Doc > , Collaborator [ ] >
1377
1378
) : 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 [ ]
1380
1380
1381
1381
const hierarchy = control . hierarchy
1382
1382
1383
+ if ( hierarchy . classHierarchyMixin ( tx . objectClass , activity . mixin . ActivityDoc ) === undefined ) return [ ]
1384
+
1383
1385
const mixin = getClassCollaborators ( control . modelDb , hierarchy , tx . objectClass )
1384
- if ( mixin === undefined || tx . attachedToClass === undefined || tx . attachedTo === undefined ) return [ ]
1386
+ if ( mixin === undefined ) return [ ]
1385
1387
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 [ ]
1387
1393
1388
- const contexts = await control . findAll ( control . ctx , notification . class . DocNotifyContext , { objectId : tx . attachedTo } )
1389
1394
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 } ) )
1400
1417
}
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
- )
1412
1418
}
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 )
1417
1424
}
1418
1425
1419
1426
return res
0 commit comments