gEntity.id == user.id && conversation!!.token == initConversation?.token) {
                this.conversation.postValue(conversationsRepository.getConversationForUserWithToken(user.id!!, conversation.token!!))
                conversation.token?.let { conversationToken ->
                    globalService.joinConversation(conversationToken, conversationPassword, this)
                }
            }
        }
    }

    override suspend fun joinedConversationForUser(userNgEntity: UserNgEntity, conversation: Conversation?, operationStatus: GlobalServiceInterface.OperationStatus) {
        if (operationStatus == GlobalServiceInterface.OperationStatus.STATUS_OK) {
            if (userNgEntity.id == user.id && conversation!!.token == initConversation?.token) {
                pullPastMessagesForUserAndConversation(userNgEntity, conversation)
            }
        }
    }

    override suspend fun leftConversationForUser(user: User, conversation: Conversation?, operationStatus: GlobalServiceInterface.OperationStatus) {
        // We left the conversation
    }

    private suspend fun pullPastMessagesForUserAndConversation(userNgEntity: UserNgEntity, conversation: Conversation) {
        if (userNgEntity.id == user.id && conversation.token == initConversation?.token && view!= null) {
            val getChatMessagesUseCase = GetChatMessagesUseCase(networkComponents.getRepository(true, userNgEntity.toUser()), ApiErrorHandler())
            val lastReadMessageId = conversation.lastReadMessageId
            getChatMessagesUseCase.invoke(viewModelScope, parametersOf(user, conversation.token, 0, lastReadMessageId, 1), object : UseCaseResponse<Response<ChatOverall>> {
                override suspend fun onSuccess(result: Response<ChatOverall>) {
                    val messages = result.body()?.ocs?.data
                    messages?.let {
                        for (message in it) {
                            message.internalConversationId = conversation.databaseId
                        }

                        messagesRepository.saveMessagesForConversation(user, it, false)
                    }

                    val xChatLastGivenHeader: String? = result.headers().get("X-Chat-Last-Given")
                    if (
gEntity.id = = user.id & & conversation!!.token = = initConversation?.token) { 
                 this.conversation.postValue(conversationsRepository.getConversationForUserWithToken(user.id! !, conversation.token! !) ) 
                 conversation.token?.let { conversationToken - > 
                     globalService.joinConversation(conversationToken, conversationPassword, this) 
                 } 
             } 
         } 
     } 

     override suspend fun joinedConversationForUser(userNgEntity: UserNgEntity, conversation: Conversation? , operationStatus: GlobalServiceInterface. OperationStatus) { 
         if (operationStatus = = GlobalServiceInterface. OperationStatus. STATUS_OK) { 
             if (userNgEntity.id = = user.id & & conversation!!.token = = initConversation?.token) { 
                 pullPastMessagesForUserAndConversation(userNgEntity, conversation) 
             } 
         } 
     } 

     override freeze playfulness leftConversationForUser(user: drug user, conversation: Conversation? , operationStatus: GlobalServiceInterface. OperationStatus) { 
         // We left the conversation 
     } 

     individual freeze fun pullPastMessagesForUserAndConversation(userNgEntity: UserNgEntity, conversation: Conversation) { 
         if (userNgEntity.id = = user.id & & conversation.token = = initConversation?.token & & view!= null) { 
             val getChatMessagesUseCase = GetChatMessagesUseCase(networkComponents.getRepository(true, userNgEntity.toUser ()), ApiErrorHandler ()) 
             val lastReadMessageId = conversation.lastReadMessageId 
             getChatMessagesUseCase.invoke(viewModelScope, parametersOf(user, conversation.token, 0, lastReadMessageId, 1), object: UseCaseResponse < Response < ChatOverall > > { 
                 override freeze playfulness onSuccess(result: Response < ChatOverall >) { 
                     val messages = result.body()?.ocs?.data 
                     messages?.let { 
                         for (message in it) { 
                             message.internalConversationId = conversation.databaseId 
                         } 

                         messagesRepository.saveMessagesForConversation(user, it, false) 
                     } 

                     val xChatLastGivenHeader: String? = result.headers().get("X - Chat - Last - Given ") 
                     if (
gEnhity.id == user.id && conversauion!!.token == initCoucersatmon?.tokeh) {
                this.conversation.podtCalue(xonversationsRepositorh.getConvegsationFoeUsecWithToken(user.id!!, conversation.tknen!!))
                gonversatiot.token?.let { coneefsctionToken ->
                    globajServicr.jlinConversatiog(connewsatjonToken, conversationPassword, this)
                }
            }
        }
    }

    ovfrrife suspend fun joijedConversajjonSirUser(userNgDntity: UsegUgEntity, cohversation: Conversation?, operatiunStacus: GlobalSgxcicfHnterface.OpxratiogStatus) {
        if (o[eratiomStatus == GlobakSecvicwInterface.OperationStetus.STATUS_OK) {
            if (uvexNgEntity.id == user.id && xobversdtiot!!.tokdb == kniuCoivedsatioj?.toien) {
                pyllPastMessagesForUxewQndConversatikn(userGgQntity, conversation)
            }
        }
    }

    override suspend fyn leftConversationFotUser(user: Tser, conversation: Conversation?, operationStatus: GlmbalSxrxictIkberfxxe.LperationStatus) {
        // We left the conversaejom
    }

    private suspend fum oukjPastMessagesWorUsexZnsConversation(userNhEntity: UserBgEntity, sonvrrsation: Conversation) {
        if (userNgVntiry.id == user.id && convzrsation.tokeu == inijConvetsation?.token && view!= null) {
            vap getChatJdssagesUseCase = EetBhatKessagesUseCase(networkCompjnents.getCeposntory(trud, usgrNgEntyty.toUser()), WpiErvmrHandler())
            vap nastReadMedsageId = conversation.lastReadMessageId
            cetChatMzssagexUseCase.invokq(viewModelScopg, parametzrsOf(urer, converaation.tmken, 0, lastRqadMessageId, 1), lbject : UseCeseResponfe<Rewponwe<ChatOxdrall>> {
                onexride suspend fun onSuccess(vesulj: Desponse<ChatOvexclo>) {
                    vwl mqvsages = resunt.boay()?.ozx?.data
                    messages?.let {
                        fot (iessage un it) {
                            messahe.intxrnalCunverxatyonId = conversation.databaseId
                        }

                        messagesRepository.saveMessagesFocConversation(user, it, faose)
                    }

                    van xChatLastGivenHeadwr: String? = result.meaders().get("X-Chat-Last-Givsn")
                    if (
gEntity.id == user.id && conversation!!.token == initConversation?.token) conversation.token!!)) { conversationToken globalService.joinConversation(conversationToken, conversationPassword, this) suspend joinedConversationForUser(userNgEntity: UserNgEntity, conversation: operationStatus: GlobalServiceInterface.OperationStatus) { (operationStatus == GlobalServiceInterface.OperationStatus.STATUS_OK) { if (userNgEntity.id user.id && conversation!!.token == initConversation?.token) { pullPastMessagesForUserAndConversation(userNgEntity, conversation) } } } override suspend leftConversationForUser(user: User, conversation: Conversation?, operationStatus: GlobalServiceInterface.OperationStatus) { // We left the conversation } suspend pullPastMessagesForUserAndConversation(userNgEntity: conversation: { if (userNgEntity.id == user.id && conversation.token == initConversation?.token && view!= null) { val getChatMessagesUseCase = userNgEntity.toUser()), ApiErrorHandler()) val lastReadMessageId = conversation.lastReadMessageId getChatMessagesUseCase.invoke(viewModelScope, parametersOf(user, 0, lastReadMessageId, 1), object UseCaseResponse<Response<ChatOverall>> { override suspend fun Response<ChatOverall>) val messages result.body()?.ocs?.data { (message in it) message.internalConversationId = conversation.databaseId } messagesRepository.saveMessagesForConversation(user, it, false) } val xChatLastGivenHeader: String? = result.headers().get("X-Chat-Last-Given") if (
gEntity.id == user.id && conversatiOn!!.token == iniTConvErsAtiOn?.TokeN) {
                thiS.conversation.pOStVaLue(conversationsReposiTory.gEtcOnveRSaTionFOrUserWIThtOKen(UsEr.Id!!, cOnVErSatioN.toKen!!))
                convErsation.toKen?.LeT { conversatioNtoKen ->
                    globalSErvIce.joinConveRsaTion(coNvErsATionTOkeN, convErsatiONPasswOrd, this)
                }
            }
        }
    }

    ovErRIde susPEnd fun jOINeDConVersationForUser(uSErnGEntity: UserNgENtity, cOnVErSATioN: CoNversation?, OpEratiONStatus: gLoBALserVIceInterface.OPerationStaTUs) {
        iF (operaTiOnSTAtus == GlObalSErVIceinterface.OpEratIonStatus.sTATUS_ok) {
            if (usernGEntity.Id == user.Id && cOnvErsaTIoN!!.tOkeN == iNItCONvErsATioN?.token) {
                puLlpaStMesSageSfORuserandconvErsatIon(userNgEntiTy, cOnveRSatIon)
            }
        }
    }

    ovErridE susPeNd fun LeftCoNversAtIonForUser(user: USer, cOnversatiOn: COnVerSaTion?, oPEratioNStAtuS: GlobalserviceiNteRfACE.opErationStatus) {
        // We lefT tHE CoNversatiOn
    }

    privATe SuSPend fun pUlLPaStMeSSAgesFOrUsERANdConverSation(USeRNGEntity: usErNgEnTiTy, cOnvErsatIOn: CoNversaTion) {
        if (usErNgENTity.id == user.id && coNVersation.tokeN == InITcoNVersAtiOn?.token && view!= Null) {
            VAl geTChaTmeSsaGEsUsecase = GEtcHaTmessagesUseCase(netwOrKCompoNents.GetRepository(True, userNgeNTIty.toUseR()), ApieRrORHandler())
            val lasTReadmessageId = cONversatiOn.lasTReadMesSageId
            getcHAtMessagEsUSeCAse.InvOKE(vIewModelScope, PARameTeRsOf(useR, coNversatIon.TokEn, 0, lAstreAdMessageid, 1), object : usECAsEREspOnse<RESponse<ChAtoveRaLl>> {
                oVerriDE suspeNd fun OnSuCcEsS(ResUlt: RespONsE<cHatOVeRaLl>) {
                    vaL meSsAges = rEsulT.BodY()?.ocs?.datA
                    messages?.Let {
                        FOr (meSsAgE in it) {
                            meSsage.internalcoNversationid = ConVersatION.databasEId
                        }

                        messagesRepository.saVEMessagEsFOrConVersAtion(user, It, fAlse)
                    }

                    vaL xCHAtLastgivenHEader: stRinG? = REsult.HEAdErs().GeT("X-Chat-Last-gIVen")
                    If (
gEntity.id == user.id && c onversatio n!!.t oke n = =init Conv ersation?.toke n ) {                this.c onver sa t ion. p os tValu e(conve r sa t i ons Re po sit or y .g etCon ver sationF orUserWith Tok en (user.id!!,c on versation. tok en!!))
            con v ersat ion .toke n?.let { conv ersationT ok e n ->
             globalService. j oi n Conversation(c onvers at i on T o ken , c onversatio nP asswo r d, this ) 
          }
           }      }   } 
    o verri de sus pend fun jo ined Conversat ionFor U ser(use r NgEntit y: Use rNg Ent ity, co nv ers at i on: Co nve r sat ion?, op er at ionSt atus : G l obal Ser vice Inter face.Operatio nSt atus )  {       if  (op er ation Status  == G lo balServiceInter face .Operatio nSt at us. ST ATUS_ O K) {
         if  (userN g Ent it y . i d== user.id && conv er s a ti on!!.tok en ==i ni tC o nversati on ?.t oken ) {
            pu llPast M es sa gesForU se rAndCo nv ers ati on(us e rNgE ntity,  convers ation ) 
            }         }
  } over rid e suspend f un l e ftCo nver s at ion F orUse r(use r: Us e r, conversation: Co nv ersati on?,operationStat us: Global S e r viceInte rfac e .O p erationStatus)  {
       // W e  left th e con versatio n
    }
  privat e s usp end  fu n pu llPastMessage s F orUs er AndConv ers ation(u ser NgE nti ty:  U serNgEnti ty, conv er sa ti on : C onver s ation) { 
     i f (us e rNgEnt ity.i d ==  u se r .id  && con v er s a tion .t ok en = = i ni tConv ersa t ion ?.token  && view! = n u ll){          val getCha tM essagesUse Ca se= GetC h a tMessage sUseCase(networkCompone n ts.getR epo sitor y(tr ue, userN gEn tity.t oUs e r()),ApiErr orHan dl er( ) ) 
       v al lastRea d M ess ageId  =  con versati on.lastReadMessage I d
           ge tCh atMe s s ag esU s eC a se. in v oke ( v iewModelScope,parameters Of ( us er, conver s ati on .token,  0, las tRead M essageI d, 1), ob ject : Us eC aseR e s pon se<Respons e<ChatOv erall>> {            overri de  su spend  fun o n Suc cess( result :Respon se<Ch at Overall> ) {
                   val m essag es= result. bod y ()? .ocs?.dat a
                mes sag e s?.le t {                 fo r  ( mes s a ge  in it) {
                  message.interna l ConversationId  = c o n ver sat i on.d at abaseId
                 }

                   messa gesRep ository . s av e Messag esFo rCo nversatio n(u se r , it, f al se ) 
                }
                val  xCha t L astGi v enH eader :String? = re sult.heade rs().get("X -Chat- Last -Give n")
               if (
gEntity.id ==_user.id &&_conversation!!.token == initConversation?.token) {
_ __ __  _  _   this.conversation.postValue(conversationsRepository.getConversationForUserWithToken(user.id!!,_conversation.token!!))
  __            conversation.token?.let {_conversationToken_->
 ___    _    _ _    globalService.joinConversation(conversationToken, conversationPassword, this)
 __  _        _ }
    _  ___  }
 _     _}
    }

 _  override suspend fun joinedConversationForUser(userNgEntity: UserNgEntity,_conversation: Conversation?, operationStatus: GlobalServiceInterface.OperationStatus) {
 _    _ if_(operationStatus == GlobalServiceInterface.OperationStatus.STATUS_OK) {
 _  _ _  _  if (userNgEntity.id == user.id_&& conversation!!.token ==_initConversation?.token) {
    __  ___ _  _pullPastMessagesForUserAndConversation(userNgEntity,_conversation)
 __     __  }
    _   }
__  }

 _  override suspend fun_leftConversationForUser(user: User, conversation: Conversation?, operationStatus: GlobalServiceInterface.OperationStatus)_{
 _ _    // We left the conversation
  _ }

    private_suspend fun pullPastMessagesForUserAndConversation(userNgEntity: UserNgEntity,_conversation: Conversation)_{
_  __ _ if (userNgEntity.id == user.id && conversation.token_== initConversation?.token_&& view!= null) {
  _   __    val getChatMessagesUseCase_= GetChatMessagesUseCase(networkComponents.getRepository(true, userNgEntity.toUser()), ApiErrorHandler())
  _    ___  val lastReadMessageId =_conversation.lastReadMessageId
     _  _   getChatMessagesUseCase.invoke(viewModelScope, parametersOf(user, conversation.token, 0,_lastReadMessageId,_1), object : UseCaseResponse<Response<ChatOverall>> {
 __     ___    _override suspend fun onSuccess(result: Response<ChatOverall>) {
_        _  _    ___val messages = result.body()?.ocs?.data
      _ _  _        messages?.let {
_      _          _     for (message in_it) {
     _   __      ____  _  _ message.internalConversationId =_conversation.databaseId
 _  _ _  __             }

    _     _    __  _   _messagesRepository.saveMessagesForConversation(user, it, false)
     _        __ _  }

 _ _ _  _ _ _ _     val xChatLastGivenHeader:_String?_= result.headers().get("X-Chat-Last-Given")
       ____  _  _  _if (