-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7476 from vector-im/fix/mna/push-toggle-check-sup…
…port [Session manager] Hide push notification toggle when there is no server support (PSG-970)
- Loading branch information
Showing
24 changed files
with
572 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[Session manager] Hide push notification toggle when there is no server support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...d/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo042.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2022 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.internal.database.migration | ||
|
||
import io.realm.DynamicRealm | ||
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntityFields | ||
import org.matrix.android.sdk.internal.extensions.forceRefreshOfHomeServerCapabilities | ||
import org.matrix.android.sdk.internal.util.database.RealmMigrator | ||
|
||
internal class MigrateSessionTo042(realm: DynamicRealm) : RealmMigrator(realm, 42) { | ||
|
||
override fun doMigrate(realm: DynamicRealm) { | ||
realm.schema.get("HomeServerCapabilitiesEntity") | ||
?.addField(HomeServerCapabilitiesEntityFields.CAN_REMOTELY_TOGGLE_PUSH_NOTIFICATIONS_OF_DEVICES, Boolean::class.java) | ||
?.forceRefreshOfHomeServerCapabilities() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ettings/devices/v2/notification/CheckIfCanTogglePushNotificationsViaAccountDataUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.settings.devices.v2.notification | ||
|
||
import im.vector.app.core.di.ActiveSessionHolder | ||
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes | ||
import javax.inject.Inject | ||
|
||
class CheckIfCanTogglePushNotificationsViaAccountDataUseCase @Inject constructor( | ||
private val activeSessionHolder: ActiveSessionHolder, | ||
) { | ||
|
||
fun execute(deviceId: String): Boolean { | ||
return activeSessionHolder | ||
.getSafeActiveSession() | ||
?.accountDataService() | ||
?.getUserAccountDataEvent(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId) != null | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...res/settings/devices/v2/notification/CheckIfCanTogglePushNotificationsViaPusherUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.settings.devices.v2.notification | ||
|
||
import im.vector.app.core.di.ActiveSessionHolder | ||
import org.matrix.android.sdk.api.extensions.orFalse | ||
import javax.inject.Inject | ||
|
||
class CheckIfCanTogglePushNotificationsViaPusherUseCase @Inject constructor( | ||
private val activeSessionHolder: ActiveSessionHolder, | ||
) { | ||
|
||
fun execute(): Boolean { | ||
return activeSessionHolder | ||
.getSafeActiveSession() | ||
?.homeServerCapabilitiesService() | ||
?.getHomeServerCapabilities() | ||
?.canRemotelyTogglePushNotificationsOfDevices | ||
.orFalse() | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
.../im/vector/app/features/settings/devices/v2/notification/GetNotificationsStatusUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.settings.devices.v2.notification | ||
|
||
import im.vector.app.core.di.ActiveSessionHolder | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.flow.map | ||
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.toModel | ||
import org.matrix.android.sdk.flow.flow | ||
import org.matrix.android.sdk.flow.unwrap | ||
import javax.inject.Inject | ||
|
||
class GetNotificationsStatusUseCase @Inject constructor( | ||
private val activeSessionHolder: ActiveSessionHolder, | ||
private val checkIfCanTogglePushNotificationsViaPusherUseCase: CheckIfCanTogglePushNotificationsViaPusherUseCase, | ||
private val checkIfCanTogglePushNotificationsViaAccountDataUseCase: CheckIfCanTogglePushNotificationsViaAccountDataUseCase, | ||
) { | ||
|
||
fun execute(deviceId: String): Flow<NotificationsStatus> { | ||
val session = activeSessionHolder.getSafeActiveSession() | ||
return when { | ||
session == null -> flowOf(NotificationsStatus.NOT_SUPPORTED) | ||
checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(deviceId) -> { | ||
session.flow() | ||
.liveUserAccountData(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId) | ||
.unwrap() | ||
.map { it.content.toModel<LocalNotificationSettingsContent>()?.isSilenced?.not() } | ||
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED } | ||
.distinctUntilChanged() | ||
} | ||
checkIfCanTogglePushNotificationsViaPusherUseCase.execute() -> { | ||
session.flow() | ||
.livePushers() | ||
.map { it.filter { pusher -> pusher.deviceId == deviceId } } | ||
.map { it.takeIf { it.isNotEmpty() }?.any { pusher -> pusher.enabled } } | ||
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED } | ||
.distinctUntilChanged() | ||
} | ||
else -> flowOf(NotificationsStatus.NOT_SUPPORTED) | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../main/java/im/vector/app/features/settings/devices/v2/notification/NotificationsStatus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.settings.devices.v2.notification | ||
|
||
enum class NotificationsStatus { | ||
ENABLED, | ||
DISABLED, | ||
NOT_SUPPORTED, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.