Scarlet icon indicating copy to clipboard operation
Scarlet copied to clipboard

How to subscribe to similar entities

Open abbath0767 opened this issue 6 years ago • 3 comments

v. 0.2.1-alpha4 There is a basic entity of the socket response that differs in the content of the data field and the value of the endpoint field. For example. First is a payment structure:

{
  "endpoint": "updates.payments", 
  "data": {
    "payments": [
      {
        "payment_status": "success",
        //...other fields...
        "currency": {
          "decimal_places": 2,
          "currency_code": "GBP",
          "currency_name": "UK Sterling"
        }
      }
    ]
  }
}

And message structure:

{
  "endpoint": "updates.messages", 
  "data": {
    "messages": [
      {
        "message_status": "send_success",
        //other fields
        "text":"blah blag blah"
      }
    ]
  }
}

In SocketInterface i have next code:

interface SocketInterface {

    @Receive
    fun subscribeToMessages(): Flowable<PushMessage<MessagesData>>

    @Receive
    fun subscribeToPayments(): Flowable<PushMessage<PaymentData>>
}

And PushMessage model see this:

data class PushMessage<T>(
        @SerializedName("endpoint") val method: String,
        @SerializedName("data") val data: T
)

data class MessagesData(
        @SerializedName("messages") val messages: List<ChatMessage>
)

data class PaymentData(
        @SerializedName("payments") val payments: List<BaseTransactionNet>
)

By subscribing to both events, I receive two events if I receive one of them. Is there any way to fix it?

abbath0767 avatar Feb 14 '19 11:02 abbath0767

Sounds similar to https://github.com/Tinder/Scarlet/issues/37

sbearben avatar Feb 14 '19 16:02 sbearben

Yes, same. Sorry for duplicate. I found problem with message adapters, but I'm not sure it can fix this problem quickly and cheaply. At the moment, it was easier for me to define a custom TypeAdapter for my entity at T data in 5 line class, but it is not best solution. How to make it universal and scalable - I don't know, and not invented, but something will come up - I will write to you

abbath0767 avatar Feb 14 '19 16:02 abbath0767

abbath0767

Can you show how you solved your problem? I have a similar situation

boronov avatar Jul 07 '23 19:07 boronov