@@ -31,6 +31,7 @@ import Quill, { Delta, EmitterSource, Range } from 'quill';
31
31
import { User } from 'realtime-server/lib/esm/common/models/user' ;
32
32
import { createTestUser } from 'realtime-server/lib/esm/common/models/user-test-data' ;
33
33
import { WritingSystem } from 'realtime-server/lib/esm/common/models/writing-system' ;
34
+ import { Json0OpBuilder } from 'realtime-server/lib/esm/common/utils/json0-op-builder' ;
34
35
import { obj } from 'realtime-server/lib/esm/common/utils/obj-path' ;
35
36
import { RecursivePartial } from 'realtime-server/lib/esm/common/utils/type-utils' ;
36
37
import { BiblicalTerm } from 'realtime-server/lib/esm/scriptureforge/models/biblical-term' ;
@@ -70,6 +71,7 @@ import { CONSOLE } from 'xforge-common/browser-globals';
70
71
import { BugsnagService } from 'xforge-common/bugsnag.service' ;
71
72
import { createTestFeatureFlag , FeatureFlagService } from 'xforge-common/feature-flags/feature-flag.service' ;
72
73
import { GenericDialogComponent , GenericDialogOptions } from 'xforge-common/generic-dialog/generic-dialog.component' ;
74
+ import { MemoryRealtimeDocAdapter } from 'xforge-common/memory-realtime-remote-store' ;
73
75
import { UserDoc } from 'xforge-common/models/user-doc' ;
74
76
import { NoticeService } from 'xforge-common/notice.service' ;
75
77
import { OnlineStatusService } from 'xforge-common/online-status.service' ;
@@ -3373,7 +3375,7 @@ describe('EditorComponent', () => {
3373
3375
env . dispose ( ) ;
3374
3376
} ) ) ;
3375
3377
3376
- it ( 'should remove resolved notes after a remote update' , fakeAsync ( ( ) => {
3378
+ it ( 'should remove resolved notes after a remote update' , fakeAsync ( async ( ) => {
3377
3379
const env = new TestEnvironment ( ) ;
3378
3380
env . setProjectUserConfig ( ) ;
3379
3381
env . wait ( ) ;
@@ -3382,7 +3384,7 @@ describe('EditorComponent', () => {
3382
3384
let noteThreadEmbedCount = env . countNoteThreadEmbeds ( contents . ops ! ) ;
3383
3385
expect ( noteThreadEmbedCount ) . toEqual ( 5 ) ;
3384
3386
3385
- env . resolveNote ( 'project01' , 'dataid01' ) ;
3387
+ await env . resolveNote ( 'project01' , 'dataid01' , 'remote ') ;
3386
3388
contents = env . targetEditor . getContents ( ) ;
3387
3389
noteThreadEmbedCount = env . countNoteThreadEmbeds ( contents . ops ! ) ;
3388
3390
expect ( noteThreadEmbedCount ) . toEqual ( 4 ) ;
@@ -5594,10 +5596,31 @@ class TestEnvironment {
5594
5596
return noteEmbedCount ;
5595
5597
}
5596
5598
5597
- resolveNote ( projectId : string , threadId : string ) : void {
5599
+ async resolveNote ( projectId : string , threadId : string , origin : 'local' | 'remote' ) : Promise < void > {
5598
5600
const noteDoc : NoteThreadDoc = this . getNoteThreadDoc ( projectId , threadId ) ;
5599
- noteDoc . submitJson0Op ( op => op . set ( n => n . status , NoteStatus . Resolved ) ) ;
5600
- this . realtimeService . updateQueryAdaptersRemote ( ) ;
5601
+ const builder = new Json0OpBuilder ( noteDoc . data ) ;
5602
+ const ops = op => op . set ( n => n . status , NoteStatus . Resolved ) ;
5603
+
5604
+ if ( origin === 'remote' ) {
5605
+ const docAdapter : MemoryRealtimeDocAdapter = noteDoc . adapter as MemoryRealtimeDocAdapter ;
5606
+ ops ( builder ) ;
5607
+ const operations = builder . op ;
5608
+ // Don't let the doc adapter emit about changes before the query updates its result list. Otherwise code might
5609
+ // hear about the change and examine the query before it is updated.
5610
+ const quietAdapter = Object . assign ( Object . create ( Object . getPrototypeOf ( docAdapter ) ) , docAdapter , {
5611
+ changes$ : new Subject < any > ( ) ,
5612
+ remoteChanges$ : new Subject < any > ( )
5613
+ } ) ;
5614
+ // Using submitOp to simulate writing data on a remote server may seem backwards but is getting the job done.
5615
+ await quietAdapter . submitOp ( operations , false ) ;
5616
+ // Update the query results and emit changes. The order of emits, and presence or absence of
5617
+ // RealtimeQuery.remoteDocChanges$, may be different than when running the app.
5618
+ this . realtimeService . updateQueryAdaptersRemote ( ) ;
5619
+ docAdapter . emitChange ( operations ) ;
5620
+ docAdapter . emitRemoteChange ( operations ) ;
5621
+ } else {
5622
+ await noteDoc . submitJson0Op ( ops ) ;
5623
+ }
5601
5624
this . wait ( ) ;
5602
5625
}
5603
5626
0 commit comments