Closed ezet closed 3 years ago
Another approach could be to provide an API that lets us easily disable and enable notification handling as required. That way we could call this API based on the lifecycle state of certain activities. The use-case would be to disable push handling while certain activities are in the foreground, while enable them for others.
Hey @ezet, modifying the SDK to display notifications in the foreground is something that would be hard to achieve right now. This is also not guaranteed that we will receive notification
event when the web socket connection is active (while the app is in foreground). However, you can just simply subscribe to receive a "new message" events when the app is in foreground and display your notification manually:
ChatClient.subscribeFor(NewMessageEvent::class) {
// display notification here
}
Closing the issue now. @ezet, please let us know if you need any further help on our side.
Chat is only a minor part of our application, and new chat messages might not be immediately visible even if the app is running in the foreground. We therefore want to display chat messages even if the app has focus, or have more fine-grained control of when to handle push messages and not.
This means making changes in the 3 locations.
https://github.com/GetStream/stream-chat-android/blob/master/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/notifications/ChatNotifications.kt#L65 https://github.com/GetStream/stream-chat-android/blob/master/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/notifications/ChatNotifications.kt#L75
In the above two locations, the
isForeground()
check could be moved inside thehandler.onChatEvent()
andhandler.onFirebaseMessage()
methods, which already provides an an open interface. The default implementation could bereturn isForeground()
which would abort the push notification when the app is in the foreground.The last check here https://github.com/GetStream/stream-chat-android/blob/master/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/notifications/ChatNotifications.kt#L155 doesn't have an equally simple solution, but I guess it could also delegate the check to a possibly new method in the
ChatNotificationHandler
implementation.