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

[AND-373] Filter-out unneeded notification updates and add flag to enable/disable #1314

Merged
merged 4 commits into from
Mar 13, 2025
Merged
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
10 changes: 6 additions & 4 deletions stream-video-android-core/api/stream-video-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -9932,18 +9932,20 @@ public final class io/getstream/video/android/core/notifications/DefaultStreamIn

public final class io/getstream/video/android/core/notifications/NotificationConfig {
public fun <init> ()V
public fun <init> (Ljava/util/List;Lkotlin/jvm/functions/Function0;Lio/getstream/video/android/core/notifications/NotificationHandler;ZLkotlin/jvm/functions/Function0;Z)V
public synthetic fun <init> (Ljava/util/List;Lkotlin/jvm/functions/Function0;Lio/getstream/video/android/core/notifications/NotificationHandler;ZLkotlin/jvm/functions/Function0;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/util/List;Lkotlin/jvm/functions/Function0;Lio/getstream/video/android/core/notifications/NotificationHandler;ZLkotlin/jvm/functions/Function0;ZZ)V
public synthetic fun <init> (Ljava/util/List;Lkotlin/jvm/functions/Function0;Lio/getstream/video/android/core/notifications/NotificationHandler;ZLkotlin/jvm/functions/Function0;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/util/List;
public final fun component2 ()Lkotlin/jvm/functions/Function0;
public final fun component3 ()Lio/getstream/video/android/core/notifications/NotificationHandler;
public final fun component4 ()Z
public final fun component5 ()Lkotlin/jvm/functions/Function0;
public final fun component6 ()Z
public final fun copy (Ljava/util/List;Lkotlin/jvm/functions/Function0;Lio/getstream/video/android/core/notifications/NotificationHandler;ZLkotlin/jvm/functions/Function0;Z)Lio/getstream/video/android/core/notifications/NotificationConfig;
public static synthetic fun copy$default (Lio/getstream/video/android/core/notifications/NotificationConfig;Ljava/util/List;Lkotlin/jvm/functions/Function0;Lio/getstream/video/android/core/notifications/NotificationHandler;ZLkotlin/jvm/functions/Function0;ZILjava/lang/Object;)Lio/getstream/video/android/core/notifications/NotificationConfig;
public final fun component7 ()Z
public final fun copy (Ljava/util/List;Lkotlin/jvm/functions/Function0;Lio/getstream/video/android/core/notifications/NotificationHandler;ZLkotlin/jvm/functions/Function0;ZZ)Lio/getstream/video/android/core/notifications/NotificationConfig;
public static synthetic fun copy$default (Lio/getstream/video/android/core/notifications/NotificationConfig;Ljava/util/List;Lkotlin/jvm/functions/Function0;Lio/getstream/video/android/core/notifications/NotificationHandler;ZLkotlin/jvm/functions/Function0;ZZILjava/lang/Object;)Lio/getstream/video/android/core/notifications/NotificationConfig;
public fun equals (Ljava/lang/Object;)Z
public final fun getAutoRegisterPushDevice ()Z
public final fun getEnableCallNotificationUpdates ()Z
public final fun getHideRingingNotificationInForeground ()Z
public final fun getNotificationHandler ()Lio/getstream/video/android/core/notifications/NotificationHandler;
public final fun getPushDeviceGenerators ()Ljava/util/List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public class StreamVideoBuilder @JvmOverloads constructor(
lifecycle = lifecycle,
coordinatorConnectionModule = coordinatorConnectionModule,
streamNotificationManager = streamNotificationManager,
enableCallNotificationUpdates = notificationConfig.enableCallNotificationUpdates,
callServiceConfigRegistry = callConfigRegistry,
testSfuAddress = localSfuAddress,
sounds = sounds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ internal class StreamVideoClient internal constructor(
internal val coordinatorConnectionModule: CoordinatorConnectionModule,
internal val tokenProvider: TokenProvider = ConstantTokenProvider(token),
internal val streamNotificationManager: StreamNotificationManager,
internal val enableCallNotificationUpdates: Boolean,
internal val callServiceConfigRegistry: CallServiceConfigRegistry = CallServiceConfigRegistry(),
internal val testSfuAddress: String? = null,
internal val sounds: Sounds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import io.getstream.video.android.core.Call
import io.getstream.video.android.core.R
import io.getstream.video.android.core.RingingState
import io.getstream.video.android.core.StreamVideo
import io.getstream.video.android.core.StreamVideoClient
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.ACTION_LIVE_CALL
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.ACTION_MISSED_CALL
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.ACTION_NOTIFICATION
Expand Down Expand Up @@ -394,6 +395,10 @@ public open class DefaultNotificationHandler(
localUser: User,
onUpdate: (Notification) -> Unit,
) {
val streamVideoClient = StreamVideo.instanceOrNull() as? StreamVideoClient

if (streamVideoClient?.enableCallNotificationUpdates != true) return

coroutineScope.launch {
var latestRemoteParticipantCount = -1

Expand Down Expand Up @@ -434,34 +439,38 @@ public open class DefaultNotificationHandler(
onUpdate(it)
}
} else if (ringingState is RingingState.Active) {
val currentRemoteParticipantCount = remoteParticipants.size
// If number of remote participants increased or decreased
if (remoteParticipants.size != latestRemoteParticipantCount) {
latestRemoteParticipantCount = remoteParticipants.size
if (currentRemoteParticipantCount != latestRemoteParticipantCount) {
val isSameCase = currentRemoteParticipantCount > 1 && latestRemoteParticipantCount > 1
latestRemoteParticipantCount = currentRemoteParticipantCount

val callDisplayName = if (remoteParticipants.isEmpty()) {
// If no remote participants, get simple call notification title
application.getString(
R.string.stream_video_ongoing_call_notification_title,
)
} else {
if (remoteParticipants.size > 1) {
// If more than 1 remote participant, get group call notification title
if (!isSameCase) {
val callDisplayName = if (remoteParticipants.isEmpty()) {
// If no remote participants, get simple call notification title
application.getString(
R.string.stream_video_ongoing_group_call_notification_title,
R.string.stream_video_ongoing_call_notification_title,
)
} else {
// If 1 remote participant, get the name of the remote participant
remoteParticipants.firstOrNull()?.name?.value ?: "Unknown"
if (currentRemoteParticipantCount > 1) {
// If more than 1 remote participant, get group call notification title
application.getString(
R.string.stream_video_ongoing_group_call_notification_title,
)
} else {
// If 1 remote participant, get the name of the remote participant
remoteParticipants.firstOrNull()?.name?.value ?: "Unknown"
}
}
}

// Use latest call display name in notification
getOngoingCallNotification(
callId = StreamCallId.fromCallCid(call.cid),
callDisplayName = callDisplayName,
remoteParticipantCount = remoteParticipants.size,
)?.let {
onUpdate(it)
// Use latest call display name in notification
getOngoingCallNotification(
callId = StreamCallId.fromCallCid(call.cid),
callDisplayName = callDisplayName,
remoteParticipantCount = currentRemoteParticipantCount,
)?.let {
onUpdate(it)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ public data class NotificationConfig(
* NOTE: This setting has only an effect if you don't set a custom [NotificationHandler]!
*/
val hideRingingNotificationInForeground: Boolean = false,
/**
* If `true`, call notifications will receive subsequent updates, based on the number of participants and other data.
*/
val enableCallNotificationUpdates: Boolean = true,
)
Loading