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

Dismiss direct call notification when call is cancelled #909

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ public open class DefaultNotificationHandler(
.build()
}

override fun onCallCancelled(callId: StreamCallId) {
notificationManager.cancel(INCOMING_CALL_NOTIFICATION_ID)
}

private fun maybeCreateChannel(channelId: String, context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public interface NotificationHandler : NotificationPermissionHandler {
fun onNotification(callId: StreamCallId, callDisplayName: String)
fun onLiveCall(callId: StreamCallId, callDisplayName: String)
fun getOngoingCallNotification(callId: StreamCallId): Notification?
fun onCallCancelled(callId: StreamCallId)

companion object {
const val ACTION_NOTIFICATION = "io.getstream.video.android.action.NOTIFICATION"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal object NoOpNotificationHandler : NotificationHandler {
override fun onNotification(callId: StreamCallId, callDisplayName: String) { /* NoOp */ }
override fun onLiveCall(callId: StreamCallId, callDisplayName: String) { /* NoOp */ }
override fun getOngoingCallNotification(callId: StreamCallId): Notification? = null
override fun onCallCancelled(callId: StreamCallId) { /* NoOp */ }
override fun onPermissionDenied() { /* NoOp */ }
override fun onPermissionGranted() { /* NoOp */ }
override fun onPermissionRationale() { /* NoOp */ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,34 @@ internal class VideoPushDelegate(
.let { StreamCallId(it.first, it.second) }
CoroutineScope(DispatcherProvider.IO).launch {
when (payload[KEY_TYPE]) {
KEY_TYPE_RING -> handleRingType(callId, payload)
KEY_TYPE_DIRECT_CALL -> handleDirectCallType(callId, payload)
KEY_TYPE_NOTIFICATION -> handleNotificationType(callId, payload)
KEY_TYPE_LIVE_STARTED -> handleLiveStartedType(callId, payload)
KEY_TYPE_DIRECT_CALL_CANCELLED -> handleDirectCallCancelledType(callId, payload)
}
}
}
}

private suspend fun handleRingType(callId: StreamCallId, payload: Map<String, Any?>) {
private fun handleDirectCallType(callId: StreamCallId, payload: Map<String, Any?>) {
val callDisplayName = (payload[KEY_CREATED_BY_DISPLAY_NAME] as String).ifEmpty { DEFAULT_CALL_TEXT }
getStreamVideo("ring-type-notification")?.onRingingCall(callId, callDisplayName)
}

private suspend fun handleNotificationType(callId: StreamCallId, payload: Map<String, Any?>) {
private fun handleNotificationType(callId: StreamCallId, payload: Map<String, Any?>) {
val callDisplayName = (payload[KEY_CREATED_BY_DISPLAY_NAME] as String).ifEmpty { DEFAULT_CALL_TEXT }
getStreamVideo("generic-notification")?.onNotification(callId, callDisplayName)
}

private suspend fun handleLiveStartedType(callId: StreamCallId, payload: Map<String, Any?>) {
private fun handleLiveStartedType(callId: StreamCallId, payload: Map<String, Any?>) {
val callDisplayName = (payload[KEY_CREATED_BY_DISPLAY_NAME] as String).ifEmpty { DEFAULT_CALL_TEXT }
getStreamVideo("live-started-notification")?.onLiveCall(callId, callDisplayName)
}

private fun handleDirectCallCancelledType(callId: StreamCallId, payload: Map<String, Any?>) {
getStreamVideo("call-cancelled-notification")?.onCallCancelled(callId)
}

/**
* Register a push device in our servers.
*
Expand Down Expand Up @@ -132,16 +137,17 @@ internal class VideoPushDelegate(
* Verify if the map contains a known type.
*/
private fun Map<String, Any?>.containsKnownType(): Boolean = when (this[KEY_TYPE]) {
KEY_TYPE_RING -> isValidRingType()
KEY_TYPE_DIRECT_CALL -> isValidDirectCallType()
KEY_TYPE_NOTIFICATION -> isValidNotificationType()
KEY_TYPE_LIVE_STARTED -> isValidLiveStarted()
KEY_TYPE_DIRECT_CALL_CANCELLED -> true
else -> false
}

/**
* Verify if the map contains all keys/values for a Ring Type.
*/
private fun Map<String, Any?>.isValidRingType(): Boolean =
private fun Map<String, Any?>.isValidDirectCallType(): Boolean =
// TODO: KEY_CALL_DISPLAY_NAME can be empty. Are there any other important key/values?
// !(this[KEY_CALL_DISPLAY_NAME] as? String).isNullOrBlank()
true
Expand Down Expand Up @@ -177,9 +183,10 @@ internal class VideoPushDelegate(
private companion object {
private const val KEY_SENDER = "sender"
private const val KEY_TYPE = "type"
private const val KEY_TYPE_RING = "call.ring"
private const val KEY_TYPE_DIRECT_CALL = "call.ring"
private const val KEY_TYPE_NOTIFICATION = "call.notification"
private const val KEY_TYPE_LIVE_STARTED = "call.live_started"
private const val KEY_TYPE_DIRECT_CALL_CANCELLED = "call.direct_call_cancelled"
private const val KEY_CALL_CID = "call_cid"
private const val KEY_CALL_DISPLAY_NAME = "call_display_name"
private const val KEY_CREATED_BY_DISPLAY_NAME = "created_by_display_name"
Expand Down
Loading