Start reusing RoomPreview for joining room not joined

This commit is contained in:
ganfra 2020-08-25 12:35:35 +02:00
parent c1c8c04567
commit 8f1eff8782
5 changed files with 53 additions and 23 deletions

View File

@ -54,6 +54,7 @@ import im.vector.app.features.pin.PinMode
import im.vector.app.features.roomdirectory.RoomDirectoryActivity
import im.vector.app.features.roomdirectory.createroom.CreateRoomActivity
import im.vector.app.features.roomdirectory.roompreview.RoomPreviewActivity
import im.vector.app.features.roomdirectory.roompreview.RoomPreviewData
import im.vector.app.features.roommemberprofile.RoomMemberProfileActivity
import im.vector.app.features.roommemberprofile.RoomMemberProfileArgs
import im.vector.app.features.roomprofile.RoomProfileActivity
@ -64,6 +65,7 @@ import im.vector.app.features.terms.ReviewTermsActivity
import im.vector.app.features.widgets.WidgetActivity
import im.vector.app.features.widgets.WidgetArgsBuilder
import org.matrix.android.sdk.api.session.crypto.verification.IncomingSasVerificationTransaction
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoom
import org.matrix.android.sdk.api.session.room.model.thirdparty.RoomDirectoryData
import org.matrix.android.sdk.api.session.terms.TermsService
@ -156,12 +158,16 @@ class DefaultNavigator @Inject constructor(
}
}
override fun openNotJoinedRoom(context: Context, roomIdOrAlias: String?, eventId: String?, buildTask: Boolean) {
if (context is VectorBaseActivity) {
context.notImplemented("Open not joined room")
} else {
context.toast(R.string.not_implemented)
}
override fun openNotJoinedRoom(context: Context, roomId: String, eventId: String?, roomSummary: RoomSummary?, buildTask: Boolean) {
val roomPreviewData = RoomPreviewData(
roomId = roomId,
eventId = eventId,
roomAlias = roomSummary?.canonicalAlias,
roomName = roomSummary?.displayName,
avatarUrl = roomSummary?.avatarUrl
)
val intent = RoomPreviewActivity.newIntent(context, roomPreviewData)
context.startActivity(intent)
}
override fun openGroupDetail(groupId: String, context: Context, buildTask: Boolean) {

View File

@ -28,6 +28,7 @@ import im.vector.app.features.pin.PinMode
import im.vector.app.features.settings.VectorSettingsActivity
import im.vector.app.features.share.SharedData
import im.vector.app.features.terms.ReviewTermsActivity
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoom
import org.matrix.android.sdk.api.session.room.model.thirdparty.RoomDirectoryData
import org.matrix.android.sdk.api.session.terms.TermsService
@ -50,7 +51,7 @@ interface Navigator {
fun openRoomForSharingAndFinish(activity: Activity, roomId: String, sharedData: SharedData)
fun openNotJoinedRoom(context: Context, roomIdOrAlias: String?, eventId: String? = null, buildTask: Boolean = false)
fun openNotJoinedRoom(context: Context, roomId: String, eventId: String? = null, roomSummary: RoomSummary?, buildTask: Boolean = false)
fun openRoomPreview(context: Context, publicRoom: PublicRoom, roomDirectoryData: RoomDirectoryData)

View File

@ -19,12 +19,15 @@ package im.vector.app.features.permalink
import android.content.Context
import android.net.Uri
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.utils.toast
import im.vector.app.features.navigation.Navigator
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.permalinks.PermalinkData
import org.matrix.android.sdk.api.session.permalinks.PermalinkParser
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.rx.rx
import javax.inject.Inject
@ -82,8 +85,7 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti
private fun PermalinkData.RoomLink.getRoomId(): Single<Optional<String>> {
val session = activeSessionHolder.getSafeActiveSession()
return if (isRoomAlias && session != null) {
// At the moment we are not fetching on the server as we don't handle not join room
session.rx().getRoomIdByAlias(roomIdOrAlias, false).subscribeOn(Schedulers.io())
session.rx().getRoomIdByAlias(roomIdOrAlias, true).subscribeOn(Schedulers.io())
} else {
Single.just(Optional.from(roomIdOrAlias))
}
@ -94,10 +96,21 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti
*/
private fun openRoom(context: Context, roomId: String?, eventId: String?, buildTask: Boolean) {
val session = activeSessionHolder.getSafeActiveSession() ?: return
return if (roomId != null && session.getRoom(roomId) != null) {
navigator.openRoom(context, roomId, eventId, buildTask)
} else {
navigator.openNotJoinedRoom(context, roomId, eventId, buildTask)
if (roomId == null) {
context.toast("Couldn't get roomId in permalink data.")
return
}
val roomSummary = session.getRoomSummary(roomId)
return when {
roomSummary?.membership?.isActive().orFalse() -> {
navigator.openRoom(context, roomId, eventId, buildTask)
}
roomSummary?.membership != Membership.BAN -> {
navigator.openNotJoinedRoom(context, roomId, eventId, roomSummary, buildTask)
}
else -> {
context.toast("Can't open a room where you are banned from.")
}
}
}
}

View File

@ -24,20 +24,22 @@ import im.vector.app.R
import im.vector.app.core.extensions.addFragment
import im.vector.app.core.platform.ToolbarConfigurable
import im.vector.app.core.platform.VectorBaseActivity
import kotlinx.android.parcel.Parcelize
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoom
import org.matrix.android.sdk.api.session.room.model.thirdparty.RoomDirectoryData
import org.matrix.android.sdk.api.util.MatrixItem
import kotlinx.android.parcel.Parcelize
@Parcelize
data class RoomPreviewData(
val roomId: String,
val roomName: String?,
val roomAlias: String?,
val topic: String?,
val worldReadable: Boolean,
val avatarUrl: String?,
val homeServer: String?
val eventId: String? = null,
val roomName: String? = null,
val roomAlias: String? = null,
val topic: String? = null,
val worldReadable: Boolean = false,
val avatarUrl: String? = null,
val homeServer: String? = null,
val buildTask: Boolean = false
) : Parcelable {
val matrixItem: MatrixItem
get() = MatrixItem.RoomItem(roomId, roomName ?: roomAlias, avatarUrl)
@ -48,6 +50,12 @@ class RoomPreviewActivity : VectorBaseActivity(), ToolbarConfigurable {
companion object {
private const val ARG = "ARG"
fun newIntent(context: Context, roomPreviewData: RoomPreviewData): Intent {
return Intent(context, RoomPreviewActivity::class.java).apply {
putExtra(ARG, roomPreviewData)
}
}
fun getIntent(context: Context, publicRoom: PublicRoom, roomDirectoryData: RoomDirectoryData): Intent {
return Intent(context, RoomPreviewActivity::class.java).apply {
putExtra(ARG, RoomPreviewData(

View File

@ -48,13 +48,15 @@ class RoomPreviewNoPreviewFragment @Inject constructor(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupToolbar(roomPreviewNoPreviewToolbar)
val titleText = roomPreviewData.roomName ?: roomPreviewData.roomAlias ?: roomPreviewData.roomId
// Toolbar
avatarRenderer.render(roomPreviewData.matrixItem, roomPreviewNoPreviewToolbarAvatar)
roomPreviewNoPreviewToolbarTitle.text = roomPreviewData.roomName ?: roomPreviewData.roomAlias
roomPreviewNoPreviewToolbarTitle.text = titleText
// Screen
avatarRenderer.render(roomPreviewData.matrixItem, roomPreviewNoPreviewAvatar)
roomPreviewNoPreviewName.text = roomPreviewData.roomName ?: roomPreviewData.roomAlias
roomPreviewNoPreviewName.text = titleText
roomPreviewNoPreviewTopic.setTextOrHide(roomPreviewData.topic)
if (roomPreviewData.worldReadable) {
@ -98,7 +100,7 @@ class RoomPreviewNoPreviewFragment @Inject constructor(
// Quit this screen
requireActivity().finish()
// Open room
navigator.openRoom(requireActivity(), roomPreviewData.roomId)
navigator.openRoom(requireActivity(), roomPreviewData.roomId, roomPreviewData.eventId, roomPreviewData.buildTask)
}
}
}