parley-messaging / android-library

Parley Android app library
MIT License
3 stars 3 forks source link

Added option not to resend pending messages on triggerRefreshOnConnected #55

Closed mennovogel closed 3 weeks ago

mennovogel commented 3 weeks ago

By adding the option not to resend pending messages when triggerRefreshOnConnected is called we fix a bug that results in duplicate messages being send.

This can be reproduced if you call Parley.getInstance().triggerRefreshOnConnected(); at the same that a message is being send. It's easy to reproduce this if you add this code to ChatActivity.java and send a few messages in the demo project:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat);

        setupToolbar();

        parleyView = findViewById(R.id.parley_view);

        refreshDelayed();

        setParleyViewSettings();
    }

    private void refreshDelayed() {
        new Handler(Looper.myLooper()).postDelayed(new Runnable() {
            @Override
            public void run() {
                Parley.getInstance().triggerRefreshOnConnected(true);
                refreshDelayed();
            }
        }, 150);
    }

Also check out this video:

https://github.com/parley-messaging/android-library/assets/2795333/c1870b52-8c1c-4a9b-b2bd-f8722dc7d86d

With this fix we can call Parley.getInstance().triggerRefreshOnConnected(false); to prevent the duplicate messages.

Note: The solution could maybe be resolved in a better way. For example by adding another Message status type, like SEND_STATUS_SENDING, but this would be a larger refactor and I'm not sure if I can test all cases.

mennovogel commented 3 weeks ago

Thanks for merging this,

Could you do another version bump please? We would like this last change before we go live with chat next week.

Kind regards,

Menno

alexkok commented 3 weeks ago

Yeah, was on it, it was building until now 🙂

Released in 3.9.6 🚀