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

Local Notification Settings Event #7300

Merged
merged 66 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
5ced831
Adds push notifications switch
ericdecanini Sep 28, 2022
e1b78b9
Adds functionality to Push notification toggle
ericdecanini Sep 28, 2022
233d07e
Adds DefaultPushersServiceTest for togglePusher
ericdecanini Sep 29, 2022
da80c08
Adds DefaultTogglePusherTaskTest
ericdecanini Sep 29, 2022
670cceb
Adds SessionOverviewViewModelTest for toggling pusher
ericdecanini Sep 29, 2022
71558ed
Hides pusher toggle if there are no pushers of the device
ericdecanini Sep 29, 2022
3cc22c5
Adds changelog file
ericdecanini Sep 29, 2022
66b8ebd
Edits changelog file
ericdecanini Sep 29, 2022
ae2a02c
Fixes copyrights
ericdecanini Oct 3, 2022
47e5491
Unregisters checkedChangelistener in onDetachedFromWindow for switch …
ericdecanini Oct 3, 2022
d91bbfd
Links notification settings toggle to pusher service
ericdecanini Oct 3, 2022
ac33ac1
Adds changelog file
ericdecanini Oct 3, 2022
757ee1a
Adds error handling to VectorSettingsNotificationPreferenceFragment
ericdecanini Oct 4, 2022
121415d
Removes comment in FakePushersService
ericdecanini Oct 4, 2022
826efc0
Adds parsing for LocalNotificationSettings event
ericdecanini Oct 5, 2022
3cfb6a9
Adds changelog file
ericdecanini Oct 5, 2022
225050d
Merge branch 'feature/eric/msc3881' into feature/eric/push-toggle-not…
ericdecanini Oct 5, 2022
c038540
Fixes post merge errors
ericdecanini Oct 5, 2022
2289fde
Merge branch 'feature/eric/push-toggle-notifications' into feature/er…
ericdecanini Oct 5, 2022
1639b71
Merge branch 'feature/eric/msc3881' into feature/eric/push-toggle-not…
ericdecanini Oct 7, 2022
a1908b0
Merge branch 'feature/eric/push-toggle-notifications' into feature/er…
ericdecanini Oct 7, 2022
3398646
Fixes imports and improves string name
ericdecanini Oct 7, 2022
008ea66
Merge branch 'feature/eric/notificaton-settings-enabled' into feature…
ericdecanini Oct 7, 2022
9c533bc
Merge branch 'feature/eric/msc3881' into feature/eric/push-toggle-not…
ericdecanini Oct 9, 2022
4f65d5d
Merge branch 'feature/eric/msc3881' into feature/eric/push-toggle-not…
ericdecanini Oct 9, 2022
c3a70b5
Fixes legal copies
ericdecanini Oct 9, 2022
a951a80
Fixes kdoc punctuation
ericdecanini Oct 9, 2022
a9dd794
Merge branch 'feature/eric/push-toggle-notifications' into feature/er…
ericdecanini Oct 9, 2022
e999aab
Fixes string error
ericdecanini Oct 9, 2022
b4c15d3
Removes unused imports
ericdecanini Oct 9, 2022
c356b8c
Merge branch 'feature/eric/msc3881' into feature/eric/push-toggle-not…
ericdecanini Oct 9, 2022
ddc0021
Merge branch 'feature/eric/push-toggle-notifications' into feature/er…
ericdecanini Oct 9, 2022
e5ce394
Moves LocalNotificationSettingsContent
ericdecanini Oct 9, 2022
126f048
Merge branch 'feature/eric/notificaton-settings-enabled' into feature…
ericdecanini Oct 9, 2022
4a8eb51
Merge branch 'feature/eric/msc3881' into feature/eric/push-toggle-not…
ericdecanini Oct 9, 2022
91e902f
Fixes lint errors
ericdecanini Oct 9, 2022
a996c8c
Fixes test errors
ericdecanini Oct 9, 2022
3ecd04f
Merge branch 'feature/eric/push-toggle-notifications' into feature/er…
ericdecanini Oct 9, 2022
be16bad
Fixes test errors
ericdecanini Oct 9, 2022
f397a62
Fixes error
ericdecanini Oct 9, 2022
6895e14
Merge branch 'feature/eric/push-toggle-notifications' into feature/er…
ericdecanini Oct 9, 2022
04a0da9
Merge branch 'feature/eric/notificaton-settings-enabled' into feature…
ericdecanini Oct 9, 2022
971fe8e
Fixes error
ericdecanini Oct 9, 2022
476aab3
Merge branch 'feature/eric/push-toggle-notifications' into feature/er…
ericdecanini Oct 9, 2022
e44bca3
Fixes error
ericdecanini Oct 9, 2022
7523556
Merge branch 'feature/eric/notificaton-settings-enabled' into feature…
ericdecanini Oct 9, 2022
dee1f88
Fixes error
ericdecanini Oct 9, 2022
d656000
Fixes error
ericdecanini Oct 9, 2022
1e3dbba
Fixes error
ericdecanini Oct 9, 2022
49c6240
Merge branch 'feature/eric/push-toggle-notifications' into feature/er…
ericdecanini Oct 9, 2022
dfe17cd
Merge branch 'feature/eric/notificaton-settings-enabled' into feature…
ericdecanini Oct 9, 2022
9de170a
Fixes error
ericdecanini Oct 9, 2022
f93674d
Merge branch 'feature/eric/push-toggle-notifications' into feature/er…
ericdecanini Oct 9, 2022
6457e45
Merge branch 'feature/eric/notificaton-settings-enabled' into feature…
ericdecanini Oct 9, 2022
110600c
Merge branch 'feature/eric/msc3881' into feature/eric/push-toggle-not…
ericdecanini Oct 10, 2022
2f2dc4e
Merge branch 'feature/eric/push-toggle-notifications' into feature/er…
ericdecanini Oct 10, 2022
fc61d09
Merge branch 'feature/eric/notificaton-settings-enabled' into feature…
ericdecanini Oct 10, 2022
cb81451
Merge remote-tracking branch 'origin/develop' into feature/eric/notif…
ericdecanini Oct 11, 2022
b02b4a3
Adds lost tests
ericdecanini Oct 11, 2022
8f9b315
Merge branch 'feature/eric/notificaton-settings-enabled' into feature…
ericdecanini Oct 11, 2022
c6224b1
Adds PusherEntity migration
ericdecanini Oct 11, 2022
d1562d3
Fixes session overview layout overlap
ericdecanini Oct 11, 2022
992d7d3
Fixes switch being enabled by default
ericdecanini Oct 11, 2022
b693c93
Merge branch 'feature/eric/notificaton-settings-enabled' into feature…
ericdecanini Oct 11, 2022
c0441ad
Adds device id and unstable prefix
ericdecanini Oct 12, 2022
c38bbd8
Merge remote-tracking branch 'origin/develop' into feature/eric/local…
ericdecanini Oct 12, 2022
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
1 change: 1 addition & 0 deletions changelog.d/7300.wip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implements client-side of local notification settings event
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 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.api.account

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class LocalNotificationSettingsContent(
@Json(name = "is_silenced") val isSilenced: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ object UserAccountDataTypes {
const val TYPE_IDENTITY_SERVER = "m.identity_server"
const val TYPE_ACCEPTED_TERMS = "m.accepted_terms"
const val TYPE_OVERRIDE_COLORS = "im.vector.setting.override_colors"
const val TYPE_LOCAL_NOTIFICATION_SETTINGS = "org.matrix.msc3890.local_notification_settings."
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class HomeActivity :
)
}
}

sharedActionViewModel = viewModelProvider[HomeSharedActionViewModel::class.java]
roomListSharedActionViewModel = viewModelProvider[RoomListSharedActionViewModel::class.java]
views.drawerLayout.addDrawerListener(drawerListener)
Expand Down Expand Up @@ -406,6 +407,14 @@ class HomeActivity :
}

private fun renderState(state: HomeActivityViewState) {
lifecycleScope.launch {
if (state.areNotificationsSilenced) {
unifiedPushHelper.unregister(pushersManager)
} else {
unifiedPushHelper.register(this@HomeActivity)
}
}

when (val status = state.syncRequestState) {
is SyncRequestState.InitialSyncProgressing -> {
val initSyncStepStr = initSyncStepFormatter.format(status.initialSyncStep)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package im.vector.app.features.home

import androidx.lifecycle.asFlow
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.ViewModelContext
Expand Down Expand Up @@ -45,10 +46,12 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.takeWhile
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
import org.matrix.android.sdk.api.auth.UIABaseAuth
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
import org.matrix.android.sdk.api.auth.UserPasswordAuth
Expand All @@ -57,9 +60,11 @@ import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse
import org.matrix.android.sdk.api.auth.registration.nextUncompletedStage
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.raw.RawService
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes
import org.matrix.android.sdk.api.session.crypto.crosssigning.CrossSigningService
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.api.session.crypto.model.MXUsersDevicesMap
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.getUserOrDefault
import org.matrix.android.sdk.api.session.pushrules.RuleIds
import org.matrix.android.sdk.api.session.room.model.Membership
Expand Down Expand Up @@ -115,6 +120,7 @@ class HomeActivityViewModel @AssistedInject constructor(
observeCrossSigningReset()
observeAnalytics()
observeReleaseNotes()
observeLocalNotificationsSilenced()
initThreadsMigration()
}

Expand All @@ -136,6 +142,18 @@ class HomeActivityViewModel @AssistedInject constructor(
}
}

fun observeLocalNotificationsSilenced() {
val currentSession = activeSessionHolder.getActiveSession()
val deviceId = currentSession.cryptoService().getMyDevice().deviceId
viewModelScope.launch {
currentSession.accountDataService()
.getLiveUserAccountDataEvent(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId)
.asFlow()
.map { it.getOrNull()?.content?.toModel<LocalNotificationSettingsContent>()?.isSilenced ?: false }
.onEach { setState { copy(areNotificationsSilenced = it) } }
}
}

private fun observeAnalytics() {
if (analyticsConfig.isEnabled) {
analyticsStore.didAskUserConsentFlow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ import org.matrix.android.sdk.api.session.sync.SyncRequestState

data class HomeActivityViewState(
val syncRequestState: SyncRequestState = SyncRequestState.Idle,
val authenticationDescription: AuthenticationDescription? = null
val authenticationDescription: AuthenticationDescription? = null,
val areNotificationsSilenced: Boolean = false,
) : MavericksState