Skip to content

Commit 5e2d8dd

Browse files
committed
fix: fix notification cleaning from leave button in notification
1 parent 8c237bf commit 5e2d8dd

4 files changed

Lines changed: 27 additions & 13 deletions

File tree

stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/DefaultStreamIntentResolver.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,6 @@ public class DefaultStreamIntentResolver(
367367
resolveInfo.activityInfo.name,
368368
)
369369
putExtra(NotificationHandler.INTENT_EXTRA_CALL_CID, callId)
370-
putExtra(
371-
NotificationHandler.INTENT_EXTRA_NOTIFICATION_ID,
372-
callId.cid,
373-
)
374370
}
375371
}
376372
}

stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/NotificationHandler.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public interface NotificationHandler :
7070
const val INTENT_EXTRA_CALL_DISPLAY_NAME: String =
7171
"io.getstream.video.android.intent-extra.call_displayname"
7272

73+
@Deprecated(
74+
message = "Notification ids are managed internally and this extra is no longer " +
75+
"populated. Read the active notification id from CallState.notificationIdFlow, or " +
76+
"derive it with StreamCallId.getNotificationId(NotificationType).",
77+
)
7378
const val INTENT_EXTRA_NOTIFICATION_ID: String =
7479
"io.getstream.video.android.intent-extra.notification_id"
7580

stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/receivers/LeaveCallBroadcastReceiver.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import io.getstream.video.android.core.Call
2424
import io.getstream.video.android.core.CallLeaveReason
2525
import io.getstream.video.android.core.UserActionCause
2626
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.ACTION_LEAVE_CALL
27-
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.INTENT_EXTRA_NOTIFICATION_ID
27+
import io.getstream.video.android.model.StreamCallId
2828

2929
/**
3030
* Used to process any pending intents that feature the [ACTION_LEAVE_CALL] action. By consuming this
@@ -39,13 +39,23 @@ internal class LeaveCallBroadcastReceiver : GenericCallActionBroadcastReceiver()
3939
override suspend fun onReceive(call: Call, context: Context, intent: Intent) {
4040
logger.d { "[onReceive] #ringing; callId: ${call.id}, action: ${intent.action}" }
4141

42+
// A call has at most one notification; its id is stored at creation time in
43+
// CallState.notificationIdFlow (the source of truth, replacing the deprecated
44+
// INTENT_EXTRA_NOTIFICATION_ID extra).
45+
val notificationId = call.state.notificationIdFlow.value
46+
// TODO: remove this legacy notification id once nothing posts under StreamCallId.hashCode().
47+
val legacyNotificationId = StreamCallId.fromCallCid(call.cid).hashCode()
48+
4249
call.leave(
4350
CallLeaveReason.UserAction(
4451
UserActionCause.LEAVE_FROM_NOTIFICATION,
4552
),
4653
)
47-
val notificationId = intent.getIntExtra(INTENT_EXTRA_NOTIFICATION_ID, 0)
48-
logger.d { "[onReceive], notificationId: $notificationId" }
49-
NotificationManagerCompat.from(context).cancel(notificationId)
54+
logger.d {
55+
"[onReceive], notificationId: $notificationId, legacyNotificationId: $legacyNotificationId"
56+
}
57+
val notificationManager = NotificationManagerCompat.from(context)
58+
notificationId?.let { notificationManager.cancel(it) }
59+
notificationManager.cancel(legacyNotificationId)
5060
}
5161
}

stream-video-android-ui-core/src/main/kotlin/io/getstream/video/android/ui/common/notification/AbstractNotificationActivity.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import androidx.core.app.NotificationManagerCompat
2222
import androidx.lifecycle.lifecycleScope
2323
import io.getstream.video.android.core.StreamVideo
2424
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.INTENT_EXTRA_CALL_CID
25-
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.INTENT_EXTRA_NOTIFICATION_ID
25+
import io.getstream.video.android.core.notifications.NotificationType
2626
import io.getstream.video.android.model.StreamCallId
2727
import io.getstream.video.android.model.streamCallId
2828
import kotlinx.coroutines.launch
@@ -56,7 +56,7 @@ public abstract class AbstractNotificationActivity : ComponentActivity() {
5656

5757
lifecycleScope.launch {
5858
if (hasAcceptedCall) {
59-
dismissIncomingCallNotifications()
59+
dismissIncomingCallNotifications(callCid)
6060
} else {
6161
loadCallData(callCid)
6262
}
@@ -74,15 +74,18 @@ public abstract class AbstractNotificationActivity : ComponentActivity() {
7474
// is Result.Success -> Unit
7575
// is Result.Failure -> finish()
7676
// }
77-
dismissIncomingCallNotifications()
77+
dismissIncomingCallNotifications(guid)
7878
}
7979

8080
/**
8181
* Dismisses any notifications that might be active with a given notification ID.
8282
* Used to clear up the notification state if the call has been accepted or rejected.
8383
*/
84-
private fun dismissIncomingCallNotifications() {
85-
val notificationId = intent.getIntExtra(INTENT_EXTRA_NOTIFICATION_ID, 0)
84+
private fun dismissIncomingCallNotifications(callCid: StreamCallId) {
85+
// A call has a single notification; the incoming-call notification's id comes from the
86+
// shared generator, so derive it from the call id and cancel it. (Replaces the deprecated
87+
// INTENT_EXTRA_NOTIFICATION_ID extra.)
88+
val notificationId = callCid.getNotificationId(NotificationType.Incoming)
8689
NotificationManagerCompat.from(this).cancel(notificationId)
8790
finish()
8891
}

0 commit comments

Comments
 (0)