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

fix: disable sound and vibration for notification reply [WPB-4741] #2841

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -486,7 +486,7 @@
messagesStyle.addMessage(replyMessage)
}

val notification = setUpNotificationBuilder(context, userId).apply {
val notification = setUpNotificationBuilder(context, userId, true).apply {

Check warning on line 489 in app/src/main/kotlin/com/wire/android/notification/MessageNotificationManager.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/notification/MessageNotificationManager.kt#L489

Added line #L489 was not covered by tests
Garzas marked this conversation as resolved.
Show resolved Hide resolved
setContentIntent(messagePendingIntent(context, conversationId, userIdString))
addAction(getActionReply(context, conversationId, userIdString, false))

Expand All @@ -506,10 +506,20 @@

/**
* Create NotificationBuilder and set all the parameters that are common for any MessageNotification
* use [isSelfNotification] to disable sound and vibrations when notification is self reply
* @return resulted [NotificationCompat.Builder] so we can set other specific parameters and build it.
*/
private fun setUpNotificationBuilder(context: Context, userId: QualifiedID): NotificationCompat.Builder {
val channelId = NotificationConstants.getMessagesChannelId(userId)
private fun setUpNotificationBuilder(
context: Context,
userId: QualifiedID,
isSelfNotification: Boolean = false

Check warning on line 515 in app/src/main/kotlin/com/wire/android/notification/MessageNotificationManager.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/notification/MessageNotificationManager.kt#L515

Added line #L515 was not covered by tests
): NotificationCompat.Builder {
val channelId = if (isSelfNotification) {
NotificationConstants.getSelfMessagesChannelId(userId)

Check warning on line 518 in app/src/main/kotlin/com/wire/android/notification/MessageNotificationManager.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/notification/MessageNotificationManager.kt#L518

Added line #L518 was not covered by tests
} else {
NotificationConstants.getMessagesChannelId(userId)

Check warning on line 520 in app/src/main/kotlin/com/wire/android/notification/MessageNotificationManager.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/notification/MessageNotificationManager.kt#L520

Added line #L520 was not covered by tests
}

return NotificationCompat.Builder(context, channelId).apply {
setDefaults(NotificationCompat.DEFAULT_ALL)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
createIncomingCallsChannel(groupId, user.id)
createMessagesNotificationChannel(user.id, groupId)
createPingNotificationChannel(user.id, groupId)
createSelfMessagesNotificationChannel(user.id, groupId)

Check warning on line 69 in app/src/main/kotlin/com/wire/android/notification/NotificationChannelsManager.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/notification/NotificationChannelsManager.kt#L69

Added line #L69 was not covered by tests
}

// OngoingCall is not user specific channel, but common for all users.
Expand Down Expand Up @@ -145,6 +146,19 @@
notificationManagerCompat.createNotificationChannel(notificationChannel)
}

private fun createSelfMessagesNotificationChannel(userId: UserId, channelGroupId: String) {
val notificationChannel = NotificationChannelCompat
.Builder(NotificationConstants.getSelfMessagesChannelId(userId), NotificationManagerCompat.IMPORTANCE_HIGH)
.setName(NotificationConstants.SELF_MESSAGE_CHANNEL_NAME)
.setSound(null, null)
.setLightsEnabled(false)
.setVibrationEnabled(false)
.setGroup(channelGroupId)
.build()

Check warning on line 157 in app/src/main/kotlin/com/wire/android/notification/NotificationChannelsManager.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/notification/NotificationChannelsManager.kt#L150-L157

Added lines #L150 - L157 were not covered by tests

notificationManagerCompat.createNotificationChannel(notificationChannel)

Check warning on line 159 in app/src/main/kotlin/com/wire/android/notification/NotificationChannelsManager.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/notification/NotificationChannelsManager.kt#L159

Added line #L159 was not covered by tests
}

private fun createPingNotificationChannel(userId: UserId, channelGroupId: String) {
val audioAttributes = AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

private const val MESSAGE_CHANNEL_ID = "com.wire.android.notification_channel"
const val MESSAGE_CHANNEL_NAME = "Messages"

private const val SELF_MESSAGE_CHANNEL_ID = "com.wire.android.notification_self_channel"
const val SELF_MESSAGE_CHANNEL_NAME = "Self Messages"

private const val PING_CHANNEL_ID = "com.wire.android.notification_ping_channel"
const val PING_CHANNEL_NAME = "Pings"
private const val MESSAGE_GROUP_KEY_PREFIX = "wire_reloaded_notification_group_"
Expand Down Expand Up @@ -63,6 +67,7 @@
fun getMessagesSummaryId(userId: UserId): Int = "$MESSAGE_SUMMARY_ID_STRING$userId".hashCode()
fun getChanelGroupIdForUser(userId: UserId): String = "$CHANNEL_GROUP_ID_PREFIX.$userId"
fun getMessagesChannelId(userId: UserId): String = getChanelIdForUser(userId, MESSAGE_CHANNEL_ID)
fun getSelfMessagesChannelId(userId: UserId): String = getChanelIdForUser(userId, SELF_MESSAGE_CHANNEL_ID)

Check warning on line 70 in app/src/main/kotlin/com/wire/android/notification/NotificationConstants.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/notification/NotificationConstants.kt#L70

Added line #L70 was not covered by tests
fun getPingsChannelId(userId: UserId): String = getChanelIdForUser(userId, PING_CHANNEL_ID)
fun getIncomingChannelId(userId: UserId): String = getChanelIdForUser(userId, INCOMING_CALL_CHANNEL_ID)

Expand Down
Loading