livechat / chat-window-android

LiveChat mobile chat window for Android
https://developers.livechatinc.com/mobile/android/
MIT License
23 stars 28 forks source link

Force closing a chat #17

Closed ilya-rb closed 3 years ago

ilya-rb commented 5 years ago

Hi, i there any legal way to force close the chat view Android LiveChat SDK. Like in Javascript Widget API https://developers.livechatinc.com/docs/js-api/#close-chat

I have an issue in app when user starts a chat, logs out and then logs in as another user open a new chat, previous chat from previous user persists.

anninosk commented 4 years ago

Same here

nomyzs commented 3 years ago

Hello @ilya-rb and @anninosk Thanks for reporting this and apologies for late response!

We are using our js Chat Window rendered in android WebView, which in turns handles session and stores that information in local storage. From my tests you need to clear webStorage data and cookies like so:

public void clearSession() {
    WebStorage.getInstance().deleteAllData();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(webView.getContext());
        cookieSyncMngr.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }
}

In case when ChatWindowView is attached in course of the log out flow, you going to also need to reload it by calling chatWindow.reload(); after clearSession code.

I would appreciate any feedback if that helps. If so I will update docs and provide expose this convent method in next version.

nomyzs commented 3 years ago

Added with v2.1.4 release