chat-sdk-android
chat-sdk-android copied to clipboard
Threads aren't appearing immediately after authentication
-
Is the bug present in the demo Chat SDK project? no, but demo opens another activity (
MainAppBarActivity) after authentication (SplashScreenActivityorLoginActivity), and mb because of this delay between switching activities the bug isn't reproduced, and all it asks for permission before displaying threads, my sample uses the same activity, everything happens fast, after authentication it immediately callssafeReloadDatamethod onPrivateThreadsFragment -
What modifications have you made to the Chat SDK? Used one activity for authentication and adding
PrivateThreadsFragmentin that activity -
Android Version: Any, e.g. API 30
-
Steps taken to reproduce the problem: after authentication
ChatSDK.auth().authenticate(details)in rx callbacksubscribemethod try to callfragment.safeReloadData()method immediately -
Expected result: chat private threads should have been appeared
-
Actual result: nothing appeared
-
Comments: only appears if you call
fragment.safeReloadData()method with some delay, e.g. 1 second aftersubscribemethod was called
Full Code:
class MainActivityTest : AppCompatActivity() {
private var authenticationDisposable: Disposable? = null
private lateinit var fragment: PrivateThreadsFragment
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
fragment = openPrivateThreadsFragment()
if (ChatSDK.auth().isAuthenticatedThisSession) {
// do nothing
} else if (ChatSDK.auth().isAuthenticated || ChatSDK.auth().isAuthenticating) {
authenticationDisposable = ChatSDK.auth().authenticate()
.observeOn(RX.main())
.subscribe(
{ fragment.safeReloadData() },
{ Log.i(TAG, "authenticate error $it") }
)
} else {
val details = AccountDetails.username("[email protected]", "testtest")
authenticationDisposable = ChatSDK.auth().authenticate(details)
.observeOn(RX.main())
.subscribe(
{
fragment.safeReloadData() // - TODO: WON'T WORK, WHY?
// TODO: some bug on first authentication, we need to put delay otherwise nothing will be updated
// Handler(Looper.getMainLooper()).postDelayed( {
// fragment.safeReloadData()
// }, 2000L)
Log.i(TAG, "authenticate ok ${ChatSDK.auth().isAuthenticated}")
},
{ Log.i(TAG, "authenticate error $it") }
)
}
}
override fun onResume() {
super.onResume()
fragment.safeReloadData()
}
override fun onDestroy() {
authenticationDisposable?.dispose()
super.onDestroy()
}
private fun openPrivateThreadsFragment(): PrivateThreadsFragment {
val fragmentManager = supportFragmentManager
val transaction = fragmentManager.beginTransaction()
var fragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG) as PrivateThreadsFragment?
if (fragment == null) {
fragment = PrivateThreadsFragment()
transaction.replace(R.id.frame_layout, fragment,FRAGMENT_TAG)
} else {
transaction.show(fragment)
}
transaction.commit()
return fragment
}
companion object {
private const val TAG: String = "TEST_AUTHENTICATION"
private val FRAGMENT_TAG: String = PrivateThreadsFragment::class.java.name
}
}
SDK init:
class App : Application() {
override fun onCreate() {
super.onCreate()
ChatSDKFirebase.quickStart(
this,
"pre_1",
"",
true
)
}
}
So threads are appearing only after calling safeReloadData method with delay or after this app with that activity launched the next time (when a user is authenticated already)

Sometimes it displays part of information only (only 1 item of 2, and no name of user):

Is there some synchronization happens after authentication (to local datebase for example)?
but everything works ok after launching the app again when user is already authenticated
also Log.i(TAG, "authenticate ok ${ChatSDK.auth().isAuthenticated}") isn't being called until you post it to main handler
I have that same issue