1

I am trying to implement the Pusher ChatKit from the SDK site: https://docs.pusher.com/chatkit. I prefer to keep my code entirely in Java.

In the examples, there is this code block:

chatManager.connect { result ->
  when (result) {
    is Result.Success -> {
      // We have connected!
      currentUser = result.value // CurrentUser
    }

    is Result.Failure -> {
      // Failure
      handleConnectionError(result.error)
    }
  }
}

However, the above code is written in Kotlin. In my own code, mCurrentUser is null even after the chatManager.connect method runs.

I upgraded my Android Studio to run Java 8 and I'm trying to use the following code:

                chatManager.connect(result -> {
                    if (result instanceof Result.Success) {
                        mCurrentUser = ((Result.Success<CurrentUser, Error>) result).getValue();
                    }
                    if (result instanceof Result.Failure) {
                        System.out.print(result);
                    }
                    return Unit.INSTANCE;
                });

When I step through using the debugger, the entire block is skipped. The connect methods logs a successful connection, but result is always null. Can someone either show me how to write the same callback using a listener? Or, show me the issue with my lambda expressions.

By the way, chatManager.connect takes Function1<? super Result<CurrentUser, Error> Unit> callback as a parameter. Thanks in advance. I've been stuck on this for 2 days.

0 Answers0