Merge pull request #7054 from vector-im/feature/bma/fix_invite_to_room_in_space

Fix invite to room in space
This commit is contained in:
Benoit Marty 2022-09-07 11:53:34 +02:00 committed by GitHub
commit c408621bd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 102 additions and 115 deletions

1
changelog.d/7054.bugfix Normal file
View file

@ -0,0 +1 @@
Fix invite to room when in a space buttons not working.

View file

@ -377,7 +377,7 @@ class HomeActivity :
lifecycleScope.launch {
val isHandled = permalinkHandler.launch(
context = this@HomeActivity,
fragmentActivity = this@HomeActivity,
deepLink = resolvedLink,
navigationInterceptor = this@HomeActivity,
buildTask = true

View file

@ -232,9 +232,10 @@ class HomeDetailFragment :
viewBinder = VerificationVectorAlert.ViewBinder(user, avatarRenderer)
colorInt = colorProvider.getColorFromAttribute(R.attr.colorPrimary)
contentAction = Runnable {
(weakCurrentActivity?.get() as? VectorBaseActivity<*>)
?.navigator
?.requestSessionVerification(requireContext(), newest.deviceId ?: "")
(weakCurrentActivity?.get() as? VectorBaseActivity<*>)?.let { vectorBaseActivity ->
vectorBaseActivity.navigator
.requestSessionVerification(vectorBaseActivity, newest.deviceId ?: "")
}
unknownDeviceDetectorSharedViewModel.handle(
UnknownDeviceDetectorSharedViewModel.Action.IgnoreDevice(newest.deviceId?.let { listOf(it) }.orEmpty())
)

View file

@ -250,9 +250,10 @@ class NewHomeDetailFragment :
viewBinder = VerificationVectorAlert.ViewBinder(user, avatarRenderer)
colorInt = colorProvider.getColorFromAttribute(R.attr.colorPrimary)
contentAction = Runnable {
(weakCurrentActivity?.get() as? VectorBaseActivity<*>)
?.navigator
?.requestSessionVerification(requireContext(), newest.deviceId ?: "")
(weakCurrentActivity?.get() as? VectorBaseActivity<*>)?.let { vectorBaseActivity ->
vectorBaseActivity.navigator
.requestSessionVerification(vectorBaseActivity, newest.deviceId ?: "")
}
unknownDeviceDetectorSharedViewModel.handle(
UnknownDeviceDetectorSharedViewModel.Action.IgnoreDevice(newest.deviceId?.let { listOf(it) }.orEmpty())
)

View file

@ -497,7 +497,7 @@ class TimelineFragment :
RoomDetailViewEvents.HideWaitingView -> vectorBaseActivity.hideWaitingView()
is RoomDetailViewEvents.RequestNativeWidgetPermission -> requestNativeWidgetPermission(it)
is RoomDetailViewEvents.OpenRoom -> handleOpenRoom(it)
RoomDetailViewEvents.OpenInvitePeople -> navigator.openInviteUsersToRoom(requireContext(), timelineArgs.roomId)
RoomDetailViewEvents.OpenInvitePeople -> navigator.openInviteUsersToRoom(requireActivity(), timelineArgs.roomId)
RoomDetailViewEvents.OpenSetRoomAvatarDialog -> galleryOrCameraDialogHelper.show()
RoomDetailViewEvents.OpenRoomSettings -> handleOpenRoomSettings(RoomProfileActivity.EXTRA_DIRECT_ACCESS_ROOM_SETTINGS)
RoomDetailViewEvents.OpenRoomProfile -> handleOpenRoomSettings()
@ -2190,7 +2190,7 @@ class TimelineFragment :
override fun onRoomCreateLinkClicked(url: String) {
viewLifecycleOwner.lifecycleScope.launchWhenResumed {
permalinkHandler
.launch(requireContext(), url, object : NavigationInterceptor {
.launch(requireActivity(), url, object : NavigationInterceptor {
override fun navToRoom(roomId: String?, eventId: String?, deepLink: Uri?, rootThreadEventId: String?): Boolean {
requireActivity().finish()
return false

View file

@ -188,7 +188,7 @@ class RoomListFragment :
}
private fun handleShowMxToLink(link: String) {
navigator.openMatrixToBottomSheet(requireContext(), link, OriginOfMatrixTo.ROOM_LIST)
navigator.openMatrixToBottomSheet(requireActivity(), link, OriginOfMatrixTo.ROOM_LIST)
}
override fun onDestroyView() {

View file

@ -25,11 +25,11 @@ import android.view.View
import android.view.Window
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityOptionsCompat
import androidx.core.app.TaskStackBuilder
import androidx.core.util.Pair
import androidx.core.view.ViewCompat
import androidx.fragment.app.FragmentActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.SpaceStateHandler
@ -224,75 +224,65 @@ class DefaultNavigator @Inject constructor(
startActivity(context, SpacePreviewActivity.newIntent(context, spaceId), false)
}
override fun performDeviceVerification(context: Context, otherUserId: String, sasTransactionId: String) {
override fun performDeviceVerification(fragmentActivity: FragmentActivity, otherUserId: String, sasTransactionId: String) {
val session = sessionHolder.getSafeActiveSession() ?: return
val tx = session.cryptoService().verificationService().getExistingTransaction(otherUserId, sasTransactionId)
?: return
(tx as? IncomingSasVerificationTransaction)?.performAccept()
if (context is AppCompatActivity) {
VerificationBottomSheet.withArgs(
roomId = null,
otherUserId = otherUserId,
transactionId = sasTransactionId
).show(context.supportFragmentManager, "REQPOP")
}
VerificationBottomSheet.withArgs(
roomId = null,
otherUserId = otherUserId,
transactionId = sasTransactionId
).show(fragmentActivity.supportFragmentManager, "REQPOP")
}
override fun requestSessionVerification(context: Context, otherSessionId: String) {
override fun requestSessionVerification(fragmentActivity: FragmentActivity, otherSessionId: String) {
val session = sessionHolder.getSafeActiveSession() ?: return
val pr = session.cryptoService().verificationService().requestKeyVerification(
supportedVerificationMethodsProvider.provide(),
session.myUserId,
listOf(otherSessionId)
)
if (context is AppCompatActivity) {
VerificationBottomSheet.withArgs(
roomId = null,
otherUserId = session.myUserId,
transactionId = pr.transactionId
).show(context.supportFragmentManager, VerificationBottomSheet.WAITING_SELF_VERIF_TAG)
}
VerificationBottomSheet.withArgs(
roomId = null,
otherUserId = session.myUserId,
transactionId = pr.transactionId
).show(fragmentActivity.supportFragmentManager, VerificationBottomSheet.WAITING_SELF_VERIF_TAG)
}
override fun requestSelfSessionVerification(context: Context) {
override fun requestSelfSessionVerification(fragmentActivity: FragmentActivity) {
val session = sessionHolder.getSafeActiveSession() ?: return
val otherSessions = session.cryptoService()
.getCryptoDeviceInfo(session.myUserId)
.filter { it.deviceId != session.sessionParams.deviceId }
.map { it.deviceId }
if (context is AppCompatActivity) {
if (otherSessions.isNotEmpty()) {
val pr = session.cryptoService().verificationService().requestKeyVerification(
supportedVerificationMethodsProvider.provide(),
session.myUserId,
otherSessions
)
VerificationBottomSheet.forSelfVerification(session, pr.transactionId ?: pr.localId)
.show(context.supportFragmentManager, VerificationBottomSheet.WAITING_SELF_VERIF_TAG)
} else {
VerificationBottomSheet.forSelfVerification(session)
.show(context.supportFragmentManager, VerificationBottomSheet.WAITING_SELF_VERIF_TAG)
}
}
}
override fun waitSessionVerification(context: Context) {
val session = sessionHolder.getSafeActiveSession() ?: return
if (context is AppCompatActivity) {
VerificationBottomSheet.forSelfVerification(session)
.show(context.supportFragmentManager, VerificationBottomSheet.WAITING_SELF_VERIF_TAG)
}
}
override fun upgradeSessionSecurity(context: Context, initCrossSigningOnly: Boolean) {
if (context is AppCompatActivity) {
BootstrapBottomSheet.show(
context.supportFragmentManager,
if (initCrossSigningOnly) SetupMode.CROSS_SIGNING_ONLY else SetupMode.NORMAL
if (otherSessions.isNotEmpty()) {
val pr = session.cryptoService().verificationService().requestKeyVerification(
supportedVerificationMethodsProvider.provide(),
session.myUserId,
otherSessions
)
VerificationBottomSheet.forSelfVerification(session, pr.transactionId ?: pr.localId)
.show(fragmentActivity.supportFragmentManager, VerificationBottomSheet.WAITING_SELF_VERIF_TAG)
} else {
VerificationBottomSheet.forSelfVerification(session)
.show(fragmentActivity.supportFragmentManager, VerificationBottomSheet.WAITING_SELF_VERIF_TAG)
}
}
override fun waitSessionVerification(fragmentActivity: FragmentActivity) {
val session = sessionHolder.getSafeActiveSession() ?: return
VerificationBottomSheet.forSelfVerification(session)
.show(fragmentActivity.supportFragmentManager, VerificationBottomSheet.WAITING_SELF_VERIF_TAG)
}
override fun upgradeSessionSecurity(fragmentActivity: FragmentActivity, initCrossSigningOnly: Boolean) {
BootstrapBottomSheet.show(
fragmentActivity.supportFragmentManager,
if (initCrossSigningOnly) SetupMode.CROSS_SIGNING_ONLY else SetupMode.NORMAL
)
}
override fun openRoomMemberProfile(userId: String, roomId: String?, context: Context, buildTask: Boolean) {
val args = RoomMemberProfileArgs(userId = userId, roomId = roomId)
val intent = RoomMemberProfileActivity.newIntent(context, args)
@ -316,16 +306,14 @@ class DefaultNavigator @Inject constructor(
context.startActivity(intent)
}
override fun openMatrixToBottomSheet(context: Context, link: String, origin: OriginOfMatrixTo) {
if (context is AppCompatActivity) {
if (context !is MatrixToBottomSheet.InteractionListener) {
fatalError("Caller context should implement MatrixToBottomSheet.InteractionListener", vectorPreferences.failFast())
return
}
// TODO check if there is already one??
MatrixToBottomSheet.withLink(link, origin)
.show(context.supportFragmentManager, "HA#MatrixToBottomSheet")
override fun openMatrixToBottomSheet(fragmentActivity: FragmentActivity, link: String, origin: OriginOfMatrixTo) {
if (fragmentActivity !is MatrixToBottomSheet.InteractionListener) {
fatalError("Caller context should implement MatrixToBottomSheet.InteractionListener", vectorPreferences.failFast())
return
}
// TODO check if there is already one??
MatrixToBottomSheet.withLink(link, origin)
.show(fragmentActivity.supportFragmentManager, "HA#MatrixToBottomSheet")
}
override fun openRoomDirectory(context: Context, initialFilter: String) {
@ -347,18 +335,16 @@ class DefaultNavigator @Inject constructor(
}.start(context)
}
override fun openInviteUsersToRoom(context: Context, roomId: String) {
override fun openInviteUsersToRoom(fragmentActivity: FragmentActivity, roomId: String) {
when (val currentSpace = spaceStateHandler.getCurrentSpace()) {
null -> InviteUsersToRoomActivity.getIntent(context, roomId).start(context)
else -> showInviteToDialog(context, currentSpace, roomId)
null -> InviteUsersToRoomActivity.getIntent(fragmentActivity, roomId).start(fragmentActivity)
else -> showInviteToDialog(fragmentActivity, currentSpace, roomId)
}
}
private fun showInviteToDialog(context: Context, currentSpace: RoomSummary, roomId: String) {
(context as? AppCompatActivity)?.supportFragmentManager?.let { fragmentManager ->
InviteRoomSpaceChooserBottomSheet.showInstance(fragmentManager, currentSpace.roomId, roomId) { itemId ->
InviteUsersToRoomActivity.getIntent(context, itemId).start(context)
}
private fun showInviteToDialog(fragmentActivity: FragmentActivity, currentSpace: RoomSummary, roomId: String) {
InviteRoomSpaceChooserBottomSheet.showInstance(fragmentActivity.supportFragmentManager, currentSpace.roomId, roomId) { itemId ->
InviteUsersToRoomActivity.getIntent(fragmentActivity, itemId).start(fragmentActivity)
}
}
@ -381,24 +367,20 @@ class DefaultNavigator @Inject constructor(
debugNavigator.openDebugMenu(context)
}
override fun openKeysBackupSetup(context: Context, showManualExport: Boolean) {
override fun openKeysBackupSetup(fragmentActivity: FragmentActivity, showManualExport: Boolean) {
// if cross signing is enabled and trusted or not set up at all we should propose full 4S
sessionHolder.getSafeActiveSession()?.let { session ->
if (session.cryptoService().crossSigningService().getMyCrossSigningKeys() == null ||
session.cryptoService().crossSigningService().canCrossSign()) {
(context as? AppCompatActivity)?.let {
BootstrapBottomSheet.show(it.supportFragmentManager, SetupMode.NORMAL)
}
BootstrapBottomSheet.show(fragmentActivity.supportFragmentManager, SetupMode.NORMAL)
} else {
context.startActivity(KeysBackupSetupActivity.intent(context, showManualExport))
fragmentActivity.startActivity(KeysBackupSetupActivity.intent(fragmentActivity, showManualExport))
}
}
}
override fun open4SSetup(context: Context, setupMode: SetupMode) {
if (context is AppCompatActivity) {
BootstrapBottomSheet.show(context.supportFragmentManager, setupMode)
}
override fun open4SSetup(fragmentActivity: FragmentActivity, setupMode: SetupMode) {
BootstrapBottomSheet.show(fragmentActivity.supportFragmentManager, setupMode)
}
override fun openKeysBackupManager(context: Context) {

View file

@ -23,6 +23,7 @@ import android.net.Uri
import android.view.View
import androidx.activity.result.ActivityResultLauncher
import androidx.core.util.Pair
import androidx.fragment.app.FragmentActivity
import im.vector.app.features.analytics.plan.ViewRoom
import im.vector.app.features.crypto.recover.SetupMode
import im.vector.app.features.displayname.getBestName
@ -76,15 +77,15 @@ interface Navigator {
fun openSpacePreview(context: Context, spaceId: String)
fun performDeviceVerification(context: Context, otherUserId: String, sasTransactionId: String)
fun performDeviceVerification(fragmentActivity: FragmentActivity, otherUserId: String, sasTransactionId: String)
fun requestSessionVerification(context: Context, otherSessionId: String)
fun requestSessionVerification(fragmentActivity: FragmentActivity, otherSessionId: String)
fun requestSelfSessionVerification(context: Context)
fun requestSelfSessionVerification(fragmentActivity: FragmentActivity)
fun waitSessionVerification(context: Context)
fun waitSessionVerification(fragmentActivity: FragmentActivity)
fun upgradeSessionSecurity(context: Context, initCrossSigningOnly: Boolean)
fun upgradeSessionSecurity(fragmentActivity: FragmentActivity, initCrossSigningOnly: Boolean)
fun openRoomForSharingAndFinish(activity: Activity, roomId: String, sharedData: SharedData)
@ -92,13 +93,13 @@ interface Navigator {
fun openRoomPreview(context: Context, roomPreviewData: RoomPreviewData, fromEmailInviteLink: PermalinkData.RoomEmailInviteLink? = null)
fun openMatrixToBottomSheet(context: Context, link: String, origin: OriginOfMatrixTo)
fun openMatrixToBottomSheet(fragmentActivity: FragmentActivity, link: String, origin: OriginOfMatrixTo)
fun openCreateRoom(context: Context, initialName: String = "", openAfterCreate: Boolean = true)
fun openCreateDirectRoom(context: Context)
fun openInviteUsersToRoom(context: Context, roomId: String)
fun openInviteUsersToRoom(fragmentActivity: FragmentActivity, roomId: String)
fun openRoomDirectory(context: Context, initialFilter: String = "")
@ -110,9 +111,9 @@ interface Navigator {
fun openDebug(context: Context)
fun openKeysBackupSetup(context: Context, showManualExport: Boolean)
fun openKeysBackupSetup(fragmentActivity: FragmentActivity, showManualExport: Boolean)
fun open4SSetup(context: Context, setupMode: SetupMode)
fun open4SSetup(fragmentActivity: FragmentActivity, setupMode: SetupMode)
fun openKeysBackupManager(context: Context)

View file

@ -19,6 +19,7 @@ package im.vector.app.features.permalink
import android.content.Context
import android.net.Uri
import androidx.core.net.toUri
import androidx.fragment.app.FragmentActivity
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.extensions.isIgnored
@ -52,17 +53,17 @@ class PermalinkHandler @Inject constructor(
) {
suspend fun launch(
context: Context,
fragmentActivity: FragmentActivity,
deepLink: String?,
navigationInterceptor: NavigationInterceptor? = null,
buildTask: Boolean = false
): Boolean {
val uri = deepLink?.let { Uri.parse(it) }
return launch(context, uri, navigationInterceptor, buildTask)
return launch(fragmentActivity, uri, navigationInterceptor, buildTask)
}
suspend fun launch(
context: Context,
fragmentActivity: FragmentActivity,
deepLink: Uri?,
navigationInterceptor: NavigationInterceptor? = null,
buildTask: Boolean = false
@ -70,12 +71,12 @@ class PermalinkHandler @Inject constructor(
return when {
deepLink == null -> false
deepLink.isIgnored() -> true
!isPermalinkSupported(context, deepLink.toString()) -> false
!isPermalinkSupported(fragmentActivity, deepLink.toString()) -> false
else -> {
tryOrNull {
withContext(Dispatchers.Default) {
val permalinkData = PermalinkParser.parse(deepLink)
handlePermalink(permalinkData, deepLink, context, navigationInterceptor, buildTask)
handlePermalink(permalinkData, deepLink, fragmentActivity, navigationInterceptor, buildTask)
}
} ?: false
}
@ -85,22 +86,22 @@ class PermalinkHandler @Inject constructor(
private suspend fun handlePermalink(
permalinkData: PermalinkData,
rawLink: Uri,
context: Context,
fragmentActivity: FragmentActivity,
navigationInterceptor: NavigationInterceptor?,
buildTask: Boolean
): Boolean {
return when (permalinkData) {
is PermalinkData.RoomLink -> handleRoomLink(permalinkData, rawLink, context, navigationInterceptor, buildTask)
is PermalinkData.UserLink -> handleUserLink(permalinkData, rawLink, context, navigationInterceptor, buildTask)
is PermalinkData.FallbackLink -> handleFallbackLink(permalinkData, context)
is PermalinkData.RoomEmailInviteLink -> handleRoomInviteLink(permalinkData, context)
is PermalinkData.RoomLink -> handleRoomLink(permalinkData, rawLink, fragmentActivity, navigationInterceptor, buildTask)
is PermalinkData.UserLink -> handleUserLink(permalinkData, rawLink, fragmentActivity, navigationInterceptor, buildTask)
is PermalinkData.FallbackLink -> handleFallbackLink(permalinkData, fragmentActivity)
is PermalinkData.RoomEmailInviteLink -> handleRoomInviteLink(permalinkData, fragmentActivity)
}
}
private suspend fun handleRoomLink(
permalinkData: PermalinkData.RoomLink,
rawLink: Uri,
context: Context,
fragmentActivity: FragmentActivity,
navigationInterceptor: NavigationInterceptor?,
buildTask: Boolean
): Boolean {
@ -119,7 +120,7 @@ class PermalinkHandler @Inject constructor(
}
openRoom(
navigationInterceptor,
context = context,
fragmentActivity = fragmentActivity,
roomId = roomId,
permalinkData = permalinkData,
rawLink = rawLink,
@ -200,7 +201,7 @@ class PermalinkHandler @Inject constructor(
*/
private fun openRoom(
navigationInterceptor: NavigationInterceptor?,
context: Context,
fragmentActivity: FragmentActivity,
roomId: String?,
permalinkData: PermalinkData.RoomLink,
rawLink: Uri,
@ -209,7 +210,7 @@ class PermalinkHandler @Inject constructor(
) {
val session = activeSessionHolder.getSafeActiveSession() ?: return
if (roomId == null) {
context.toast(R.string.room_error_not_found)
fragmentActivity.toast(R.string.room_error_not_found)
return
}
val roomSummary = session.getRoomSummary(roomId)
@ -218,19 +219,19 @@ class PermalinkHandler @Inject constructor(
// val roomAlias = permalinkData.getRoomAliasOrNull()
val isSpace = roomSummary?.roomType == RoomType.SPACE
return when {
membership == Membership.BAN -> context.toast(R.string.error_opening_banned_room)
membership == Membership.BAN -> fragmentActivity.toast(R.string.error_opening_banned_room)
membership?.isActive().orFalse() -> {
if (!isSpace && membership == Membership.JOIN) {
// If it's a room you're in, let's just open it, you can tap back if needed
navigationInterceptor.openJoinedRoomScreen(buildTask, roomId, eventId, rawLink, context, rootThreadEventId, roomSummary)
navigationInterceptor.openJoinedRoomScreen(buildTask, roomId, eventId, rawLink, fragmentActivity, rootThreadEventId, roomSummary)
} else {
// maybe open space preview navigator.openSpacePreview(context, roomId)? if already joined?
navigator.openMatrixToBottomSheet(context, rawLink.toString(), OriginOfMatrixTo.LINK)
// maybe open space preview navigator.openSpacePreview(fragmentActivity, roomId)? if already joined?
navigator.openMatrixToBottomSheet(fragmentActivity, rawLink.toString(), OriginOfMatrixTo.LINK)
}
}
else -> {
// XXX this could trigger another server load
navigator.openMatrixToBottomSheet(context, rawLink.toString(), OriginOfMatrixTo.LINK)
navigator.openMatrixToBottomSheet(fragmentActivity, rawLink.toString(), OriginOfMatrixTo.LINK)
}
}
}

View file

@ -130,7 +130,7 @@ class PublicRoomsFragment :
viewLifecycleOwner.lifecycleScope.launch {
val permalink = session.permalinkService().createPermalink(roomIdOrAlias)
val isHandled = permalinkHandler
.launch(requireContext(), permalink, object : NavigationInterceptor {
.launch(requireActivity(), permalink, object : NavigationInterceptor {
override fun navToRoom(roomId: String?, eventId: String?, deepLink: Uri?, rootThreadEventId: String?): Boolean {
requireActivity().finish()
return false

View file

@ -76,7 +76,7 @@ class RoomMemberListFragment :
private fun setupInviteUsersButton() {
views.inviteUsersButton.debouncedClicks {
navigator.openInviteUsersToRoom(requireContext(), roomProfileArgs.roomId)
navigator.openInviteUsersToRoom(requireActivity(), roomProfileArgs.roomId)
}
// Hide FAB when list is scrolling
views.roomSettingGeneric.roomSettingsRecyclerView.addOnScrollListener(

View file

@ -94,7 +94,7 @@ class VectorSettingsDevicesFragment :
}
}
is DevicesViewEvents.PromptResetSecrets -> {
navigator.open4SSetup(requireContext(), SetupMode.PASSPHRASE_AND_NEEDED_SECRETS_RESET)
navigator.open4SSetup(requireActivity(), SetupMode.PASSPHRASE_AND_NEEDED_SECRETS_RESET)
}
}
}

View file

@ -99,7 +99,7 @@ class VectorSettingsDevicesFragment :
}
}
is DevicesViewEvents.PromptResetSecrets -> {
navigator.open4SSetup(requireContext(), SetupMode.PASSPHRASE_AND_NEEDED_SECRETS_RESET)
navigator.open4SSetup(requireActivity(), SetupMode.PASSPHRASE_AND_NEEDED_SECRETS_RESET)
}
}
}