Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Jitsi Widget Permissions #3393

Merged
merged 6 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class IntegrationManagerActivity : AbstractWidgetActivity() {

Log.d(LOG_TAG, "Received request to get widget in room " + mRoom!!.roomId)

val widgets = widgetManager.getActiveWidgets(mSession, mRoom)
val widgets = WidgetsManager.getActiveWidgets(mSession, mRoom)
val responseData = ArrayList<JsonDict<Any>>()

for (widget in widgets) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ public void initUiAndData() {
return;
}

if (getWidgetManager() == null) {
finish();
return;
}

mRoom = mSession.getDataHandler().getRoom(mWidget.getRoomId());
if (null == mRoom) {
Log.e(LOG_TAG, "## onCreate() : undefined room " + mWidget.getRoomId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,7 @@ private void launchJitsiActivity(Widget widget, boolean aIsVideoCall) {

String domain = UrlUtilKt.extractDomain(JitsiCallActivity.JITSI_SERVER_URL);
if (domain == null) return; //display a toast?
boolean isAllowed = mSession.getIntegrationManager().isVideoConfDomainAllowed(domain);
boolean isAllowed = mSession.getIntegrationManager().isNativeWidgetAllowed("jitsi", domain);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if (isAllowed) {
final Intent intent = new Intent(this, JitsiCallActivity.class);
intent.putExtra(JitsiCallActivity.EXTRA_WIDGET_ID, widget);
Expand All @@ -1791,7 +1791,7 @@ private void launchJitsiActivity(Widget widget, boolean aIsVideoCall) {
}
return Unit.INSTANCE;
});
bs.show(getSupportFragmentManager(), "JitsyPerm");
bs.show(getSupportFragmentManager(), "JitsiPerm");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class RoomWidgetPermissionViewModel(val session: MXSession, val widget: Widget,

})
} else {
session.integrationManager.seVideoConfDomainAllowed(state.widgetDomain
session.integrationManager.setNativeWidgetDomainAllowed("jitsi", state.widgetDomain
?: "", true, object : SimpleApiCallback<Void?>() {

override fun onSuccess(info: Void?) {
Expand All @@ -75,7 +75,7 @@ class RoomWidgetPermissionViewModel(val session: MXSession, val widget: Widget,

})
} else {
session.integrationManager.seVideoConfDomainAllowed(state.widgetDomain
session.integrationManager.setNativeWidgetDomainAllowed("jitsi", state.widgetDomain
?: "", false, object : SimpleApiCallback<Void?>() {

override fun onSuccess(info: Void?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ class RoomWidgetViewModel(initialState: RoomWidgetViewModelState, val widget: Wi

val isAllowed = session
?.integrationManager
?.getKnownWidgetPermissions()
?.find { it.stateEventId == widget.widgetEvent.eventId }
?.allowed
?.isWidgetAllowed( widget.widgetEvent.eventId)
?: false

if (!isAllowed) {
Expand Down
8 changes: 2 additions & 6 deletions vector/src/main/java/im/vector/view/ActiveWidgetsBanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,8 @@ public void setOnUpdateListener(onUpdateListener listener) {
* Refresh the view visibility
*/
private void refresh() {
WidgetsManager wm = getWidgetManager(getContext());
if (wm == null) {
return;
}
if ((null != mRoom) && (null != mSession)) {
List<Widget> activeWidgets = wm.getActiveWebviewWidgets(mSession, mRoom);
List<Widget> activeWidgets = WidgetsManager.getActiveWebviewWidgets(mSession, mRoom);
Widget firstWidget = null;

if ((activeWidgets.size() != mActiveWidgets.size()) || !mActiveWidgets.containsAll(activeWidgets)) {
Expand All @@ -202,7 +198,7 @@ private void refresh() {
setVisibility((mActiveWidgets.size() > 0) ? View.VISIBLE : View.GONE);

// show the close widget button if the user is allowed to do it
mCloseWidgetIcon.setVisibility(((null != firstWidget) && (null == wm.checkWidgetPermission(mSession, mRoom))) ?
mCloseWidgetIcon.setVisibility(((null != firstWidget) && (null == WidgetsManager.checkWidgetPermission(mSession, mRoom))) ?
View.VISIBLE : View.GONE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,8 @@ public void setCallClickListener(ICallClickListener callClickListener) {
* Refresh the view visibility
*/
public void refresh() {
WidgetsManager wm = Matrix.getWidgetManager(getContext());
if (wm == null) {
return;
}
if ((null != mRoom) && (null != mSession)) {
List<Widget> mActiveWidgets = wm.getActiveJitsiWidgets(mSession, mRoom);
List<Widget> mActiveWidgets = WidgetsManager.getActiveJitsiWidgets(mSession, mRoom);
Widget widget = mActiveWidgets.isEmpty() ? null : mActiveWidgets.get(0);

if (mActiveWidget != widget) {
Expand All @@ -266,7 +262,7 @@ public void refresh() {
setVisibility(((!MXCallsManager.isCallInProgress(call) && mRoom.isOngoingConferenceCall()) || (null != mActiveWidget)) ? View.VISIBLE : View.GONE);

// show the close widget button if the user is allowed to do it
mCloseWidgetIcon.setVisibility(((null != mActiveWidget) && (null == wm.checkWidgetPermission(mSession, mRoom))) ?
mCloseWidgetIcon.setVisibility(((null != mActiveWidget) && (null == WidgetsManager.checkWidgetPermission(mSession, mRoom))) ?
View.VISIBLE : View.GONE);
}
}
Expand Down
8 changes: 4 additions & 4 deletions vector/src/main/java/im/vector/widgets/WidgetsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public String getUIUrl() {
* @param room the room to check.
* @return the active widgets list
*/
public List<Widget> getActiveWidgets(MXSession session, Room room) {
public static List<Widget> getActiveWidgets(MXSession session, Room room) {
return getActiveWidgets(session, room, null, null);
}

Expand Down Expand Up @@ -124,7 +124,7 @@ public static Boolean isJitsiWidget(Widget widget) {
* @param excludedTypes the excluded widget types
* @return the active widgets list
*/
private List<Widget> getActiveWidgets(final MXSession session, final Room room, final Set<String> widgetTypes, final Set<String> excludedTypes) {
private static List<Widget> getActiveWidgets(final MXSession session, final Room room, final Set<String> widgetTypes, final Set<String> excludedTypes) {
// Get all im.vector.modular.widgets state events in the room
List<Event> widgetEvents = room.getState().getStateEvents(new HashSet<>(Arrays.asList(WIDGET_EVENT_TYPE)));

Expand Down Expand Up @@ -210,7 +210,7 @@ public int compare(Event e1, Event e2) {
* @param room the room
* @return the list of active widgets
*/
public List<Widget> getActiveJitsiWidgets(final MXSession session, final Room room) {
public static List<Widget> getActiveJitsiWidgets(final MXSession session, final Room room) {
return getActiveWidgets(session, room, new HashSet<>(Arrays.asList(WidgetsManager.WIDGET_TYPE_JITSI)), null);
}

Expand All @@ -221,7 +221,7 @@ public List<Widget> getActiveJitsiWidgets(final MXSession session, final Room ro
* @param room the room
* @return the list of active widgets
*/
public List<Widget> getActiveWebviewWidgets(final MXSession session, final Room room) {
public static List<Widget> getActiveWebviewWidgets(final MXSession session, final Room room) {
return getActiveWidgets(session, room, null, new HashSet<>(Arrays.asList(WidgetsManager.WIDGET_TYPE_JITSI)));
}

Expand Down
6 changes: 3 additions & 3 deletions vector/src/main/res/menu/menu_room_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
android:icon="@drawable/ic_widget_refresh"
android:iconTint="?attr/vctr_icon_tint_on_dark_action_bar_color"
android:title="@string/room_widget_reload"
app:showAsAction="ifRoom" />
app:showAsAction="never" />

<item
android:id="@+id/action_widget_open_ext"
android:icon="@drawable/ic_widget_external_link"
android:iconTint="?attr/vctr_icon_tint_on_dark_action_bar_color"
android:title="@string/room_widget_open_in_browser"
app:showAsAction="ifRoom" />
app:showAsAction="never" />

<item
android:id="@+id/action_close"
android:icon="@drawable/ic_widget_bin"
android:iconTint="@color/vector_error_color"
android:title="@string/delete"
app:showAsAction="ifRoom" />
app:showAsAction="never" />

<item
android:id="@+id/action_revoke"
Expand Down