@@ -3,13 +3,22 @@ import { DomSanitizer } from '@angular/platform-browser';
33import { ActivatedRoute } from '@angular/router' ;
44import { NavController } from '@ionic/angular' ;
55import { UntilDestroy , untilDestroyed } from '@ngneat/until-destroy' ;
6- import { combineLatest , fromEvent } from 'rxjs' ;
7- import { map , tap } from 'rxjs/operators' ;
6+ import { combineLatest , fromEvent , of } from 'rxjs' ;
7+ import {
8+ concatMap ,
9+ finalize ,
10+ first ,
11+ map ,
12+ tap as switchTap ,
13+ } from 'rxjs/operators' ;
814import { DiaBackendAuthService } from '../../../../shared/dia-backend/auth/dia-backend-auth.service' ;
915import { BUBBLE_IFRAME_URL } from '../../../../shared/dia-backend/secret' ;
1016import { BubbleToIonicPostMessage } from '../../../../shared/iframe/iframe' ;
1117import { IframeService } from '../../../../shared/iframe/iframe.service' ;
18+ import { getOldProof } from '../../../../shared/repositories/proof/old-proof-adapter' ;
19+ import { ProofRepository } from '../../../../shared/repositories/proof/proof-repository.service' ;
1220import { isNonNullable } from '../../../../utils/rx-operators/rx-operators' ;
21+ import { InformationSessionService } from '../information/session/information-session.service' ;
1322
1423@UntilDestroy ( )
1524@Component ( {
@@ -43,15 +52,17 @@ export class EditCaptionPage {
4352 private readonly sanitizer : DomSanitizer ,
4453 private readonly navController : NavController ,
4554 private readonly iframeService : IframeService ,
46- private readonly diaBackendAuthService : DiaBackendAuthService
55+ private readonly diaBackendAuthService : DiaBackendAuthService ,
56+ private readonly informationSessionService : InformationSessionService ,
57+ private readonly proofRepository : ProofRepository
4758 ) {
4859 this . processIframeEvents ( ) ;
4960 }
5061
5162 processIframeEvents ( ) {
5263 fromEvent ( window , 'message' )
5364 . pipe (
54- tap ( event => {
65+ switchTap ( event => {
5566 const postMessageEvent = event as MessageEvent ;
5667 const data = postMessageEvent . data as BubbleToIonicPostMessage ;
5768 switch ( data ) {
@@ -60,12 +71,36 @@ export class EditCaptionPage {
6071 break ;
6172 case BubbleToIonicPostMessage . EDIT_CAPTION_SAVE :
6273 this . iframeService . refreshDetailsPageIframe ( ) ;
63- this . navController . back ( ) ;
74+ this . syncCaptionAndNavigateBack ( ) ;
6475 break ;
6576 }
6677 } ) ,
6778 untilDestroyed ( this )
6879 )
6980 . subscribe ( ) ;
7081 }
82+
83+ syncCaptionAndNavigateBack ( ) {
84+ if ( this . informationSessionService . activatedDetailedCapture ) {
85+ combineLatest ( [
86+ this . informationSessionService . activatedDetailedCapture . proof$ ,
87+ this . informationSessionService . activatedDetailedCapture . caption$ ,
88+ ] )
89+ . pipe (
90+ first ( ) ,
91+ concatMap ( ( [ proof , latestCaptionFromBackend ] ) => {
92+ if ( proof ) {
93+ proof . caption = latestCaptionFromBackend ;
94+ return this . proofRepository . update (
95+ [ proof ] ,
96+ ( x , y ) => getOldProof ( x ) . hash === getOldProof ( y ) . hash
97+ ) ;
98+ }
99+ return of ( null ) ;
100+ } ) ,
101+ finalize ( ( ) => this . navController . back ( ) )
102+ )
103+ . subscribe ( ) ;
104+ }
105+ }
71106}
0 commit comments