Let enterprise build be able to use a different notification channel for noisy notification.
This commit is contained in:
Submodule enterprise updated: 6207ddc1cb...6c63bfa2d2
@@ -35,6 +35,11 @@ interface EnterpriseService {
|
|||||||
|
|
||||||
fun bugReportUrlFlow(sessionId: SessionId?): Flow<BugReportUrl>
|
fun bugReportUrlFlow(sessionId: SessionId?): Flow<BugReportUrl>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets Notification Channel to use for the noisy notifications of the provided session.
|
||||||
|
*/
|
||||||
|
fun getNoisyNotificationChannelId(sessionId: SessionId): String?
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val ANY_ACCOUNT_PROVIDER = "*"
|
const val ANY_ACCOUNT_PROVIDER = "*"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,4 +43,6 @@ class DefaultEnterpriseService : EnterpriseService {
|
|||||||
override fun bugReportUrlFlow(sessionId: SessionId?): Flow<BugReportUrl> {
|
override fun bugReportUrlFlow(sessionId: SessionId?): Flow<BugReportUrl> {
|
||||||
return flowOf(BugReportUrl.UseDefault)
|
return flowOf(BugReportUrl.UseDefault)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getNoisyNotificationChannelId(sessionId: SessionId): String? = null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,4 +98,10 @@ class DefaultEnterpriseServiceTest {
|
|||||||
awaitComplete()
|
awaitComplete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `getNoisyNotificationChannelId returns null`() = runTest {
|
||||||
|
val defaultEnterpriseService = DefaultEnterpriseService()
|
||||||
|
assertThat(defaultEnterpriseService.getNoisyNotificationChannelId(A_SESSION_ID)).isNull()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class FakeEnterpriseService(
|
|||||||
private val overrideBrandColorResult: (SessionId?, String?) -> Unit = { _, _ -> lambdaError() },
|
private val overrideBrandColorResult: (SessionId?, String?) -> Unit = { _, _ -> lambdaError() },
|
||||||
private val firebasePushGatewayResult: () -> String? = { lambdaError() },
|
private val firebasePushGatewayResult: () -> String? = { lambdaError() },
|
||||||
private val unifiedPushDefaultPushGatewayResult: () -> String? = { lambdaError() },
|
private val unifiedPushDefaultPushGatewayResult: () -> String? = { lambdaError() },
|
||||||
|
private val getNoisyNotificationChannelIdResult: (SessionId?) -> String? = { lambdaError() },
|
||||||
) : EnterpriseService {
|
) : EnterpriseService {
|
||||||
private val brandColorState = MutableStateFlow(initialBrandColor)
|
private val brandColorState = MutableStateFlow(initialBrandColor)
|
||||||
private val semanticColorsState = MutableStateFlow(initialSemanticColors)
|
private val semanticColorsState = MutableStateFlow(initialSemanticColors)
|
||||||
@@ -69,4 +70,8 @@ class FakeEnterpriseService(
|
|||||||
override fun bugReportUrlFlow(sessionId: SessionId?): Flow<BugReportUrl> {
|
override fun bugReportUrlFlow(sessionId: SessionId?): Flow<BugReportUrl> {
|
||||||
return bugReportUrlMutableFlow.asStateFlow()
|
return bugReportUrlMutableFlow.asStateFlow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getNoisyNotificationChannelId(sessionId: SessionId): String? {
|
||||||
|
return getNoisyNotificationChannelIdResult(sessionId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1238,7 +1238,7 @@ class MessagesPresenterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `present - shows a "world_readable" icon if the room is encrypted and history is world_readable`() = runTest {
|
fun `present - shows a 'world_readable' icon if the room is encrypted and history is world_readable`() = runTest {
|
||||||
val presenter = createMessagesPresenter(
|
val presenter = createMessagesPresenter(
|
||||||
joinedRoom = FakeJoinedRoom(
|
joinedRoom = FakeJoinedRoom(
|
||||||
baseRoom = FakeBaseRoom(
|
baseRoom = FakeBaseRoom(
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ import dev.zacsweers.metro.AppScope
|
|||||||
import dev.zacsweers.metro.ContributesBinding
|
import dev.zacsweers.metro.ContributesBinding
|
||||||
import dev.zacsweers.metro.SingleIn
|
import dev.zacsweers.metro.SingleIn
|
||||||
import io.element.android.appconfig.NotificationConfig
|
import io.element.android.appconfig.NotificationConfig
|
||||||
|
import io.element.android.features.enterprise.api.EnterpriseService
|
||||||
import io.element.android.libraries.di.annotations.ApplicationContext
|
import io.element.android.libraries.di.annotations.ApplicationContext
|
||||||
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
import io.element.android.libraries.push.impl.R
|
import io.element.android.libraries.push.impl.R
|
||||||
import io.element.android.services.toolbox.api.strings.StringProvider
|
import io.element.android.services.toolbox.api.strings.StringProvider
|
||||||
|
|
||||||
@@ -47,9 +49,10 @@ interface NotificationChannels {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the channel for messages.
|
* Get the channel for messages.
|
||||||
|
* @param sessionId the session the message belongs to.
|
||||||
* @param noisy true if the notification should have sound and vibration.
|
* @param noisy true if the notification should have sound and vibration.
|
||||||
*/
|
*/
|
||||||
fun getChannelIdForMessage(noisy: Boolean): String
|
fun getChannelIdForMessage(sessionId: SessionId, noisy: Boolean): String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the channel for test notifications.
|
* Get the channel for test notifications.
|
||||||
@@ -67,6 +70,7 @@ class DefaultNotificationChannels(
|
|||||||
private val stringProvider: StringProvider,
|
private val stringProvider: StringProvider,
|
||||||
@ApplicationContext
|
@ApplicationContext
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
|
private val enterpriseService: EnterpriseService,
|
||||||
) : NotificationChannels {
|
) : NotificationChannels {
|
||||||
init {
|
init {
|
||||||
createNotificationChannels()
|
createNotificationChannels()
|
||||||
@@ -115,7 +119,7 @@ class DefaultNotificationChannels(
|
|||||||
.setSound(
|
.setSound(
|
||||||
Uri.Builder()
|
Uri.Builder()
|
||||||
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
|
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
|
||||||
// Strangely wwe have to provide a "//" before the package name
|
// Strangely we have to provide a "//" before the package name
|
||||||
.path("//" + context.packageName + "/" + R.raw.message)
|
.path("//" + context.packageName + "/" + R.raw.message)
|
||||||
.build(),
|
.build(),
|
||||||
AudioAttributes.Builder()
|
AudioAttributes.Builder()
|
||||||
@@ -186,8 +190,13 @@ class DefaultNotificationChannels(
|
|||||||
return if (ring) RINGING_CALL_NOTIFICATION_CHANNEL_ID else CALL_NOTIFICATION_CHANNEL_ID
|
return if (ring) RINGING_CALL_NOTIFICATION_CHANNEL_ID else CALL_NOTIFICATION_CHANNEL_ID
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getChannelIdForMessage(noisy: Boolean): String {
|
override fun getChannelIdForMessage(sessionId: SessionId, noisy: Boolean): String {
|
||||||
return if (noisy) NOISY_NOTIFICATION_CHANNEL_ID else SILENT_NOTIFICATION_CHANNEL_ID
|
return if (noisy) {
|
||||||
|
enterpriseService.getNoisyNotificationChannelId(sessionId)
|
||||||
|
?: NOISY_NOTIFICATION_CHANNEL_ID
|
||||||
|
} else {
|
||||||
|
SILENT_NOTIFICATION_CHANNEL_ID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getChannelIdForTest(): String = NOISY_NOTIFICATION_CHANNEL_ID
|
override fun getChannelIdForTest(): String = NOISY_NOTIFICATION_CHANNEL_ID
|
||||||
|
|||||||
@@ -151,7 +151,10 @@ class DefaultNotificationCreator(
|
|||||||
val channelId = if (containsMissedCall) {
|
val channelId = if (containsMissedCall) {
|
||||||
notificationChannels.getChannelForIncomingCall(false)
|
notificationChannels.getChannelForIncomingCall(false)
|
||||||
} else {
|
} else {
|
||||||
notificationChannels.getChannelIdForMessage(noisy = roomInfo.shouldBing)
|
notificationChannels.getChannelIdForMessage(
|
||||||
|
sessionId = roomInfo.sessionId,
|
||||||
|
noisy = roomInfo.shouldBing,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
// A category allows groups of notifications to be ranked and filtered – per user or system settings.
|
// A category allows groups of notifications to be ranked and filtered – per user or system settings.
|
||||||
// For example, alarm notifications should display before promo notifications, or message from known contact
|
// For example, alarm notifications should display before promo notifications, or message from known contact
|
||||||
@@ -230,7 +233,10 @@ class DefaultNotificationCreator(
|
|||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
inviteNotifiableEvent: InviteNotifiableEvent,
|
inviteNotifiableEvent: InviteNotifiableEvent,
|
||||||
): Notification {
|
): Notification {
|
||||||
val channelId = notificationChannels.getChannelIdForMessage(inviteNotifiableEvent.noisy)
|
val channelId = notificationChannels.getChannelIdForMessage(
|
||||||
|
sessionId = inviteNotifiableEvent.sessionId,
|
||||||
|
noisy = inviteNotifiableEvent.noisy,
|
||||||
|
)
|
||||||
return NotificationCompat.Builder(context, channelId)
|
return NotificationCompat.Builder(context, channelId)
|
||||||
.setOnlyAlertOnce(true)
|
.setOnlyAlertOnce(true)
|
||||||
.setContentTitle((inviteNotifiableEvent.roomName ?: buildMeta.applicationName).annotateForDebug(5))
|
.setContentTitle((inviteNotifiableEvent.roomName ?: buildMeta.applicationName).annotateForDebug(5))
|
||||||
@@ -270,7 +276,10 @@ class DefaultNotificationCreator(
|
|||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
simpleNotifiableEvent: SimpleNotifiableEvent,
|
simpleNotifiableEvent: SimpleNotifiableEvent,
|
||||||
): Notification {
|
): Notification {
|
||||||
val channelId = notificationChannels.getChannelIdForMessage(simpleNotifiableEvent.noisy)
|
val channelId = notificationChannels.getChannelIdForMessage(
|
||||||
|
sessionId = simpleNotifiableEvent.sessionId,
|
||||||
|
noisy = simpleNotifiableEvent.noisy,
|
||||||
|
)
|
||||||
return NotificationCompat.Builder(context, channelId)
|
return NotificationCompat.Builder(context, channelId)
|
||||||
.setOnlyAlertOnce(true)
|
.setOnlyAlertOnce(true)
|
||||||
.setContentTitle(buildMeta.applicationName.annotateForDebug(7))
|
.setContentTitle(buildMeta.applicationName.annotateForDebug(7))
|
||||||
@@ -302,7 +311,10 @@ class DefaultNotificationCreator(
|
|||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
fallbackNotifiableEvent: FallbackNotifiableEvent,
|
fallbackNotifiableEvent: FallbackNotifiableEvent,
|
||||||
): Notification {
|
): Notification {
|
||||||
val channelId = notificationChannels.getChannelIdForMessage(false)
|
val channelId = notificationChannels.getChannelIdForMessage(
|
||||||
|
sessionId = fallbackNotifiableEvent.sessionId,
|
||||||
|
noisy = false,
|
||||||
|
)
|
||||||
return NotificationCompat.Builder(context, channelId)
|
return NotificationCompat.Builder(context, channelId)
|
||||||
.setOnlyAlertOnce(true)
|
.setOnlyAlertOnce(true)
|
||||||
.setContentTitle(buildMeta.applicationName.annotateForDebug(7))
|
.setContentTitle(buildMeta.applicationName.annotateForDebug(7))
|
||||||
@@ -334,8 +346,11 @@ class DefaultNotificationCreator(
|
|||||||
noisy: Boolean,
|
noisy: Boolean,
|
||||||
lastMessageTimestamp: Long,
|
lastMessageTimestamp: Long,
|
||||||
): Notification {
|
): Notification {
|
||||||
val channelId = notificationChannels.getChannelIdForMessage(noisy)
|
|
||||||
val userId = notificationAccountParams.user.userId
|
val userId = notificationAccountParams.user.userId
|
||||||
|
val channelId = notificationChannels.getChannelIdForMessage(
|
||||||
|
sessionId = userId,
|
||||||
|
noisy = noisy,
|
||||||
|
)
|
||||||
return NotificationCompat.Builder(context, channelId)
|
return NotificationCompat.Builder(context, channelId)
|
||||||
.setOnlyAlertOnce(true)
|
.setOnlyAlertOnce(true)
|
||||||
// used in compat < N, after summary is built based on child notifications
|
// used in compat < N, after summary is built based on child notifications
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import android.os.Build
|
|||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.appconfig.NotificationConfig
|
import io.element.android.appconfig.NotificationConfig
|
||||||
|
import io.element.android.features.enterprise.api.EnterpriseService
|
||||||
|
import io.element.android.features.enterprise.test.FakeEnterpriseService
|
||||||
import io.element.android.libraries.matrix.api.media.MediaSource
|
import io.element.android.libraries.matrix.api.media.MediaSource
|
||||||
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||||
import io.element.android.libraries.matrix.test.A_TIMESTAMP
|
import io.element.android.libraries.matrix.test.A_TIMESTAMP
|
||||||
@@ -66,7 +68,11 @@ class DefaultBaseRoomGroupMessageCreatorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test createRoomMessage with one noisy Event`() = runTest {
|
fun `test createRoomMessage with one noisy Event`() = runTest {
|
||||||
val sut = createRoomGroupMessageCreator()
|
val sut = createRoomGroupMessageCreator(
|
||||||
|
enterpriseService = FakeEnterpriseService(
|
||||||
|
getNoisyNotificationChannelIdResult = { null }
|
||||||
|
)
|
||||||
|
)
|
||||||
val fakeImageLoader = FakeImageLoader()
|
val fakeImageLoader = FakeImageLoader()
|
||||||
val result = sut.createRoomMessage(
|
val result = sut.createRoomMessage(
|
||||||
notificationAccountParams = aNotificationAccountParams(),
|
notificationAccountParams = aNotificationAccountParams(),
|
||||||
@@ -228,6 +234,7 @@ class DefaultBaseRoomGroupMessageCreatorTest {
|
|||||||
|
|
||||||
fun createRoomGroupMessageCreator(
|
fun createRoomGroupMessageCreator(
|
||||||
sdkIntProvider: BuildVersionSdkIntProvider = FakeBuildVersionSdkIntProvider(Build.VERSION_CODES.O),
|
sdkIntProvider: BuildVersionSdkIntProvider = FakeBuildVersionSdkIntProvider(Build.VERSION_CODES.O),
|
||||||
|
enterpriseService: EnterpriseService = FakeEnterpriseService(),
|
||||||
): RoomGroupMessageCreator {
|
): RoomGroupMessageCreator {
|
||||||
val context = RuntimeEnvironment.getApplication() as Context
|
val context = RuntimeEnvironment.getApplication() as Context
|
||||||
val bitmapLoader = DefaultNotificationBitmapLoader(
|
val bitmapLoader = DefaultNotificationBitmapLoader(
|
||||||
@@ -236,7 +243,10 @@ fun createRoomGroupMessageCreator(
|
|||||||
initialsAvatarBitmapGenerator = FakeInitialsAvatarBitmapGenerator(),
|
initialsAvatarBitmapGenerator = FakeInitialsAvatarBitmapGenerator(),
|
||||||
)
|
)
|
||||||
return DefaultRoomGroupMessageCreator(
|
return DefaultRoomGroupMessageCreator(
|
||||||
notificationCreator = createNotificationCreator(bitmapLoader = bitmapLoader),
|
notificationCreator = createNotificationCreator(
|
||||||
|
bitmapLoader = bitmapLoader,
|
||||||
|
enterpriseService = enterpriseService,
|
||||||
|
),
|
||||||
bitmapLoader = bitmapLoader,
|
bitmapLoader = bitmapLoader,
|
||||||
stringProvider = AndroidStringProvider(context.resources)
|
stringProvider = AndroidStringProvider(context.resources)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,17 +8,19 @@
|
|||||||
|
|
||||||
package io.element.android.libraries.push.impl.notifications.channels
|
package io.element.android.libraries.push.impl.notifications.channels
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
|
|
||||||
class FakeNotificationChannels(
|
class FakeNotificationChannels(
|
||||||
var channelForIncomingCall: (ring: Boolean) -> String = { _ -> "" },
|
var channelForIncomingCall: (ring: Boolean) -> String = { _ -> "" },
|
||||||
var channelIdForMessage: (noisy: Boolean) -> String = { _ -> "" },
|
var channelIdForMessage: (sessionId: SessionId, noisy: Boolean) -> String = { _, _ -> "" },
|
||||||
var channelIdForTest: () -> String = { "" }
|
var channelIdForTest: () -> String = { "" }
|
||||||
) : NotificationChannels {
|
) : NotificationChannels {
|
||||||
override fun getChannelForIncomingCall(ring: Boolean): String {
|
override fun getChannelForIncomingCall(ring: Boolean): String {
|
||||||
return channelForIncomingCall(ring)
|
return channelForIncomingCall(ring)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getChannelIdForMessage(noisy: Boolean): String {
|
override fun getChannelIdForMessage(sessionId: SessionId, noisy: Boolean): String {
|
||||||
return channelIdForMessage(noisy)
|
return channelIdForMessage(sessionId, noisy)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getChannelIdForTest(): String {
|
override fun getChannelIdForTest(): String {
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ import android.os.Build
|
|||||||
import androidx.core.app.NotificationChannelCompat
|
import androidx.core.app.NotificationChannelCompat
|
||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import io.element.android.features.enterprise.api.EnterpriseService
|
||||||
|
import io.element.android.features.enterprise.test.FakeEnterpriseService
|
||||||
|
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
||||||
import io.element.android.services.toolbox.test.strings.FakeStringProvider
|
import io.element.android.services.toolbox.test.strings.FakeStringProvider
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
@@ -50,10 +53,28 @@ class NotificationChannelsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `getChannelIdForMessage - returns the right channel`() {
|
fun `getChannelIdForMessage - returns the right channel`() {
|
||||||
val notificationChannels = createNotificationChannels()
|
val notificationChannels = createNotificationChannels(
|
||||||
|
enterpriseService = FakeEnterpriseService(
|
||||||
|
getNoisyNotificationChannelIdResult = { null }
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assertThat(notificationChannels.getChannelIdForMessage(sessionId = A_SESSION_ID, noisy = true))
|
||||||
|
.isEqualTo(NOISY_NOTIFICATION_CHANNEL_ID)
|
||||||
|
assertThat(notificationChannels.getChannelIdForMessage(sessionId = A_SESSION_ID, noisy = false))
|
||||||
|
.isEqualTo(SILENT_NOTIFICATION_CHANNEL_ID)
|
||||||
|
}
|
||||||
|
|
||||||
assertThat(notificationChannels.getChannelIdForMessage(noisy = true)).isEqualTo(NOISY_NOTIFICATION_CHANNEL_ID)
|
@Test
|
||||||
assertThat(notificationChannels.getChannelIdForMessage(noisy = false)).isEqualTo(SILENT_NOTIFICATION_CHANNEL_ID)
|
fun `getChannelIdForMessage - returns the right channel when enterprise service override the result`() {
|
||||||
|
val notificationChannels = createNotificationChannels(
|
||||||
|
enterpriseService = FakeEnterpriseService(
|
||||||
|
getNoisyNotificationChannelIdResult = { "A_CHANNEL_ID" }
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assertThat(notificationChannels.getChannelIdForMessage(sessionId = A_SESSION_ID, noisy = true))
|
||||||
|
.isEqualTo("A_CHANNEL_ID")
|
||||||
|
assertThat(notificationChannels.getChannelIdForMessage(sessionId = A_SESSION_ID, noisy = false))
|
||||||
|
.isEqualTo(SILENT_NOTIFICATION_CHANNEL_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -65,9 +86,11 @@ class NotificationChannelsTest {
|
|||||||
|
|
||||||
private fun createNotificationChannels(
|
private fun createNotificationChannels(
|
||||||
notificationManager: NotificationManagerCompat = mockk(relaxed = true),
|
notificationManager: NotificationManagerCompat = mockk(relaxed = true),
|
||||||
|
enterpriseService: EnterpriseService = FakeEnterpriseService(),
|
||||||
) = DefaultNotificationChannels(
|
) = DefaultNotificationChannels(
|
||||||
notificationManager = notificationManager,
|
notificationManager = notificationManager,
|
||||||
stringProvider = FakeStringProvider(),
|
stringProvider = FakeStringProvider(),
|
||||||
context = RuntimeEnvironment.getApplication(),
|
context = RuntimeEnvironment.getApplication(),
|
||||||
|
enterpriseService = enterpriseService,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import androidx.core.app.NotificationCompat
|
|||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.appconfig.NotificationConfig
|
import io.element.android.appconfig.NotificationConfig
|
||||||
|
import io.element.android.features.enterprise.api.EnterpriseService
|
||||||
|
import io.element.android.features.enterprise.test.FakeEnterpriseService
|
||||||
import io.element.android.libraries.core.meta.BuildMeta
|
import io.element.android.libraries.core.meta.BuildMeta
|
||||||
import io.element.android.libraries.matrix.test.AN_EVENT_ID
|
import io.element.android.libraries.matrix.test.AN_EVENT_ID
|
||||||
import io.element.android.libraries.matrix.test.A_COLOR_INT
|
import io.element.android.libraries.matrix.test.A_COLOR_INT
|
||||||
@@ -129,7 +131,11 @@ class DefaultNotificationCreatorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test createSimpleEventNotification noisy`() {
|
fun `test createSimpleEventNotification noisy`() {
|
||||||
val sut = createNotificationCreator()
|
val sut = createNotificationCreator(
|
||||||
|
enterpriseService = FakeEnterpriseService(
|
||||||
|
getNoisyNotificationChannelIdResult = { null },
|
||||||
|
),
|
||||||
|
)
|
||||||
val result = sut.createSimpleEventNotification(
|
val result = sut.createSimpleEventNotification(
|
||||||
notificationAccountParams = aNotificationAccountParams(),
|
notificationAccountParams = aNotificationAccountParams(),
|
||||||
SimpleNotifiableEvent(
|
SimpleNotifiableEvent(
|
||||||
@@ -189,7 +195,11 @@ class DefaultNotificationCreatorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test createRoomInvitationNotification noisy`() {
|
fun `test createRoomInvitationNotification noisy`() {
|
||||||
val sut = createNotificationCreator()
|
val sut = createNotificationCreator(
|
||||||
|
enterpriseService = FakeEnterpriseService(
|
||||||
|
getNoisyNotificationChannelIdResult = { null },
|
||||||
|
),
|
||||||
|
)
|
||||||
val result = sut.createRoomInvitationNotification(
|
val result = sut.createRoomInvitationNotification(
|
||||||
notificationAccountParams = aNotificationAccountParams(),
|
notificationAccountParams = aNotificationAccountParams(),
|
||||||
InviteNotifiableEvent(
|
InviteNotifiableEvent(
|
||||||
@@ -231,7 +241,11 @@ class DefaultNotificationCreatorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test createSummaryListNotification noisy`() {
|
fun `test createSummaryListNotification noisy`() {
|
||||||
val sut = createNotificationCreator()
|
val sut = createNotificationCreator(
|
||||||
|
enterpriseService = FakeEnterpriseService(
|
||||||
|
getNoisyNotificationChannelIdResult = { null },
|
||||||
|
),
|
||||||
|
)
|
||||||
val matrixUser = aMatrixUser()
|
val matrixUser = aMatrixUser()
|
||||||
val result = sut.createSummaryListNotification(
|
val result = sut.createSummaryListNotification(
|
||||||
notificationAccountParams = aNotificationAccountParams(user = matrixUser),
|
notificationAccountParams = aNotificationAccountParams(user = matrixUser),
|
||||||
@@ -271,7 +285,11 @@ class DefaultNotificationCreatorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test createMessagesListNotification should bing and thread`() = runTest {
|
fun `test createMessagesListNotification should bing and thread`() = runTest {
|
||||||
val sut = createNotificationCreator()
|
val sut = createNotificationCreator(
|
||||||
|
enterpriseService = FakeEnterpriseService(
|
||||||
|
getNoisyNotificationChannelIdResult = { null },
|
||||||
|
),
|
||||||
|
)
|
||||||
val result = sut.createMessagesListNotification(
|
val result = sut.createMessagesListNotification(
|
||||||
notificationAccountParams = aNotificationAccountParams(),
|
notificationAccountParams = aNotificationAccountParams(),
|
||||||
roomInfo = RoomEventGroupInfo(
|
roomInfo = RoomEventGroupInfo(
|
||||||
@@ -312,7 +330,8 @@ const val REJECT_INVITATION_ACTION_TITLE = "RejectInvitationAction"
|
|||||||
fun createNotificationCreator(
|
fun createNotificationCreator(
|
||||||
context: Context = RuntimeEnvironment.getApplication(),
|
context: Context = RuntimeEnvironment.getApplication(),
|
||||||
buildMeta: BuildMeta = aBuildMeta(),
|
buildMeta: BuildMeta = aBuildMeta(),
|
||||||
notificationChannels: NotificationChannels = createNotificationChannels(),
|
enterpriseService: EnterpriseService = FakeEnterpriseService(),
|
||||||
|
notificationChannels: NotificationChannels = createNotificationChannels(enterpriseService),
|
||||||
bitmapLoader: NotificationBitmapLoader = DefaultNotificationBitmapLoader(
|
bitmapLoader: NotificationBitmapLoader = DefaultNotificationBitmapLoader(
|
||||||
context = context,
|
context = context,
|
||||||
sdkIntProvider = FakeBuildVersionSdkIntProvider(Build.VERSION_CODES.R),
|
sdkIntProvider = FakeBuildVersionSdkIntProvider(Build.VERSION_CODES.R),
|
||||||
@@ -358,11 +377,14 @@ fun createNotificationCreator(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createNotificationChannels(): NotificationChannels {
|
fun createNotificationChannels(
|
||||||
|
enterpriseService: EnterpriseService = FakeEnterpriseService(),
|
||||||
|
): NotificationChannels {
|
||||||
val context = RuntimeEnvironment.getApplication()
|
val context = RuntimeEnvironment.getApplication()
|
||||||
return DefaultNotificationChannels(
|
return DefaultNotificationChannels(
|
||||||
notificationManager = NotificationManagerCompat.from(context),
|
notificationManager = NotificationManagerCompat.from(context),
|
||||||
stringProvider = FakeStringProvider(""),
|
stringProvider = FakeStringProvider(""),
|
||||||
context = context,
|
context = context,
|
||||||
|
enterpriseService = enterpriseService,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ data class ElementWellKnown(
|
|||||||
val enforceElementPro: Boolean?,
|
val enforceElementPro: Boolean?,
|
||||||
val rageshakeUrl: String?,
|
val rageshakeUrl: String?,
|
||||||
val brandColor: String?,
|
val brandColor: String?,
|
||||||
|
val notificationSound: String?,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -30,4 +30,6 @@ data class InternalElementWellKnown(
|
|||||||
val rageshakeUrl: String? = null,
|
val rageshakeUrl: String? = null,
|
||||||
@SerialName("brand_color")
|
@SerialName("brand_color")
|
||||||
val brandColor: String? = null,
|
val brandColor: String? = null,
|
||||||
|
@SerialName("notification_sound")
|
||||||
|
val notificationSound: String? = null,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,4 +15,5 @@ internal fun InternalElementWellKnown.map() = ElementWellKnown(
|
|||||||
enforceElementPro = enforceElementPro,
|
enforceElementPro = enforceElementPro,
|
||||||
rageshakeUrl = rageshakeUrl,
|
rageshakeUrl = rageshakeUrl,
|
||||||
brandColor = brandColor,
|
brandColor = brandColor,
|
||||||
|
notificationSound = notificationSound,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class DefaultSessionWellknownRetrieverTest {
|
|||||||
enforceElementPro = null,
|
enforceElementPro = null,
|
||||||
rageshakeUrl = null,
|
rageshakeUrl = null,
|
||||||
brandColor = null,
|
brandColor = null,
|
||||||
|
notificationSound = null,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -51,7 +52,8 @@ class DefaultSessionWellknownRetrieverTest {
|
|||||||
"registration_helper_url": "a_registration_url",
|
"registration_helper_url": "a_registration_url",
|
||||||
"enforce_element_pro": true,
|
"enforce_element_pro": true,
|
||||||
"rageshake_url": "a_rageshake_url",
|
"rageshake_url": "a_rageshake_url",
|
||||||
"brand_color": "#FF0000"
|
"brand_color": "#FF0000",
|
||||||
|
"notification_sound": "a_notification_sound.flac"
|
||||||
}""".trimIndent().toByteArray()
|
}""".trimIndent().toByteArray()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -63,6 +65,7 @@ class DefaultSessionWellknownRetrieverTest {
|
|||||||
enforceElementPro = true,
|
enforceElementPro = true,
|
||||||
rageshakeUrl = "a_rageshake_url",
|
rageshakeUrl = "a_rageshake_url",
|
||||||
brandColor = "#FF0000",
|
brandColor = "#FF0000",
|
||||||
|
notificationSound = "a_notification_sound.flac",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -89,6 +92,7 @@ class DefaultSessionWellknownRetrieverTest {
|
|||||||
enforceElementPro = true,
|
enforceElementPro = true,
|
||||||
rageshakeUrl = "a_rageshake_url",
|
rageshakeUrl = "a_rageshake_url",
|
||||||
brandColor = null,
|
brandColor = null,
|
||||||
|
notificationSound = null,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,9 +15,11 @@ fun anElementWellKnown(
|
|||||||
enforceElementPro: Boolean? = null,
|
enforceElementPro: Boolean? = null,
|
||||||
rageshakeUrl: String? = null,
|
rageshakeUrl: String? = null,
|
||||||
brandColor: String? = null,
|
brandColor: String? = null,
|
||||||
|
notificationSound: String? = null,
|
||||||
) = ElementWellKnown(
|
) = ElementWellKnown(
|
||||||
registrationHelperUrl = registrationHelperUrl,
|
registrationHelperUrl = registrationHelperUrl,
|
||||||
enforceElementPro = enforceElementPro,
|
enforceElementPro = enforceElementPro,
|
||||||
rageshakeUrl = rageshakeUrl,
|
rageshakeUrl = rageshakeUrl,
|
||||||
brandColor = brandColor,
|
brandColor = brandColor,
|
||||||
|
notificationSound = notificationSound,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user