Last active
February 4, 2021 08:21
-
-
Save wajahatkarim3/e68158b39c73776a9ac798adc2d9aa15 to your computer and use it in GitHub Desktop.
CometChat Authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun createAndLoginCometUser(uid: String, name: String, isDoctor: Boolean) { | |
var cometUser = User() | |
cometUser.uid = uid | |
cometUser.name = name | |
var meta = JSONObject() | |
meta.put("isDoctor", isDoctor) | |
cometUser.metadata = meta | |
CometChat.createUser(cometUser, getString(R.string.auth_key), object : CometChat.CallbackListener<User>() { | |
override fun onSuccess(u: User?) { | |
Log.d("createUser", u.toString()); | |
CometChat.login(cometUser.uid, getString(R.string.auth_key), object : CometChat.CallbackListener<User>() { | |
override fun onSuccess(u: User?) { | |
if (u?.metadata?.has("isDoctor") == true && u.metadata?.getBoolean("isDoctor") == true) { | |
val i = Intent(applicationContext, DoctorMainActivity::class.java) | |
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) | |
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) | |
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | |
startActivity(i) | |
finish() | |
} | |
else { | |
val i = Intent(applicationContext, MainActivity::class.java) | |
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) | |
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) | |
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | |
startActivity(i) | |
finish() | |
} | |
} | |
override fun onError(ex: CometChatException?) { | |
Snackbar.make(bi.root, ex?.localizedMessage ?: "Couldn't login CometChat user", Snackbar.LENGTH_SHORT).show() | |
} | |
}) | |
} | |
override fun onError(ex: CometChatException?) { | |
Snackbar.make(bi.root, ex?.localizedMessage ?: "Couldn't create CometChat user", Snackbar.LENGTH_SHORT).show() | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment