Skip to content

Commit 8941e63

Browse files
committed
Hide multi signout if we have an external account manager (#8616)
1 parent 4254415 commit 8941e63

File tree

6 files changed

+47
-12
lines changed

6 files changed

+47
-12
lines changed

vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import timber.log.Timber
4040

4141
class DevicesViewModel @AssistedInject constructor(
4242
@Assisted initialState: DevicesViewState,
43-
activeSessionHolder: ActiveSessionHolder,
43+
private val activeSessionHolder: ActiveSessionHolder,
4444
private val getCurrentSessionCrossSigningInfoUseCase: GetCurrentSessionCrossSigningInfoUseCase,
4545
private val getDeviceFullInfoListUseCase: GetDeviceFullInfoListUseCase,
4646
private val refreshDevicesOnCryptoDevicesChangeUseCase: RefreshDevicesOnCryptoDevicesChangeUseCase,
@@ -69,6 +69,18 @@ class DevicesViewModel @AssistedInject constructor(
6969
refreshDeviceList()
7070
refreshIpAddressVisibility()
7171
observePreferences()
72+
initExternalAccountManagementUrl()
73+
}
74+
75+
private fun initExternalAccountManagementUrl() {
76+
setState {
77+
copy(
78+
externalAccountManagementUrl = activeSessionHolder.getSafeActiveSession()
79+
?.homeServerCapabilitiesService()
80+
?.getHomeServerCapabilities()
81+
?.externalAccountManagementUrl
82+
)
83+
}
7284
}
7385

7486
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {

vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ data class DevicesViewState(
2626
val devices: Async<DeviceFullInfoList> = Uninitialized,
2727
val isLoading: Boolean = false,
2828
val isShowingIpAddress: Boolean = false,
29+
val externalAccountManagementUrl: String? = null,
2930
) : MavericksState
3031

3132
data class DeviceFullInfoList(

vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ class VectorSettingsDevicesFragment :
290290
val unverifiedSessionsCount = deviceFullInfoList?.unverifiedSessionsCount ?: 0
291291

292292
renderSecurityRecommendations(inactiveSessionsCount, unverifiedSessionsCount)
293-
renderCurrentSessionView(currentDeviceInfo, hasOtherDevices = otherDevices?.isNotEmpty().orFalse())
294-
renderOtherSessionsView(otherDevices, state.isShowingIpAddress)
293+
renderCurrentSessionView(currentDeviceInfo, hasOtherDevices = otherDevices?.isNotEmpty().orFalse(), state)
294+
renderOtherSessionsView(otherDevices, state)
295295
} else {
296296
hideSecurityRecommendations()
297297
hideCurrentSessionView()
@@ -347,13 +347,16 @@ class VectorSettingsDevicesFragment :
347347
hideInactiveSessionsRecommendation()
348348
}
349349

350-
private fun renderOtherSessionsView(otherDevices: List<DeviceFullInfo>?, isShowingIpAddress: Boolean) {
350+
private fun renderOtherSessionsView(otherDevices: List<DeviceFullInfo>?, state: DevicesViewState) {
351+
val isShowingIpAddress = state.isShowingIpAddress
351352
if (otherDevices.isNullOrEmpty()) {
352353
hideOtherSessionsView()
353354
} else {
354355
views.deviceListHeaderOtherSessions.isVisible = true
355356
val colorDestructive = colorProvider.getColorFromAttribute(R.attr.colorError)
356357
val multiSignoutItem = views.deviceListHeaderOtherSessions.menu.findItem(R.id.otherSessionsHeaderMultiSignout)
358+
// Hide multi signout if we have an external account manager
359+
multiSignoutItem.isVisible = state.externalAccountManagementUrl == null
357360
val nbDevices = otherDevices.size
358361
multiSignoutItem.title = stringProvider.getQuantityString(R.plurals.device_manager_other_sessions_multi_signout_all, nbDevices, nbDevices)
359362
multiSignoutItem.setTextColor(colorDestructive)
@@ -377,23 +380,24 @@ class VectorSettingsDevicesFragment :
377380
views.deviceListOtherSessions.isVisible = false
378381
}
379382

380-
private fun renderCurrentSessionView(currentDeviceInfo: DeviceFullInfo?, hasOtherDevices: Boolean) {
383+
private fun renderCurrentSessionView(currentDeviceInfo: DeviceFullInfo?, hasOtherDevices: Boolean, state: DevicesViewState) {
381384
currentDeviceInfo?.let {
382-
renderCurrentSessionHeaderView(hasOtherDevices)
385+
renderCurrentSessionHeaderView(hasOtherDevices, state)
383386
renderCurrentSessionListView(it)
384387
} ?: run {
385388
hideCurrentSessionView()
386389
}
387390
}
388391

389-
private fun renderCurrentSessionHeaderView(hasOtherDevices: Boolean) {
392+
private fun renderCurrentSessionHeaderView(hasOtherDevices: Boolean, state: DevicesViewState) {
390393
views.deviceListHeaderCurrentSession.isVisible = true
391394
val colorDestructive = colorProvider.getColorFromAttribute(R.attr.colorError)
392395
val signoutSessionItem = views.deviceListHeaderCurrentSession.menu.findItem(R.id.currentSessionHeaderSignout)
393396
signoutSessionItem.setTextColor(colorDestructive)
394397
val signoutOtherSessionsItem = views.deviceListHeaderCurrentSession.menu.findItem(R.id.currentSessionHeaderSignoutOtherSessions)
395398
signoutOtherSessionsItem.setTextColor(colorDestructive)
396-
signoutOtherSessionsItem.isVisible = hasOtherDevices
399+
// Hide signout other sessions if we have an external account manager
400+
signoutOtherSessionsItem.isVisible = hasOtherDevices && state.externalAccountManagementUrl == null
397401
}
398402

399403
private fun renderCurrentSessionListView(currentDeviceInfo: DeviceFullInfo) {

vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsFragment.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,15 @@ class OtherSessionsFragment :
103103
val nbDevices = viewState.devices()?.size ?: 0
104104
stringProvider.getQuantityString(R.plurals.device_manager_other_sessions_multi_signout_all, nbDevices, nbDevices)
105105
}
106-
multiSignoutItem.isVisible = if (viewState.isSelectModeEnabled) {
107-
viewState.devices.invoke()?.any { it.isSelected }.orFalse()
106+
multiSignoutItem.isVisible = if (viewState.externalAccountManagementUrl != null) {
107+
// Hide multi signout if we have an external account manager
108+
false
108109
} else {
109-
viewState.devices.invoke()?.isNotEmpty().orFalse()
110+
if (viewState.isSelectModeEnabled) {
111+
viewState.devices.invoke()?.any { it.isSelected }.orFalse()
112+
} else {
113+
viewState.devices.invoke()?.isNotEmpty().orFalse()
114+
}
110115
}
111116
val showAsActionFlag = if (viewState.isSelectModeEnabled) MenuItem.SHOW_AS_ACTION_IF_ROOM else MenuItem.SHOW_AS_ACTION_NEVER
112117
multiSignoutItem.setShowAsAction(showAsActionFlag or MenuItem.SHOW_AS_ACTION_WITH_TEXT)

vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import timber.log.Timber
4141

4242
class OtherSessionsViewModel @AssistedInject constructor(
4343
@Assisted private val initialState: OtherSessionsViewState,
44-
activeSessionHolder: ActiveSessionHolder,
44+
private val activeSessionHolder: ActiveSessionHolder,
4545
private val getDeviceFullInfoListUseCase: GetDeviceFullInfoListUseCase,
4646
private val signoutSessionsUseCase: SignoutSessionsUseCase,
4747
private val pendingAuthHandler: PendingAuthHandler,
@@ -65,6 +65,18 @@ class OtherSessionsViewModel @AssistedInject constructor(
6565
observeDevices(initialState.currentFilter)
6666
refreshIpAddressVisibility()
6767
observePreferences()
68+
initExternalAccountManagementUrl()
69+
}
70+
71+
private fun initExternalAccountManagementUrl() {
72+
setState {
73+
copy(
74+
externalAccountManagementUrl = activeSessionHolder.getSafeActiveSession()
75+
?.homeServerCapabilitiesService()
76+
?.getHomeServerCapabilities()
77+
?.externalAccountManagementUrl
78+
)
79+
}
6880
}
6981

7082
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {

vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ data class OtherSessionsViewState(
2929
val isSelectModeEnabled: Boolean = false,
3030
val isLoading: Boolean = false,
3131
val isShowingIpAddress: Boolean = false,
32+
val externalAccountManagementUrl: String? = null,
3233
) : MavericksState {
3334

3435
constructor(args: OtherSessionsArgs) : this(excludeCurrentDevice = args.excludeCurrentDevice)

0 commit comments

Comments
 (0)