mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 17:35:54 +03:00
Check if account data has content to decide if push notifications can be toggled using account data
This commit is contained in:
parent
0c6781e9ef
commit
9d684bc021
2 changed files with 27 additions and 3 deletions
|
@ -16,8 +16,10 @@
|
|||
|
||||
package im.vector.app.features.settings.devices.v2.notification
|
||||
|
||||
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
import javax.inject.Inject
|
||||
|
||||
class CheckIfCanTogglePushNotificationsViaAccountDataUseCase @Inject constructor() {
|
||||
|
@ -25,6 +27,9 @@ class CheckIfCanTogglePushNotificationsViaAccountDataUseCase @Inject constructor
|
|||
fun execute(session: Session, deviceId: String): Boolean {
|
||||
return session
|
||||
.accountDataService()
|
||||
.getUserAccountDataEvent(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId) != null
|
||||
.getUserAccountDataEvent(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId)
|
||||
?.content
|
||||
.toModel<LocalNotificationSettingsContent>()
|
||||
?.isSilenced != null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,9 @@ import im.vector.app.test.fakes.FakeSession
|
|||
import io.mockk.mockk
|
||||
import org.amshove.kluent.shouldBeEqualTo
|
||||
import org.junit.Test
|
||||
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
||||
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes
|
||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||
|
||||
private const val A_DEVICE_ID = "device-id"
|
||||
|
||||
|
@ -32,7 +34,24 @@ class CheckIfCanTogglePushNotificationsViaAccountDataUseCaseTest {
|
|||
CheckIfCanTogglePushNotificationsViaAccountDataUseCase()
|
||||
|
||||
@Test
|
||||
fun `given current session and an account data for the device id when execute then result is true`() {
|
||||
fun `given current session and an account data with a content for the device id when execute then result is true`() {
|
||||
// Given
|
||||
fakeSession
|
||||
.accountDataService()
|
||||
.givenGetUserAccountDataEventReturns(
|
||||
type = UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + A_DEVICE_ID,
|
||||
content = LocalNotificationSettingsContent(isSilenced = true).toContent(),
|
||||
)
|
||||
|
||||
// When
|
||||
val result = checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
||||
|
||||
// Then
|
||||
result shouldBeEqualTo true
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given current session and an account data with empty content for the device id when execute then result is false`() {
|
||||
// Given
|
||||
fakeSession
|
||||
.accountDataService()
|
||||
|
@ -45,7 +64,7 @@ class CheckIfCanTogglePushNotificationsViaAccountDataUseCaseTest {
|
|||
val result = checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
||||
|
||||
// Then
|
||||
result shouldBeEqualTo true
|
||||
result shouldBeEqualTo false
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue