mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 19:05:56 +03:00
Merge pull request #7352 from vector-im/feature/mna/device-manager-lab-flag-account-data
[Device management] Add lab flag for matrix client info account data event (PSG-800)
This commit is contained in:
commit
ec5964bc20
17 changed files with 407 additions and 7 deletions
1
changelog.d/7344.feature
Normal file
1
changelog.d/7344.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[Device management] Add lab flag for matrix client info account data event
|
|
@ -3340,6 +3340,8 @@
|
||||||
<string name="device_manager_learn_more_session_rename">Other users in direct messages and rooms that you join are able to view a full list of your sessions.\n\nThis provides them with confidence that they are really speaking to you, but it also means they can see the session name you enter here.</string>
|
<string name="device_manager_learn_more_session_rename">Other users in direct messages and rooms that you join are able to view a full list of your sessions.\n\nThis provides them with confidence that they are really speaking to you, but it also means they can see the session name you enter here.</string>
|
||||||
<string name="labs_enable_session_manager_title">Enable new session manager</string>
|
<string name="labs_enable_session_manager_title">Enable new session manager</string>
|
||||||
<string name="labs_enable_session_manager_summary">Have greater visibility and control over all your sessions.</string>
|
<string name="labs_enable_session_manager_summary">Have greater visibility and control over all your sessions.</string>
|
||||||
|
<string name="labs_enable_client_info_recording_title">Enable client info recording</string>
|
||||||
|
<string name="labs_enable_client_info_recording_summary">Record the client name, version, and url to recognise sessions more easily in session manager.</string>
|
||||||
|
|
||||||
<!-- Note to translators: %s will be replaces with selected space name -->
|
<!-- Note to translators: %s will be replaces with selected space name -->
|
||||||
<string name="home_empty_space_no_rooms_title">%s\nis looking a little empty.</string>
|
<string name="home_empty_space_no_rooms_title">%s\nis looking a little empty.</string>
|
||||||
|
|
|
@ -42,6 +42,9 @@
|
||||||
<bool name="settings_labs_thread_messages_default">false</bool>
|
<bool name="settings_labs_thread_messages_default">false</bool>
|
||||||
<bool name="settings_labs_new_app_layout_default">true</bool>
|
<bool name="settings_labs_new_app_layout_default">true</bool>
|
||||||
<bool name="settings_labs_new_session_manager_default">false</bool>
|
<bool name="settings_labs_new_session_manager_default">false</bool>
|
||||||
|
<bool name="settings_labs_new_session_manager_visible">true</bool>
|
||||||
|
<bool name="settings_labs_client_info_recording_default">false</bool>
|
||||||
|
<bool name="settings_labs_client_info_recording_visible">true</bool>
|
||||||
<bool name="settings_timeline_show_live_sender_info_visible">true</bool>
|
<bool name="settings_timeline_show_live_sender_info_visible">true</bool>
|
||||||
<bool name="settings_timeline_show_live_sender_info_default">false</bool>
|
<bool name="settings_timeline_show_live_sender_info_default">false</bool>
|
||||||
<bool name="settings_labs_rich_text_editor_visible">true</bool>
|
<bool name="settings_labs_rich_text_editor_visible">true</bool>
|
||||||
|
|
|
@ -100,6 +100,7 @@ import im.vector.app.features.settings.devtools.KeyRequestViewModel
|
||||||
import im.vector.app.features.settings.font.FontScaleSettingViewModel
|
import im.vector.app.features.settings.font.FontScaleSettingViewModel
|
||||||
import im.vector.app.features.settings.homeserver.HomeserverSettingsViewModel
|
import im.vector.app.features.settings.homeserver.HomeserverSettingsViewModel
|
||||||
import im.vector.app.features.settings.ignored.IgnoredUsersViewModel
|
import im.vector.app.features.settings.ignored.IgnoredUsersViewModel
|
||||||
|
import im.vector.app.features.settings.labs.VectorSettingsLabsViewModel
|
||||||
import im.vector.app.features.settings.legals.LegalsViewModel
|
import im.vector.app.features.settings.legals.LegalsViewModel
|
||||||
import im.vector.app.features.settings.locale.LocalePickerViewModel
|
import im.vector.app.features.settings.locale.LocalePickerViewModel
|
||||||
import im.vector.app.features.settings.push.PushGatewaysViewModel
|
import im.vector.app.features.settings.push.PushGatewaysViewModel
|
||||||
|
@ -665,4 +666,9 @@ interface MavericksViewModelModule {
|
||||||
@IntoMap
|
@IntoMap
|
||||||
@MavericksViewModelKey(SessionLearnMoreViewModel::class)
|
@MavericksViewModelKey(SessionLearnMoreViewModel::class)
|
||||||
fun sessionLearnMoreViewModelFactory(factory: SessionLearnMoreViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
|
fun sessionLearnMoreViewModelFactory(factory: SessionLearnMoreViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
@IntoMap
|
||||||
|
@MavericksViewModelKey(VectorSettingsLabsViewModel::class)
|
||||||
|
fun vectorSettingsLabsViewModelFactory(factory: VectorSettingsLabsViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import im.vector.app.core.extensions.startSyncing
|
import im.vector.app.core.extensions.startSyncing
|
||||||
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
|
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
|
||||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||||
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.sync.FilterService
|
import org.matrix.android.sdk.api.session.sync.FilterService
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
@ -30,6 +31,7 @@ class ConfigureAndStartSessionUseCase @Inject constructor(
|
||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
private val webRtcCallManager: WebRtcCallManager,
|
private val webRtcCallManager: WebRtcCallManager,
|
||||||
private val updateMatrixClientInfoUseCase: UpdateMatrixClientInfoUseCase,
|
private val updateMatrixClientInfoUseCase: UpdateMatrixClientInfoUseCase,
|
||||||
|
private val vectorPreferences: VectorPreferences,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun execute(session: Session, startSyncing: Boolean = true) {
|
suspend fun execute(session: Session, startSyncing: Boolean = true) {
|
||||||
|
@ -41,6 +43,8 @@ class ConfigureAndStartSessionUseCase @Inject constructor(
|
||||||
}
|
}
|
||||||
session.pushersService().refreshPushers()
|
session.pushersService().refreshPushers()
|
||||||
webRtcCallManager.checkForProtocolsSupportIfNeeded()
|
webRtcCallManager.checkForProtocolsSupportIfNeeded()
|
||||||
updateMatrixClientInfoUseCase.execute(session)
|
if (vectorPreferences.isClientInfoRecordingEnabled()) {
|
||||||
|
updateMatrixClientInfoUseCase.execute(session)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* 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.core.session.clientinfo
|
||||||
|
|
||||||
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
|
import timber.log.Timber
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This use case delete the account data event containing extended client info.
|
||||||
|
*/
|
||||||
|
class DeleteMatrixClientInfoUseCase @Inject constructor(
|
||||||
|
private val activeSessionHolder: ActiveSessionHolder,
|
||||||
|
private val setMatrixClientInfoUseCase: SetMatrixClientInfoUseCase,
|
||||||
|
) {
|
||||||
|
|
||||||
|
suspend fun execute(): Result<Unit> = runCatching {
|
||||||
|
Timber.d("deleting recorded client info")
|
||||||
|
val session = activeSessionHolder.getActiveSession()
|
||||||
|
val emptyClientInfo = MatrixClientInfoContent(
|
||||||
|
name = "",
|
||||||
|
version = "",
|
||||||
|
url = "",
|
||||||
|
)
|
||||||
|
return setMatrixClientInfoUseCase.execute(session, emptyClientInfo)
|
||||||
|
}
|
||||||
|
}
|
|
@ -73,6 +73,7 @@ class VectorPreferences @Inject constructor(
|
||||||
const val SETTINGS_LABS_DEFERRED_DM_KEY = "SETTINGS_LABS_DEFERRED_DM_KEY"
|
const val SETTINGS_LABS_DEFERRED_DM_KEY = "SETTINGS_LABS_DEFERRED_DM_KEY"
|
||||||
const val SETTINGS_LABS_RICH_TEXT_EDITOR_KEY = "SETTINGS_LABS_RICH_TEXT_EDITOR_KEY"
|
const val SETTINGS_LABS_RICH_TEXT_EDITOR_KEY = "SETTINGS_LABS_RICH_TEXT_EDITOR_KEY"
|
||||||
const val SETTINGS_LABS_NEW_SESSION_MANAGER_KEY = "SETTINGS_LABS_NEW_SESSION_MANAGER_KEY"
|
const val SETTINGS_LABS_NEW_SESSION_MANAGER_KEY = "SETTINGS_LABS_NEW_SESSION_MANAGER_KEY"
|
||||||
|
const val SETTINGS_LABS_CLIENT_INFO_RECORDING_KEY = "SETTINGS_LABS_CLIENT_INFO_RECORDING_KEY"
|
||||||
const val SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY"
|
const val SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY"
|
||||||
const val SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY"
|
const val SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY"
|
||||||
const val SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY"
|
const val SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY"
|
||||||
|
@ -1188,6 +1189,13 @@ class VectorPreferences @Inject constructor(
|
||||||
return defaultPrefs.getBoolean(SETTINGS_LABS_NEW_SESSION_MANAGER_KEY, getDefault(R.bool.settings_labs_new_session_manager_default))
|
return defaultPrefs.getBoolean(SETTINGS_LABS_NEW_SESSION_MANAGER_KEY, getDefault(R.bool.settings_labs_new_session_manager_default))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether or not client info recording is enabled.
|
||||||
|
*/
|
||||||
|
fun isClientInfoRecordingEnabled(): Boolean {
|
||||||
|
return defaultPrefs.getBoolean(SETTINGS_LABS_CLIENT_INFO_RECORDING_KEY, getDefault(R.bool.settings_labs_client_info_recording_default))
|
||||||
|
}
|
||||||
|
|
||||||
fun showLiveSenderInfo(): Boolean {
|
fun showLiveSenderInfo(): Boolean {
|
||||||
return defaultPrefs.getBoolean(SETTINGS_TIMELINE_SHOW_LIVE_SENDER_INFO, getDefault(R.bool.settings_timeline_show_live_sender_info_default))
|
return defaultPrefs.getBoolean(SETTINGS_TIMELINE_SHOW_LIVE_SENDER_INFO, getDefault(R.bool.settings_timeline_show_live_sender_info_default))
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* 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.labs
|
||||||
|
|
||||||
|
import im.vector.app.core.platform.VectorViewModelAction
|
||||||
|
|
||||||
|
sealed class VectorSettingsLabsAction : VectorViewModelAction {
|
||||||
|
object UpdateClientInfo : VectorSettingsLabsAction()
|
||||||
|
object DeleteRecordedClientInfo : VectorSettingsLabsAction()
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 New Vector Ltd
|
* Copyright (c) 2019 New Vector Ltd
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -14,13 +14,15 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package im.vector.app.features.settings
|
package im.vector.app.features.settings.labs
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.method.LinkMovementMethod
|
import android.text.method.LinkMovementMethod
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
|
import androidx.preference.Preference.OnPreferenceChangeListener
|
||||||
import androidx.preference.SwitchPreference
|
import androidx.preference.SwitchPreference
|
||||||
|
import com.airbnb.mvrx.fragmentViewModel
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
|
@ -30,6 +32,8 @@ import im.vector.app.features.MainActivityArgs
|
||||||
import im.vector.app.features.VectorFeatures
|
import im.vector.app.features.VectorFeatures
|
||||||
import im.vector.app.features.analytics.plan.MobileScreen
|
import im.vector.app.features.analytics.plan.MobileScreen
|
||||||
import im.vector.app.features.home.room.threads.ThreadsManager
|
import im.vector.app.features.home.room.threads.ThreadsManager
|
||||||
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
|
import im.vector.app.features.settings.VectorSettingsBaseFragment
|
||||||
import org.matrix.android.sdk.api.settings.LightweightSettingsStorage
|
import org.matrix.android.sdk.api.settings.LightweightSettingsStorage
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -37,6 +41,8 @@ import javax.inject.Inject
|
||||||
class VectorSettingsLabsFragment :
|
class VectorSettingsLabsFragment :
|
||||||
VectorSettingsBaseFragment() {
|
VectorSettingsBaseFragment() {
|
||||||
|
|
||||||
|
private val viewModel: VectorSettingsLabsViewModel by fragmentViewModel()
|
||||||
|
|
||||||
@Inject lateinit var vectorPreferences: VectorPreferences
|
@Inject lateinit var vectorPreferences: VectorPreferences
|
||||||
@Inject lateinit var lightweightSettingsStorage: LightweightSettingsStorage
|
@Inject lateinit var lightweightSettingsStorage: LightweightSettingsStorage
|
||||||
@Inject lateinit var threadsManager: ThreadsManager
|
@Inject lateinit var threadsManager: ThreadsManager
|
||||||
|
@ -85,6 +91,7 @@ class VectorSettingsLabsFragment :
|
||||||
}
|
}
|
||||||
|
|
||||||
configureUnreadNotificationsAsTabPreference()
|
configureUnreadNotificationsAsTabPreference()
|
||||||
|
configureEnableClientInfoRecordingPreference()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureUnreadNotificationsAsTabPreference() {
|
private fun configureUnreadNotificationsAsTabPreference() {
|
||||||
|
@ -140,4 +147,16 @@ class VectorSettingsLabsFragment :
|
||||||
private fun onNewLayoutPreferenceClicked() {
|
private fun onNewLayoutPreferenceClicked() {
|
||||||
configureUnreadNotificationsAsTabPreference()
|
configureUnreadNotificationsAsTabPreference()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun configureEnableClientInfoRecordingPreference() {
|
||||||
|
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_LABS_CLIENT_INFO_RECORDING_KEY)?.onPreferenceChangeListener =
|
||||||
|
OnPreferenceChangeListener { _, newValue ->
|
||||||
|
when (newValue as? Boolean) {
|
||||||
|
false -> viewModel.handle(VectorSettingsLabsAction.DeleteRecordedClientInfo)
|
||||||
|
true -> viewModel.handle(VectorSettingsLabsAction.UpdateClientInfo)
|
||||||
|
else -> Unit
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* 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.labs
|
||||||
|
|
||||||
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
|
import dagger.assisted.Assisted
|
||||||
|
import dagger.assisted.AssistedFactory
|
||||||
|
import dagger.assisted.AssistedInject
|
||||||
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
|
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||||
|
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||||
|
import im.vector.app.core.platform.EmptyViewEvents
|
||||||
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
|
import im.vector.app.core.session.clientinfo.DeleteMatrixClientInfoUseCase
|
||||||
|
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class VectorSettingsLabsViewModel @AssistedInject constructor(
|
||||||
|
@Assisted initialState: VectorSettingsLabsViewState,
|
||||||
|
private val activeSessionHolder: ActiveSessionHolder,
|
||||||
|
private val updateMatrixClientInfoUseCase: UpdateMatrixClientInfoUseCase,
|
||||||
|
private val deleteMatrixClientInfoUseCase: DeleteMatrixClientInfoUseCase,
|
||||||
|
) : VectorViewModel<VectorSettingsLabsViewState, VectorSettingsLabsAction, EmptyViewEvents>(initialState) {
|
||||||
|
|
||||||
|
@AssistedFactory
|
||||||
|
interface Factory : MavericksAssistedViewModelFactory<VectorSettingsLabsViewModel, VectorSettingsLabsViewState> {
|
||||||
|
override fun create(initialState: VectorSettingsLabsViewState): VectorSettingsLabsViewModel
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object : MavericksViewModelFactory<VectorSettingsLabsViewModel, VectorSettingsLabsViewState> by hiltMavericksViewModelFactory()
|
||||||
|
|
||||||
|
override fun handle(action: VectorSettingsLabsAction) {
|
||||||
|
when (action) {
|
||||||
|
VectorSettingsLabsAction.UpdateClientInfo -> handleUpdateClientInfo()
|
||||||
|
VectorSettingsLabsAction.DeleteRecordedClientInfo -> handleDeleteRecordedClientInfo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleUpdateClientInfo() {
|
||||||
|
viewModelScope.launch {
|
||||||
|
activeSessionHolder.getSafeActiveSession()
|
||||||
|
?.let { session ->
|
||||||
|
updateMatrixClientInfoUseCase.execute(session)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleDeleteRecordedClientInfo() {
|
||||||
|
viewModelScope.launch {
|
||||||
|
deleteMatrixClientInfoUseCase.execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* 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.labs
|
||||||
|
|
||||||
|
import com.airbnb.mvrx.MavericksState
|
||||||
|
|
||||||
|
class VectorSettingsLabsViewState : MavericksState
|
|
@ -107,6 +107,14 @@
|
||||||
android:defaultValue="@bool/settings_labs_new_session_manager_default"
|
android:defaultValue="@bool/settings_labs_new_session_manager_default"
|
||||||
android:key="SETTINGS_LABS_NEW_SESSION_MANAGER_KEY"
|
android:key="SETTINGS_LABS_NEW_SESSION_MANAGER_KEY"
|
||||||
android:summary="@string/labs_enable_session_manager_summary"
|
android:summary="@string/labs_enable_session_manager_summary"
|
||||||
android:title="@string/labs_enable_session_manager_title" />
|
android:title="@string/labs_enable_session_manager_title"
|
||||||
|
app:isPreferenceVisible="@bool/settings_labs_new_session_manager_visible" />
|
||||||
|
|
||||||
|
<im.vector.app.core.preference.VectorSwitchPreference
|
||||||
|
android:defaultValue="@bool/settings_labs_client_info_recording_default"
|
||||||
|
android:key="SETTINGS_LABS_CLIENT_INFO_RECORDING_KEY"
|
||||||
|
android:summary="@string/labs_enable_client_info_recording_summary"
|
||||||
|
android:title="@string/labs_enable_client_info_recording_title"
|
||||||
|
app:isPreferenceVisible="@bool/settings_labs_client_info_recording_visible" />
|
||||||
|
|
||||||
</androidx.preference.PreferenceScreen>
|
</androidx.preference.PreferenceScreen>
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
<im.vector.app.core.preference.VectorPreference
|
<im.vector.app.core.preference.VectorPreference
|
||||||
android:icon="@drawable/ic_settings_root_labs"
|
android:icon="@drawable/ic_settings_root_labs"
|
||||||
android:title="@string/room_settings_labs_pref_title"
|
android:title="@string/room_settings_labs_pref_title"
|
||||||
app:fragment="im.vector.app.features.settings.VectorSettingsLabsFragment"
|
app:fragment="im.vector.app.features.settings.labs.VectorSettingsLabsFragment"
|
||||||
app:isPreferenceVisible="@bool/settings_root_labs_visible" />
|
app:isPreferenceVisible="@bool/settings_root_labs_visible" />
|
||||||
|
|
||||||
<im.vector.app.core.preference.VectorPreference
|
<im.vector.app.core.preference.VectorPreference
|
||||||
|
|
|
@ -20,6 +20,7 @@ import im.vector.app.core.extensions.startSyncing
|
||||||
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
|
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
|
||||||
import im.vector.app.test.fakes.FakeContext
|
import im.vector.app.test.fakes.FakeContext
|
||||||
import im.vector.app.test.fakes.FakeSession
|
import im.vector.app.test.fakes.FakeSession
|
||||||
|
import im.vector.app.test.fakes.FakeVectorPreferences
|
||||||
import im.vector.app.test.fakes.FakeWebRtcCallManager
|
import im.vector.app.test.fakes.FakeWebRtcCallManager
|
||||||
import io.mockk.coJustRun
|
import io.mockk.coJustRun
|
||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
|
@ -41,11 +42,13 @@ class ConfigureAndStartSessionUseCaseTest {
|
||||||
private val fakeContext = FakeContext()
|
private val fakeContext = FakeContext()
|
||||||
private val fakeWebRtcCallManager = FakeWebRtcCallManager()
|
private val fakeWebRtcCallManager = FakeWebRtcCallManager()
|
||||||
private val fakeUpdateMatrixClientInfoUseCase = mockk<UpdateMatrixClientInfoUseCase>()
|
private val fakeUpdateMatrixClientInfoUseCase = mockk<UpdateMatrixClientInfoUseCase>()
|
||||||
|
private val fakeVectorPreferences = FakeVectorPreferences()
|
||||||
|
|
||||||
private val configureAndStartSessionUseCase = ConfigureAndStartSessionUseCase(
|
private val configureAndStartSessionUseCase = ConfigureAndStartSessionUseCase(
|
||||||
context = fakeContext.instance,
|
context = fakeContext.instance,
|
||||||
webRtcCallManager = fakeWebRtcCallManager.instance,
|
webRtcCallManager = fakeWebRtcCallManager.instance,
|
||||||
updateMatrixClientInfoUseCase = fakeUpdateMatrixClientInfoUseCase,
|
updateMatrixClientInfoUseCase = fakeUpdateMatrixClientInfoUseCase,
|
||||||
|
vectorPreferences = fakeVectorPreferences.instance,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -59,11 +62,12 @@ class ConfigureAndStartSessionUseCaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given a session and start sync needed when configuring and starting the session then it should be configured properly`() = runTest {
|
fun `given start sync needed and client info recording enabled when execute then it should be configured properly`() = runTest {
|
||||||
// Given
|
// Given
|
||||||
val fakeSession = givenASession()
|
val fakeSession = givenASession()
|
||||||
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
|
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
|
||||||
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
|
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
|
||||||
|
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = true)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = true)
|
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = true)
|
||||||
|
@ -77,11 +81,31 @@ class ConfigureAndStartSessionUseCaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given a session and no start sync needed when configuring and starting the session then it should be configured properly`() = runTest {
|
fun `given start sync needed and client info recording disabled when execute then it should be configured properly`() = runTest {
|
||||||
// Given
|
// Given
|
||||||
val fakeSession = givenASession()
|
val fakeSession = givenASession()
|
||||||
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
|
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
|
||||||
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
|
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
|
||||||
|
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = false)
|
||||||
|
|
||||||
|
// When
|
||||||
|
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = true)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
verify { fakeSession.startSyncing(fakeContext.instance) }
|
||||||
|
fakeSession.fakeFilterService.verifySetFilter(FilterService.FilterPreset.ElementFilter)
|
||||||
|
fakeSession.fakePushersService.verifyRefreshPushers()
|
||||||
|
fakeWebRtcCallManager.verifyCheckForProtocolsSupportIfNeeded()
|
||||||
|
coVerify(inverse = true) { fakeUpdateMatrixClientInfoUseCase.execute(fakeSession) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given a session and no start sync needed when execute then it should be configured properly`() = runTest {
|
||||||
|
// Given
|
||||||
|
val fakeSession = givenASession()
|
||||||
|
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
|
||||||
|
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
|
||||||
|
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = true)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = false)
|
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = false)
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* 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.core.session.clientinfo
|
||||||
|
|
||||||
|
import im.vector.app.test.fakes.FakeActiveSessionHolder
|
||||||
|
import io.mockk.coEvery
|
||||||
|
import io.mockk.coVerify
|
||||||
|
import io.mockk.mockk
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.amshove.kluent.shouldBe
|
||||||
|
import org.amshove.kluent.shouldBeEqualTo
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class DeleteMatrixClientInfoUseCaseTest {
|
||||||
|
|
||||||
|
private val fakeActiveSessionHolder = FakeActiveSessionHolder()
|
||||||
|
private val fakeSetMatrixClientInfoUseCase = mockk<SetMatrixClientInfoUseCase>()
|
||||||
|
|
||||||
|
private val deleteMatrixClientInfoUseCase = DeleteMatrixClientInfoUseCase(
|
||||||
|
activeSessionHolder = fakeActiveSessionHolder.instance,
|
||||||
|
setMatrixClientInfoUseCase = fakeSetMatrixClientInfoUseCase
|
||||||
|
)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given current session when calling use case then empty client info is set and result is success`() = runTest {
|
||||||
|
// Given
|
||||||
|
givenSetMatrixClientInfoSucceeds()
|
||||||
|
val expectedClientInfoToBeSet = MatrixClientInfoContent(
|
||||||
|
name = "",
|
||||||
|
version = "",
|
||||||
|
url = "",
|
||||||
|
)
|
||||||
|
|
||||||
|
// When
|
||||||
|
val result = deleteMatrixClientInfoUseCase.execute()
|
||||||
|
|
||||||
|
// Then
|
||||||
|
result.isSuccess shouldBe true
|
||||||
|
coVerify {
|
||||||
|
fakeSetMatrixClientInfoUseCase.execute(
|
||||||
|
fakeActiveSessionHolder.fakeSession,
|
||||||
|
expectedClientInfoToBeSet
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given current session and error during the process when calling use case then result is failure`() = runTest {
|
||||||
|
// Given
|
||||||
|
val error = Exception()
|
||||||
|
givenSetMatrixClientInfoFails(error)
|
||||||
|
|
||||||
|
// When
|
||||||
|
val result = deleteMatrixClientInfoUseCase.execute()
|
||||||
|
|
||||||
|
// Then
|
||||||
|
result.isFailure shouldBe true
|
||||||
|
result.exceptionOrNull() shouldBeEqualTo error
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun givenSetMatrixClientInfoSucceeds() {
|
||||||
|
coEvery { fakeSetMatrixClientInfoUseCase.execute(any(), any()) } returns Result.success(Unit)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun givenSetMatrixClientInfoFails(error: Exception) {
|
||||||
|
coEvery { fakeSetMatrixClientInfoUseCase.execute(any(), any()) } returns Result.failure(error)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* 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.labs
|
||||||
|
|
||||||
|
import com.airbnb.mvrx.test.MavericksTestRule
|
||||||
|
import im.vector.app.core.session.clientinfo.DeleteMatrixClientInfoUseCase
|
||||||
|
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
|
||||||
|
import im.vector.app.test.fakes.FakeActiveSessionHolder
|
||||||
|
import im.vector.app.test.test
|
||||||
|
import im.vector.app.test.testDispatcher
|
||||||
|
import io.mockk.coEvery
|
||||||
|
import io.mockk.coVerify
|
||||||
|
import io.mockk.mockk
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class VectorSettingsLabsViewModelTest {
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val mavericksTestRule = MavericksTestRule(testDispatcher = testDispatcher)
|
||||||
|
|
||||||
|
private val fakeActiveSessionHolder = FakeActiveSessionHolder()
|
||||||
|
private val fakeUpdateMatrixClientInfoUseCase = mockk<UpdateMatrixClientInfoUseCase>()
|
||||||
|
private val fakeDeleteMatrixClientInfoUseCase = mockk<DeleteMatrixClientInfoUseCase>()
|
||||||
|
|
||||||
|
private fun createViewModel(): VectorSettingsLabsViewModel {
|
||||||
|
return VectorSettingsLabsViewModel(
|
||||||
|
initialState = VectorSettingsLabsViewState(),
|
||||||
|
activeSessionHolder = fakeActiveSessionHolder.instance,
|
||||||
|
updateMatrixClientInfoUseCase = fakeUpdateMatrixClientInfoUseCase,
|
||||||
|
deleteMatrixClientInfoUseCase = fakeDeleteMatrixClientInfoUseCase,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given update client info action when handling this action then update client info use case is called`() {
|
||||||
|
// Given
|
||||||
|
givenUpdateClientInfoSucceeds()
|
||||||
|
|
||||||
|
// When
|
||||||
|
val viewModel = createViewModel()
|
||||||
|
val viewModelTest = viewModel.test()
|
||||||
|
viewModel.handle(VectorSettingsLabsAction.UpdateClientInfo)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
viewModelTest.finish()
|
||||||
|
coVerify { fakeUpdateMatrixClientInfoUseCase.execute(fakeActiveSessionHolder.fakeSession) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given delete client info action when handling this action then delete client info use case is called`() {
|
||||||
|
// Given
|
||||||
|
givenDeleteClientInfoSucceeds()
|
||||||
|
|
||||||
|
// When
|
||||||
|
val viewModel = createViewModel()
|
||||||
|
val viewModelTest = viewModel.test()
|
||||||
|
viewModel.handle(VectorSettingsLabsAction.DeleteRecordedClientInfo)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
viewModelTest.finish()
|
||||||
|
coVerify { fakeDeleteMatrixClientInfoUseCase.execute() }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun givenUpdateClientInfoSucceeds() {
|
||||||
|
coEvery { fakeUpdateMatrixClientInfoUseCase.execute(any()) } returns Result.success(Unit)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun givenDeleteClientInfoSucceeds() {
|
||||||
|
coEvery { fakeDeleteMatrixClientInfoUseCase.execute() } returns Result.success(Unit)
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,4 +36,8 @@ class FakeVectorPreferences {
|
||||||
fun verifySetSpaceBackstack(value: List<String?>, inverse: Boolean = false) {
|
fun verifySetSpaceBackstack(value: List<String?>, inverse: Boolean = false) {
|
||||||
verify(inverse = inverse) { instance.setSpaceBackstack(value) }
|
verify(inverse = inverse) { instance.setSpaceBackstack(value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun givenIsClientInfoRecordingEnabled(isEnabled: Boolean) {
|
||||||
|
every { instance.isClientInfoRecordingEnabled() } returns isEnabled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue