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 all 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
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ MatrixSdk 🚀:

Features ✨:
- Privacy / Room Widget permissions (#3378)
- Privacy / Widget Permission for jitsi widgets (#3391)

Improvementss 🙌:
-
- Jitsi / Use mx display name in Jitsi conf

Other changes:
- Add User-Interactive Auth to /account/3pid/add (#3333)
Expand Down
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
23 changes: 17 additions & 6 deletions vector/src/main/java/im/vector/activity/JitsiCallActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
import org.jitsi.meet.sdk.JitsiMeetActivityDelegate;
import org.jitsi.meet.sdk.JitsiMeetActivityInterface;
import org.jitsi.meet.sdk.JitsiMeetConferenceOptions;
import org.jitsi.meet.sdk.JitsiMeetUserInfo;
import org.jitsi.meet.sdk.JitsiMeetView;
import org.jitsi.meet.sdk.JitsiMeetViewListener;
import org.matrix.androidsdk.MXSession;
import org.matrix.androidsdk.core.Log;
import org.matrix.androidsdk.data.Room;

import java.net.URL;
import java.util.Map;

import butterknife.BindView;
Expand Down Expand Up @@ -65,7 +67,7 @@ public class JitsiCallActivity extends VectorAppCompatActivity implements JitsiM
/**
* Base server URL
*/
private static final String JITSI_SERVER_URL = "https://jitsi.riot.im/";
public static final String JITSI_SERVER_URL = "https://jitsi.riot.im/";

// the jitsi view
private JitsiMeetView mJitsiView;
Expand Down Expand Up @@ -134,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 All @@ -156,8 +153,22 @@ public void initUiAndData() {
*/
private void loadURL() {
try {
JitsiMeetUserInfo userInfo = new JitsiMeetUserInfo();
userInfo.setDisplayName(mSession.getMyUser().displayname);
try {
String avatarUrl = mSession.getMyUser().avatar_url;
if (avatarUrl != null) {
String downloadableUrl = mSession.getContentManager().getDownloadableUrl(avatarUrl, false);
if (downloadableUrl != null) {
userInfo.setAvatar(new URL(downloadableUrl));
}
}
} catch (Exception e) {
//nop
}
JitsiMeetConferenceOptions jitsiMeetConferenceOptions = new JitsiMeetConferenceOptions.Builder()
.setVideoMuted(!mIsVideoCall)
.setUserInfo(userInfo)
// Configure the title of the screen
// TODO config.putString("callDisplayName", mRoom.getRoomDisplayName(this));
.setRoom(mCallUrl)
Expand Down
34 changes: 29 additions & 5 deletions vector/src/main/java/im/vector/activity/VectorRoomActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
import im.vector.fragments.VectorMessageListFragment;
import im.vector.fragments.VectorReadReceiptsDialogFragment;
import im.vector.fragments.VectorUnknownDevicesFragment;
import im.vector.fragments.roomwidgets.RoomWidgetPermissionBottomSheet;
import im.vector.listeners.IMessagesAdapterActionsListener;
import im.vector.ui.themes.ThemeUtils;
import im.vector.util.CallsManager;
Expand All @@ -128,6 +129,7 @@
import im.vector.util.ReadMarkerManager;
import im.vector.util.RoomUtils;
import im.vector.util.SlashCommandsParser;
import im.vector.util.UrlUtilKt;
import im.vector.util.VectorMarkdownParser;
import im.vector.util.VectorRoomMediasSender;
import im.vector.util.VectorUtils;
Expand All @@ -138,6 +140,7 @@
import im.vector.view.VectorPendingCallView;
import im.vector.widgets.Widget;
import im.vector.widgets.WidgetsManager;
import kotlin.Unit;

/**
* Displays a single room with messages.
Expand Down Expand Up @@ -924,7 +927,7 @@ public void onClick(final List<Widget> widgets) {
}

new AlertDialog.Builder(VectorRoomActivity.this)
.setItems(widgetNames.toArray(CharSequences), new DialogInterface.OnClickListener() {
.setItems(widgetNames.toArray(CharSequences), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int n) {
d.cancel();
Expand Down Expand Up @@ -1765,10 +1768,31 @@ private void launchJitsiActivity(Widget widget, boolean aIsVideoCall) {
.setPositiveButton(R.string.ok, null)
.show();
} else {
final Intent intent = new Intent(this, JitsiCallActivity.class);
intent.putExtra(JitsiCallActivity.EXTRA_WIDGET_ID, widget);
intent.putExtra(JitsiCallActivity.EXTRA_ENABLE_VIDEO, aIsVideoCall);
startActivity(intent);
//Here check native widget perm

String domain = UrlUtilKt.extractDomain(JitsiCallActivity.JITSI_SERVER_URL);
if (domain == null) return; //display a toast?
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);
intent.putExtra(JitsiCallActivity.EXTRA_ENABLE_VIDEO, aIsVideoCall);
startActivity(intent);
} else {
//we need to prompt for permissions
RoomWidgetPermissionBottomSheet bs = RoomWidgetPermissionBottomSheet.Companion
.newInstance(mSession.getMyUserId(), widget);
bs.setOnFinish((accepted) -> {
if (accepted) {
final Intent intent = new Intent(this, JitsiCallActivity.class);
intent.putExtra(JitsiCallActivity.EXTRA_WIDGET_ID, widget);
intent.putExtra(JitsiCallActivity.EXTRA_ENABLE_VIDEO, aIsVideoCall);
startActivity(intent);
}
return Unit.INSTANCE;
});
bs.show(getSupportFragmentManager(), "JitsiPerm");
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion vector/src/main/java/im/vector/activity/WidgetActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ class WidgetActivity : VectorAppCompatActivity() {
//already there
} else {
RoomWidgetPermissionBottomSheet
.newInstance(viewModel.session!!.myUserId, viewModel.widget)
.newInstance(viewModel.session!!.myUserId, viewModel.widget).apply {
Copy link
Member

Choose a reason for hiding this comment

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

Does this code is robust to screen rotation, will the bottomSheet is displayed?

Copy link
Member Author

Choose a reason for hiding this comment

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

worst case you have to tap again on the video conf banner

onFinish = { accepted ->
if (!accepted) finish()
}
}
.show(supportFragmentManager, FRAGMENT_TAG_PERMISSION)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,9 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref

//Disable it while updating the state, will be re-enabled by the account data listener.
it.isEnabled = false
mSession.enableIntegrationManagerUsage(newValue as Boolean, object : ApiCallback<Void> {
mSession.integrationManager.enableIntegrationManagerUsage(newValue as Boolean, object : ApiCallback<Void> {
override fun onSuccess(info: Void?) {
//nop
refreshIntegrationManagerSettings()
}

override fun onUnexpectedError(e: java.lang.Exception?) {
Expand Down Expand Up @@ -2038,7 +2038,7 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref
mSession.identityServerManager.checkAdd3pidInteractiveFlow(listOf(LoginRestClient.LOGIN_FLOW_TYPE_PASSWORD),
object : ApiCallback<IdentityServerManager.SupportedFlowResult> {
override fun onSuccess(info: IdentityServerManager.SupportedFlowResult) {
addEmailBtn.isEnabled = info == IdentityServerManager.SupportedFlowResult.SUPPORTED
addEmailBtn.isEnabled = info == IdentityServerManager.SupportedFlowResult.SUPPORTED
|| info == IdentityServerManager.SupportedFlowResult.INTERACTIVE_AUTH_NOT_SUPPORTED
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import android.widget.TextView
import butterknife.BindView
import butterknife.OnClick
import com.airbnb.mvrx.MvRx
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.R
Expand All @@ -53,8 +52,8 @@ class RoomWidgetPermissionBottomSheet : VectorBaseBottomSheetDialogFragment() {

@BindView(R.id.bottom_sheet_widget_permission_owner_avatar)
lateinit var authorAvatarView: ImageView

private val sharedActivityViewModel: RoomWidgetViewModel by activityViewModel()
var onFinish: ((Boolean) -> Unit)? = null
Copy link
Member

Choose a reason for hiding this comment

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

The sharedViewModel was better, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

It makes the bottom sheet more generic, can be used in other activity easier


override fun invalidate() = withState(viewModel) { state ->

Expand All @@ -63,9 +62,13 @@ class RoomWidgetPermissionBottomSheet : VectorBaseBottomSheetDialogFragment() {
VectorUtils.loadUserAvatar(requireContext(), viewModel.session, authorAvatarView,
state.authorAvatarUrl, state.authorId, state.authorName)

val domain = state.widgetDomain ?: ""
val infoBuilder = SpannableStringBuilder()
.append(getString(R.string.room_widget_permission_shared_info_title, "'${state.widgetDomain
?: ""}'"))
.append(getString(
R.string.room_widget_permission_webview_shared_info_title
.takeIf { state.isWebviewWidget }
?: R.string.room_widget_permission_shared_info_title,
"'$domain'"))
infoBuilder.append("\n")

state.permissionsList?.forEach {
Expand Down Expand Up @@ -94,19 +97,21 @@ class RoomWidgetPermissionBottomSheet : VectorBaseBottomSheetDialogFragment() {
viewModel.blockWidget()
//optimistic dismiss
dismiss()
sharedActivityViewModel.doFinish()
onFinish?.invoke(false)
}

@OnClick(R.id.bottom_sheet_widget_permission_continue_button)
fun doAccept() {
viewModel.allowWidget()
onFinish?.invoke(true)
//optimistic dismiss
dismiss()

}

override fun onCancel(dialog: DialogInterface?) {
super.onCancel(dialog)
sharedActivityViewModel.doFinish()
onFinish?.invoke(false)
}

@Parcelize
Expand Down
Loading