Commit 8ca07df9 authored by Valere's avatar Valere

Fixes #3379 revoke permission

parent c80f2cc1
......@@ -243,12 +243,18 @@ class RoomWidgetFragment : VectorBaseMvRxFragment(), HandleBackParticipant {
openUrlInExternalBrowser(requireContext(), state.formattedURL.invoke())
return@withState true
}
R.id.action_revoke -> if (state.status == WidgetState.WIDGET_ALLOWED) {
viewModel.revokeWidget()
viewModel.doFinish()
return@withState true
}
}
return@withState super.onOptionsItemSelected(item)
}
override fun onPrepareOptionsMenu(menu: Menu?) = withState(viewModel) { state ->
menu?.findItem(R.id.action_close)?.isVisible = state.canManageWidgets
menu?.findItem(R.id.action_revoke)?.isVisible = state.status == WidgetState.WIDGET_ALLOWED
super.onPrepareOptionsMenu(menu)
}
......
......@@ -28,6 +28,7 @@ import im.vector.ui.arch.LiveEvent
import im.vector.widgets.Widget
import im.vector.widgets.WidgetsManager
import org.matrix.androidsdk.MXSession
import org.matrix.androidsdk.core.Log
import org.matrix.androidsdk.core.callback.ApiCallback
import org.matrix.androidsdk.core.model.MatrixError
import org.matrix.androidsdk.data.Room
......@@ -165,7 +166,7 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi
val isAllowed = session
?.integrationManager
?.getKnownWidgetPermissions()
?.find { it.stateEventId == widget.widgetEvent.eventId }
?.find { it.stateEventId == widget.widgetEvent.eventId }
?.allowed
?: false
......@@ -276,6 +277,33 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi
}
}
fun revokeWidget(onFinished: (() -> Unit)? = null) {
setState {
copy(
status = WidgetState.UNKNOWN
)
}
session?.integrationManager?.setWidgetAllowed(widget.widgetEvent?.eventId
?: "", false, object : ApiCallback<Void?> {
override fun onSuccess(info: Void?) {
onFinished?.invoke()
}
override fun onUnexpectedError(e: Exception) {
Log.e(this::class.java.name, e.message)
}
override fun onNetworkError(e: Exception) {
Log.e(this::class.java.name, e.message)
}
override fun onMatrixError(e: MatrixError) {
Log.e(this::class.java.name, e.message)
}
})
}
override fun onCleared() {
super.onCleared()
widgetsManager?.removeListener(mWidgetListener)
......
......@@ -23,4 +23,9 @@
android:title="@string/delete"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_revoke"
android:title="@string/room_widget_revoke_access"
app:showAsAction="never" />
</menu>
\ No newline at end of file
......@@ -1122,6 +1122,7 @@
<string name="room_widget_failed_to_load">Failed to load widget.\n%s</string>
<string name="room_widget_reload">Reload widget</string>
<string name="room_widget_open_in_browser">Open in browser</string>
<string name="room_widget_revoke_access">Revoke access for me</string>
<string name="room_widget_permission_display_name">Your display name</string>
<string name="room_widget_permission_avatar_url">Your avatar URL</string>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment