leegeunhyeok / react-native-zendesk-messaging

🗣️ Zendesk messaging SDK for React Native
https://www.npmjs.com/package/react-native-zendesk-messaging
MIT License
39 stars 11 forks source link

Close conversation screen #35

Open Esteban-ortega-roy opened 11 months ago

Esteban-ortega-roy commented 11 months ago

This is not a bug but a question:

Context: If the app is sent to background and opened it again X minutes later, the user has to authenticate/login again, just like most baking apps.

Problem: If the conversation was opened before the app was sent to background, when the app comes to foreground again, the conversation is visible.

Goal: Programmatically close the conversation when the app is sent to background.

I've tried using "reset" to invalidate the instance but that only makes the conversation unresponsive (can't send messages) but it is still visible/readable.

leegeunhyeok commented 11 months ago

Hi, @Esteban-ortega-roy.

Esteban-ortega-roy commented 11 months ago

Thank you for your answer @leegeunhyeok

A2. iOS: need to implement bridge method for call from js runtime / Android isn't possible because we can't access to the conversation activity.

Yes, that's what I tried using this example repo: bridge + native code to rootController.dimiss. It seems to work

A1. No, the Zendesk SDK does not implement the feature to close conversation view.

I have an open ticket with Zendesk talking about this. So far the only workaround they gave me is what we've discussed above about iOS, I'm still waiting for workaround for Android. I also asked them if it would be possible that they include this feature in their SDKs, for me it makes sense to have a ".closeMessaging", just as they have ".showMessaging".

I'll update this ticket with the information I got from them, just in case it helps to someone else.

leegeunhyeok commented 11 months ago

Thanks! I'll follow up too.

pwfcurry commented 9 months ago

Hi @leegeunhyeok thank you for creating this package! Did you or @Esteban-ortega-roy hear back from Zendesk?

Esteban-ortega-roy commented 9 months ago

@pwfcurry Not yet. I'm waiting for them to confirm if something like ".closeMessaging" is in their roadmap. As soon as I know something else I'll post it here

mfds commented 8 months ago

Hi! Here's what we did to handle the "closeMessaging" behaviour on Android

Unfortunately, having a "closeMessagingView" method might not be the best solution here as that would require the activity to run/call that code. Zendesk chat runs on a separate Activity, so we need to work around that.

We have a similar use case where the application needs to close the chat window if the app has been in background for too long.

Having tried a few things, we eventually settled for a new custom native module that listens to the Activity changes:

class ActivityLifecycleListener : Application.ActivityLifecycleCallbacks {
  override fun onActivityResumed(activity: Activity) {
    if (activity.javaClass.simpleName != "MainActivity" && areConditionsMet()) {
      activity.finish()
    }
    trackActivityResumed(activity.javaClass.simpleName);  
  }

  override fun onActivityStopped(activity: Activity) {
      trackActivityStopped(activity.javaClass.simpleName);  
  }

(just an example with the gist of what we did, this is not actual code). Remember to override all methods within this public interface.

Last thing to do is to register the listener. Expo native modules can call a method on module creation that has access to appContext so you can do things like:

private fun registerLifecycleListener() {
  val applicationContext = appContext.reactContext?.applicationContext as? Application
  applicationContext?.registerActivityLifecycleCallbacks(ActivityLifecycleListener())
}

(so you would call this within the OnCreate method)

or, if you're patching the react-native-zendesk-messaging package (e.g. using patch-package) you can use init on the ZendeskMessagingModule class like so:

init {
  val applicationContext = reactContext.applicationContext as? Application
  applicationContext?.registerActivityLifecycleCallbacks(ActivityLifecycleListener())
}

Hope this helps!