diff --git a/CHANGES.md b/CHANGES.md
index 4058dcda6b..c25e804670 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -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
diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt
index 7635c3042d..6acdcc5aa6 100644
--- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt
+++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt
@@ -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)
}
diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt
index 9b2239bd4b..9709303803 100644
--- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt
+++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt
@@ -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
)
}
}
diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt
index a031803fa6..16a7379b6a 100644
--- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt
+++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt
@@ -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(
diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml
index a32f3f6a4e..3d945f3cfd 100644
--- a/vector/src/main/res/values/strings.xml
+++ b/vector/src/main/res/values/strings.xml
@@ -89,6 +89,7 @@
"Due to missing permissions, this action is not possible.
You need permission to invite to start a conference in this room
You do not have permission to start a conference call in this room
+ You do not have permission to start a call in this room
A conference is already in progress!
Start video meeting
Start audio meeting