Just wanted to know if my understanding is correct...
# android
r
Just wanted to know if my understanding is correct here. I have this function which converts async call of library to rx and everytime the below function gets called it gives me a new single.
Copy code
internal fun sendChatMessage(message: String, guestId: String): Single<SosChatSentMessageReceipt> {
  return Single.create {
    val sosChatMessageSentReceipt = SosChatSentMessageReceipt(originalText = message, guestId = guestId)
    chatClient.sendChatMessage(message)
      .onResult { _, chatSentMessageReceipt ->
        if (chatSentMessageReceipt.isScrubbed) {
          sosChatMessageSentReceipt.deliveryStatus = DeliveryStatus.MODIFIED
        } else {
          sosChatMessageSentReceipt.deliveryStatus = DeliveryStatus.SUCCESS
        }
      }
      .onComplete { _ ->
        it.onSuccess(sosChatMessageSentReceipt)
      }
      .onError { _, throwable ->
        if (throwable is EmptyChatMessageException && throwable.triggeredSensitiveDataRules.isNotEmpty()) {
          sosChatMessageSentReceipt.deliveryStatus = DeliveryStatus.NOT_SENT_PRIVACY
        } else {
          sosChatMessageSentReceipt.deliveryStatus = DeliveryStatus.FAILED
        }
        if (!it.isDisposed) {
          it.onSuccess(sosChatMessageSentReceipt)
        }
      }.also { async ->
        it.setCancellable {
          async.cancel()
        }
      }
  }
}
This i use to send call the method above.
Copy code
internal fun sendMessage(chatMsg: ChatMessage.GuestMessage) {
    compositeDisposable += sendChatMessage(chatMsg.message, chatMsg.guestId)
      .subscribe({ chatSentMessageReceipt ->

      }, {
        logger.error(SosChatUIErrorTag.ChatSendMessageFailed, it)
      })
  }
So, my understanding here is, everytime i call sendMessage , it will create a new request by calling sendChatMessage and irrespective of any order the async call returns the sosChatMessageSentReceipt which is create in first function will be specific to that request and won't jumbled up with others.
stackoverflow 2