Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V6] StreamOfflinePluginFactory was set at initialization, but the sdk required it #4717

Closed
workspace opened this issue Mar 10, 2023 · 8 comments
Assignees
Labels
bug Something isn't working sdk-issue Used for issues/bugs opened/reported by customers or us.

Comments

@workspace
Copy link
Contributor

workspace commented Mar 10, 2023

Describe the bug
I am initializing ChatClient using jetpack app startup library. After completely shutting down the app, clicking the push notification to run the app, and then calling the state-related method(ex. watchChannelAsState), the following exception appears.

It could be a problem with our app's implementation, but we had no issues with v5.

FATAL EXCEPTION: main
Process: com.tntcrowd.educast, PID: 23369
java.lang.IllegalArgumentException: Offline plugin must be configured in ChatClient. You must provide StreamOfflinePluginFactory as a PluginFactory to be able to use LogicRegistry and StateRegistry from the SDK
	at io.getstream.chat.android.state.plugin.state.StateRegistry$Companion.get$stream_chat_android_state_release(StateRegistry.kt:200)
	at io.getstream.chat.android.state.extensions.ChatClientExtensions.getState(ChatClient.kt:66)
	at io.getstream.chat.android.state.extensions.internal.ChatClientKt.requestsAsState(ChatClient.kt:40)
	at io.getstream.chat.android.state.extensions.ChatClientExtensions$watchChannelAsState$1.invoke(ChatClient.kt:128)
	at io.getstream.chat.android.state.extensions.ChatClientExtensions$watchChannelAsState$1.invoke(ChatClient.kt:127)
	at io.getstream.chat.android.state.extensions.ChatClientExtensions$getStateOrNull$$inlined$map$2$2.emit(Emitters.kt:227)
	at kotlinx.coroutines.flow.DistinctFlowImpl$collect$2.emit(Distinct.kt:81)
	at io.getstream.chat.android.state.extensions.ChatClientExtensions$getStateOrNull$$inlined$map$1$2.emit(Emitters.kt:223)
	at kotlinx.coroutines.flow.StateFlowImpl.collect(StateFlow.kt:398)
	at kotlinx.coroutines.flow.StateFlowImpl$collect$1.invokeSuspend(Unknown Source:15)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:226)
	at android.os.Looper.loop(Looper.java:313)
	at android.app.ActivityThread.main(ActivityThread.java:8747)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
	Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@11319a, Dispatchers.Main.immediate]

ChatClient initialization and connection was completed before calling watchChannelAsState
image

SDK version

  • 6.0.0-beta2
  • androidx startup 1.1.1

To Reproduce
(With our implementation)

  1. initialize ChatClient with Jetpack App Startup library.
  2. close app
  3. receive and click notification
  4. crash!

I'll try to reproduce with stream-chat-android sample

Expected behavior
in v5, there was no problem.

Device:

  • Vendor and model: Samsung Galaxy S23 Ultra
  • Android version: 13
@workspace workspace added the bug Something isn't working label Mar 10, 2023
@leandroBorgesFerreira
Copy link
Contributor

Hello @workspace, could you share how you're initializing our SDK? I believe you didn't add the state plugin.

@workspace
Copy link
Contributor Author

workspace commented Mar 12, 2023

Hello @workspace, could you share how you're initializing our SDK? I believe you didn't add the state plugin.

StreamChatInitializer

class StreamChatInitializer : Initializer<Unit> {

    override fun create(context: Context) {
        // Set up the OfflinePlugin for offline storage
       val offlinePluginFactory = StreamOfflinePluginFactory(
            appContext = context
        )
        val statePluginFactory = StreamStatePluginFactory(
            config = StatePluginConfig(
                backgroundSyncEnabled = true,
                userPresence = true
            ),
            appContext = context
        )

        // Set up the client for API calls with the plugin for offline storage
        ChatClient.Builder("stream key", context)
            .logLevel(
                if (BuildConfig.DEBUG) {
                    ChatLogLevel.DEBUG
                } else {
                    ChatLogLevel.NOTHING
                }
            )
            .withPlugin(offlinePluginFactory, statePluginFactory )
            .build()
    }

    override fun dependencies(): List<Class<out Initializer<*>>> = emptyList()
}

AndroidManifest.xml

<manifest>
  <application>
    <provider
            android:name="androidx.startup.InitializationProvider"
            android:authorities="${applicationId}.androidx-startup"
            android:exported="false"
            tools:node="merge">
            ...
            <meta-data
                android:name="com.holix.android.startup.StreamChatInitializer"
                android:value="androidx.startup" />
        </provider>
  </application>
</manifest>

image

This capture is a diff of a pull request that tested applying v6. If I open it by tapping the app icon, it works fine. However, there is a problem when opening the app through push notifications.

@filbabic filbabic added the sdk-issue Used for issues/bugs opened/reported by customers or us. label Mar 14, 2023
@MarinTolic MarinTolic added this to the Android v6 Release prep milestone Mar 14, 2023
@JcMinarro JcMinarro mentioned this issue Mar 15, 2023
16 tasks
@JcMinarro JcMinarro self-assigned this Mar 15, 2023
@JcMinarro
Copy link
Member

Hi @workspace
How are you connecting the user?
Are you waiting for the result of the call?

If you are using connectUser(user, token).enqueue(), are you passing a callback for the result? Or are you ignoring the result and moving directly to the chat?

@workspace
Copy link
Contributor Author

workspace commented Mar 16, 2023

ignoring the result and moving directly to the chat.Then, I am watching initializationState before using ChatClient in the screen.

@JcMinarro
Copy link
Member

Thanks for your reply.
It helps me to understand the a little bit better the problem and find a bug we introduced with the new approach.
It will be fixed soon

@workspace
Copy link
Contributor Author

Thanks for the quick fix, I'm really happy to have contributed to stabilizing the STREAM V6 SDK. I can't wait to get the STREAM V6 SDK into my product. 😃

@workspace
Copy link
Contributor Author

@JcMinarro
I've verified that this snapshot build resolved the issue, I think we can close this issue.

@Xshooter26
Copy link

@workspace @JcMinarro Thanks bro this helped me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sdk-issue Used for issues/bugs opened/reported by customers or us.
Projects
Status: Merged
Development

No branches or pull requests

6 participants