Commit cdb4123a authored by Valere's avatar Valere

Fix / widget - hide revoke for me for widget owned by me

parent 788f15f4
......@@ -254,7 +254,7 @@ class RoomWidgetFragment : VectorBaseMvRxFragment(), HandleBackParticipant {
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
menu?.findItem(R.id.action_revoke)?.isVisible = state.status == WidgetState.WIDGET_ALLOWED && !state.createdByMe
super.onPrepareOptionsMenu(menu)
}
......
......@@ -46,7 +46,8 @@ data class RoomWidgetViewModelState(
val formattedURL: Async<String> = Uninitialized,
val webviewLoadedUrl: Async<String> = Uninitialized,
val widgetName: String = "",
val canManageWidgets: Boolean = false
val canManageWidgets: Boolean = false,
val createdByMe: Boolean = false
) : MvRxState
class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Widget)
......@@ -62,9 +63,13 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi
}
override fun initialState(viewModelContext: ViewModelContext): RoomWidgetViewModelState? {
return (viewModelContext.activity.intent?.extras?.getSerializable(WidgetActivity.EXTRA_WIDGET_ID) as? Widget)?.let {
RoomWidgetViewModelState(widgetName = it.humanName)
}
val widget = viewModelContext.activity.intent?.extras?.getSerializable(WidgetActivity.EXTRA_WIDGET_ID) as? Widget
?: return null
val session = Matrix.getInstance(viewModelContext.activity).getSession(widget.sessionId)
return RoomWidgetViewModelState(
widgetName = widget.humanName,
createdByMe = widget.widgetEvent.getSender() == session?.myUserId
)
}
}
......@@ -165,7 +170,7 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi
val isAllowed = session
?.integrationManager
?.isWidgetAllowed( widget.widgetEvent.eventId)
?.isWidgetAllowed(widget.widgetEvent.eventId)
?: false
if (!isAllowed) {
......
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