Visually disable call buttons/prohibit calling on insufficient permissions

Signed-off-by: Marinus Enzinger <marinus@enzingerm.de>
This commit is contained in:
Marinus Enzinger 2020-09-21 17:26:27 +02:00
parent 6486b9e5cd
commit 84df86df37
5 changed files with 19 additions and 2 deletions

View File

@ -6,6 +6,7 @@ Features ✨:
Improvements 🙌:
- Add "show password" in import Megolm keys dialog
- Visually disable call buttons in menu and prohibit calling when permissions are insufficient (#2112)
Bugfix 🐛:
- Long message cannot be sent/takes infinite time & blocks other messages #1397

View File

@ -610,6 +610,16 @@ class RoomDetailFragment @Inject constructor(
it.isVisible = roomDetailViewModel.isMenuItemVisible(it.itemId)
}
withState(roomDetailViewModel) { state ->
// Set the visual state of the call buttons (voice/video) to enabled/disabled according to user permissions
val callButtonsEnabled = when (state.asyncRoomSummary.invoke()?.joinedMembersCount) {
1 -> false
2 -> state.isAllowedToStartWebRTCCall
else -> state.isAllowedToManageWidgets
}
setOf(R.id.voice_call, R.id.video_call).forEach {
menu.findItem(it).icon?.alpha = if (callButtonsEnabled) 0xFF else 0x40
}
val matrixAppsMenuItem = menu.findItem(R.id.open_matrix_apps)
val widgetsCount = state.activeRoomWidgets.invoke()?.size ?: 0
if (widgetsCount > 0) {
@ -687,6 +697,8 @@ class RoomDetailFragment @Inject constructor(
// webRtcPeerConnectionManager.endCall()
// safeStartCall(it, isVideoCall)
// }
} else if (!state.isAllowedToStartWebRTCCall) {
showDialogWithMessage(getString(R.string.no_permissions_to_start_webrtc_call))
} else {
safeStartCall(isVideoCall)
}

View File

@ -181,10 +181,12 @@ class RoomDetailViewModel @AssistedInject constructor(
.subscribe {
val canSendMessage = PowerLevelsHelper(it).isUserAllowedToSend(session.myUserId, false, EventType.MESSAGE)
val isAllowedToManageWidgets = session.widgetService().hasPermissionsToHandleWidgets(room.roomId)
val isAllowedToStartWebRTCCall = PowerLevelsHelper(it).isUserAllowedToSend(session.myUserId, false, EventType.CALL_INVITE)
setState {
copy(
canSendMessage = canSendMessage,
isAllowedToManageWidgets = isAllowedToManageWidgets
isAllowedToManageWidgets = isAllowedToManageWidgets,
isAllowedToStartWebRTCCall = isAllowedToStartWebRTCCall
)
}
}

View File

@ -67,7 +67,8 @@ data class RoomDetailViewState(
val canShowJumpToReadMarker: Boolean = true,
val changeMembershipState: ChangeMembershipState = ChangeMembershipState.Unknown,
val canSendMessage: Boolean = true,
val isAllowedToManageWidgets: Boolean = false
val isAllowedToManageWidgets: Boolean = false,
val isAllowedToStartWebRTCCall: Boolean = true
) : MvRxState {
constructor(args: RoomDetailArgs) : this(

View File

@ -89,6 +89,7 @@
<string name="missing_permissions_error">"Due to missing permissions, this action is not possible.</string>
<string name="missing_permissions_to_start_conf_call">You need permission to invite to start a conference in this room</string>
<string name="no_permissions_to_start_conf_call">You do not have permission to start a conference call in this room</string>
<string name="no_permissions_to_start_webrtc_call">You do not have permission to start a call in this room</string>
<string name="conference_call_in_progress">A conference is already in progress!</string>
<string name="video_meeting">Start video meeting</string>
<string name="audio_meeting">Start audio meeting</string>