Duplicate messages sent with Android SDK

Respondida

13 Comentarios

  • Killian Smith

    Hi Romain, 

    Since this post is related to the the SDK, in future you should post them here, in the developer community. It might be a good idea to move the post to that community also, to be on the safe side. However we are currently looking into this issue.. We have reports that updating to 1.4.1, has fixed this issue for some of our integrators. Could you update and let me know if the issue persists? 

    Thanks in advance,

    Killian

    0
  • Leo Droidcoder

    Having the same issue.

    Updating to 1.4.1 didn't solve it.

    We are using ZopimChatFragment, Android 8.0.

    Once the chat is initially started, messages are not duplicated.

    After quitting and resuming the chat, a user sees duplicated outcoming messages. If the user leaves chat and returns again - previous messages are shown not duplicated, but newly sent will be.

    Thus, seems the only one message is being actually sent, but once user presses "send" button, the first item is already added to the adapter, and the second one is added when it is received wrom sockets

    0
  • Leo Droidcoder
    ZopimChatLogFragment.ChatObserver.updateChatItems()
    gots triggered several times.
    Firstly with one new item in TreeMap<String, RowItem> models,
    then another item gots added:


    At a first sight, the duplicated items have different Id's, timeStamps and
    one is unverified=false, whilst the other is unverified=true.
    Then these items are judst got rendered by the adapter
    0
  • Jessie Schutz

    Hi Leo!

    I'm sorry for the delay in getting a response on this for you. I'm tracking down the right person to help you out.

    0
  • Jessie Schutz

    Hey Leo!

    Just a quick update for you. The person who can answer this question for you is on vacation through the end of this. I'll touch base with them on Monday when they're back in the office!

    0
  • Leo Droidcoder

    Thank you! Looking forward to an answer

    0
  • Sebastian Chlan

    Hey,

    It can be a bit tricky to implement the ZopimChatFragment by its own. We've seen similar issues with duplicated messages before when someones tried to embed it into their own activity.
    For that reason can you share the code that integrates and interacts with the ZopimChatFragment?

    Thanks,
    Sebastian

     

    0
  • Leo Droidcoder

    Hi Sebastian,

    please find the code

    I am using 

    com.zopim.android:sdk:1.4.1

    Here is the fragment, where I use ZopimChatFragment

    class ChatFragment : MvvmFragment<ChatViewModel>() {

    override fun getViewModelType() = ChatViewModel::class.java
    override fun getLayoutResource() = R.layout.fragment_chat

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    showZopimChatFragment()
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp)
    toolbar.setNavigationOnClickListener { activity?.onBackPressed() }
    tvLanguage.setOnClickListener { viewModel.onLanguagesClick() }
    }

    override fun bind(viewModel: ChatViewModel) {
    viewModel.departmentLiveData.observe(this, Observer {
    it?.run { tvLanguage.text = it }
    })
    }

    private fun showZopimChatFragment() {
    activity?.run {
    if (!ZopimChat.resume(this).hasEnded()) {
    resumeChat()
    } else {
    showNew()
    }
    }
    }

    private fun resumeChat() {
    val manager = childFragmentManager
    // find the retained fragment
    if (manager.findFragmentByTag(ZopimChatLogFragment::class.java.name) == null) {
    val chatLogFragment = ZopimChatLogFragment()
    val transaction = manager.beginTransaction()
    transaction.add(com.zopim.android.sdk.R.id.chat_fragment_container, chatLogFragment, ZopimChatLogFragment::class.java.name)
    transaction.commit()
    }
    }

    private fun showNew() {
    // prepare chat fragment
    val fragment = ZopimChatFragment()
    // show fragment
    val manager = childFragmentManager
    val transaction = manager.beginTransaction()
    transaction.replace(R.id.chat_fragment_container, fragment, ZopimChatFragment::class.java.name)
    transaction.commit()
    }
    }

     

    And here is the activity, which hosts ChatFragment

    class ChatContainerActivity : MvvmRoutingActivity<ChatContainerViewModel>(), ChatListener {

    override fun getViewModelType() = ChatContainerViewModel::class.java
    override fun getLayoutResource() = R.layout.activity_chat

    override fun onBackPressed() {
    val id = navController.currentDestination?.id
    if (id == R.id.fragment_chat || id == R.id.fragment_intro || !navController.navigateUp()) {
    // close screen but not end chat
    finish()
    }
    }

    override fun bind(viewModel: ChatContainerViewModel) {
    viewModel.restartChatLiveData.observe(this, Observer {
    //restart chat with a new department
    it?.run { restartChat(it) }
    })
    }

    /**
    * Finishes current and restarts chat with a new department
    */
    private fun restartChat(dept: String) {
    ZopimChat.resume(this).endChat()
    finish()
    start(this, chatData.apply { department = dept })
    }

    override fun onChatLoaded(chat: Chat?) {
    L.log("ChatContainerActivity", "onChatLoaded:")
    }

    override fun onChatInitialized() {
    L.log("ChatContainerActivity", "onChatInitialized: ")
    }

    override fun onChatEnded() {
    L.log("ChatContainerActivity", "onChatEnded: ")
    }

    companion object {
    private lateinit var chatData: ChatData

    fun start(activity: FragmentActivity, data: ChatData) {
    checkNotNull(data.accountKey)
    chatData = data
    // initialize chat and set department
    ZopimChat.init(data.accountKey).department(data.department)
    // set visitor info
    ZopimChat.setVisitorInfo(VisitorInfo.Builder()
    .phoneNumber(data.phoneNumber)
    .email(data.email)
    .build()
    )
    val intent = Intent(activity, ChatContainerActivity::class.java)
    activity.startActivity(intent)
    }
    }
    }

     

    0
  • Leo Droidcoder

    The bug is exactly reproduced in the following scenario:

    1. Instantiate ChatContainerActivity with
      fun start(activity: FragmentActivity, data: ChatData) 
    2. Instantiate The ChatFragment. As it is the first launch, ZopimChatFragment will be instantiated with
      showNew()
    3. Start chat and destroy the Activity (call finish() or onBackPressed()). Note that we do not let user to end the chat session.
    4. Start the ChatContainerActivity again same as in clause 1.
    5. This time ChatFragment will do resumeChat(). So far so good, no duplicated messages.
    6. Restart the activity with department change with calling restartChat() of the Activity. It should end the current chat, set new department and restart the ChatContainerActivity (with calling the same method as in clause 1)
    7. The outgoing messages are getting duplicated on the client side.
    8. If you finish the activity and resume current chat again - duplicated messages are not shown neither are they shown in the console. Thus They are not getting sent but are just shown
    9. In some caces you mightr need to repeat the following steps

    Hope it helps to reproduce the issue and find a solution

     

     

     

     

     

     

     

    0
  • Max Brunner

    Hi Leo,

    This thread got lost here. Are you still experiencing this issue?

    Thanks,
    Max.

    0
  • Daniel Satya

    I have same problem

    If I start new chat session, everything is normal,, but if I put my phone on sleep mode, wait for 5 minutes, open my phone again, the chat room is reconnecting,, after that, every message I send will be double, same as picture above

     

    0
  • Richard Bridge

    Hi Daniel/Leo/Anyone else who has experienced this!

    Sorry for another delay in replying, our engineering team were largely unavailable last week, so we're only getting to this now. The good news is that we think your issue has been solved! We have just released 1.4.4 of the Chat SDK, and it should be available for you to use now. We are currently working on the documentation which should be available shortly, but you can use the new version right away. I believe your issue has been fixed in this version, so if you can check it out and let us know if it works for you.

    Hoping this helps you, and apologies for the delays you've seen!

    Richard

    0
  • Brendan Fahy

    Hi Leo,

    Are you saying you're still seeing this problem on version 1.4.4 that Richard pointed to?

    0

Iniciar sesión para dejar un comentario.

Tecnología de Zendesk