I've integrated Firebase into my app. I can authenticate with Firebase via email/password. Then I initialize the ChatSDK and call InterfaceManager.shared().a.startLoginActivity(this,true);
From there, the app is "taken over" by the default chat user interface and the functionality works great and ChatSDK.currentUser()
returns the expected User
object.
I would like to do the same thing with my own UI. To authenticate a user after ChatSDK initialization, I've tried:
ChatSDK.auth().authenticateWithCachedToken();
ChatSDK.auth().authenticate(AccountDetails.signUp(email,pwd));
ChatSDK.auth().authenticate(AccountDetails.username(email,pwd));
It is my understanding that I wouldn't be able to do ChatSDK.thread().createThread(...)
until I have a valid User
. However, after each authentication attempt, ChatSDK.currentUser()
is null
.
Looking at the ChatSDK source code and documentation, it appears this is the mechanism for authentication. Is there something I'm missing?
答案 0 :(得分:0)
ChatSDK.auth()
.authenticateWithCachedToken()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action() {
@Override
public void run() throws Exception {
Log.d("Success","We're in!");
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
Log.d("Err",throwable.toString());
}
});
此外,这是一些代码,用于使用已知的用户ID启动新的聊天线程。
UserWrapper userWrapper = UserWrapper.initWithEntityId(firebaseUser.uid);
userWrapper.metaOn();
userWrapper.onlineOn();
User otherUser = userWrapper.getModel();
ProgressDialog pd = new ProgressDialog(MainActivity.this);
pd.show();
ChatSDK.thread().createThread("", otherUser, ChatSDK.currentUser())
.observeOn(AndroidSchedulers.mainThread())
.doFinally(() -> {
pd.dismiss();
})
.subscribe(thread -> {
ChatSDK.ui().startChatActivityForID(getApplicationContext(), thread.getEntityID());
}, throwable -> {
ToastHelper.show(getApplicationContext(), throwable.getLocalizedMessage());
});