Start reusing RoomPreview for joining room not joined
This commit is contained in:
parent
c1c8c04567
commit
8f1eff8782
|
@ -54,6 +54,7 @@ import im.vector.app.features.pin.PinMode
|
||||||
import im.vector.app.features.roomdirectory.RoomDirectoryActivity
|
import im.vector.app.features.roomdirectory.RoomDirectoryActivity
|
||||||
import im.vector.app.features.roomdirectory.createroom.CreateRoomActivity
|
import im.vector.app.features.roomdirectory.createroom.CreateRoomActivity
|
||||||
import im.vector.app.features.roomdirectory.roompreview.RoomPreviewActivity
|
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.RoomMemberProfileActivity
|
||||||
import im.vector.app.features.roommemberprofile.RoomMemberProfileArgs
|
import im.vector.app.features.roommemberprofile.RoomMemberProfileArgs
|
||||||
import im.vector.app.features.roomprofile.RoomProfileActivity
|
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.WidgetActivity
|
||||||
import im.vector.app.features.widgets.WidgetArgsBuilder
|
import im.vector.app.features.widgets.WidgetArgsBuilder
|
||||||
import org.matrix.android.sdk.api.session.crypto.verification.IncomingSasVerificationTransaction
|
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.roomdirectory.PublicRoom
|
||||||
import org.matrix.android.sdk.api.session.room.model.thirdparty.RoomDirectoryData
|
import org.matrix.android.sdk.api.session.room.model.thirdparty.RoomDirectoryData
|
||||||
import org.matrix.android.sdk.api.session.terms.TermsService
|
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) {
|
override fun openNotJoinedRoom(context: Context, roomId: String, eventId: String?, roomSummary: RoomSummary?, buildTask: Boolean) {
|
||||||
if (context is VectorBaseActivity) {
|
val roomPreviewData = RoomPreviewData(
|
||||||
context.notImplemented("Open not joined room")
|
roomId = roomId,
|
||||||
} else {
|
eventId = eventId,
|
||||||
context.toast(R.string.not_implemented)
|
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) {
|
override fun openGroupDetail(groupId: String, context: Context, buildTask: Boolean) {
|
||||||
|
|
|
@ -28,6 +28,7 @@ import im.vector.app.features.pin.PinMode
|
||||||
import im.vector.app.features.settings.VectorSettingsActivity
|
import im.vector.app.features.settings.VectorSettingsActivity
|
||||||
import im.vector.app.features.share.SharedData
|
import im.vector.app.features.share.SharedData
|
||||||
import im.vector.app.features.terms.ReviewTermsActivity
|
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.roomdirectory.PublicRoom
|
||||||
import org.matrix.android.sdk.api.session.room.model.thirdparty.RoomDirectoryData
|
import org.matrix.android.sdk.api.session.room.model.thirdparty.RoomDirectoryData
|
||||||
import org.matrix.android.sdk.api.session.terms.TermsService
|
import org.matrix.android.sdk.api.session.terms.TermsService
|
||||||
|
@ -50,7 +51,7 @@ interface Navigator {
|
||||||
|
|
||||||
fun openRoomForSharingAndFinish(activity: Activity, roomId: String, sharedData: SharedData)
|
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)
|
fun openRoomPreview(context: Context, publicRoom: PublicRoom, roomDirectoryData: RoomDirectoryData)
|
||||||
|
|
||||||
|
|
|
@ -19,12 +19,15 @@ package im.vector.app.features.permalink
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
|
import im.vector.app.core.utils.toast
|
||||||
import im.vector.app.features.navigation.Navigator
|
import im.vector.app.features.navigation.Navigator
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.schedulers.Schedulers
|
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.PermalinkData
|
||||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkParser
|
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.api.util.Optional
|
||||||
import org.matrix.android.sdk.rx.rx
|
import org.matrix.android.sdk.rx.rx
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -82,8 +85,7 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti
|
||||||
private fun PermalinkData.RoomLink.getRoomId(): Single<Optional<String>> {
|
private fun PermalinkData.RoomLink.getRoomId(): Single<Optional<String>> {
|
||||||
val session = activeSessionHolder.getSafeActiveSession()
|
val session = activeSessionHolder.getSafeActiveSession()
|
||||||
return if (isRoomAlias && session != null) {
|
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, true).subscribeOn(Schedulers.io())
|
||||||
session.rx().getRoomIdByAlias(roomIdOrAlias, false).subscribeOn(Schedulers.io())
|
|
||||||
} else {
|
} else {
|
||||||
Single.just(Optional.from(roomIdOrAlias))
|
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) {
|
private fun openRoom(context: Context, roomId: String?, eventId: String?, buildTask: Boolean) {
|
||||||
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
||||||
return if (roomId != null && session.getRoom(roomId) != null) {
|
if (roomId == null) {
|
||||||
navigator.openRoom(context, roomId, eventId, buildTask)
|
context.toast("Couldn't get roomId in permalink data.")
|
||||||
} else {
|
return
|
||||||
navigator.openNotJoinedRoom(context, roomId, eventId, buildTask)
|
}
|
||||||
|
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.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,20 +24,22 @@ import im.vector.app.R
|
||||||
import im.vector.app.core.extensions.addFragment
|
import im.vector.app.core.extensions.addFragment
|
||||||
import im.vector.app.core.platform.ToolbarConfigurable
|
import im.vector.app.core.platform.ToolbarConfigurable
|
||||||
import im.vector.app.core.platform.VectorBaseActivity
|
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.roomdirectory.PublicRoom
|
||||||
import org.matrix.android.sdk.api.session.room.model.thirdparty.RoomDirectoryData
|
import org.matrix.android.sdk.api.session.room.model.thirdparty.RoomDirectoryData
|
||||||
import org.matrix.android.sdk.api.util.MatrixItem
|
import org.matrix.android.sdk.api.util.MatrixItem
|
||||||
import kotlinx.android.parcel.Parcelize
|
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class RoomPreviewData(
|
data class RoomPreviewData(
|
||||||
val roomId: String,
|
val roomId: String,
|
||||||
val roomName: String?,
|
val eventId: String? = null,
|
||||||
val roomAlias: String?,
|
val roomName: String? = null,
|
||||||
val topic: String?,
|
val roomAlias: String? = null,
|
||||||
val worldReadable: Boolean,
|
val topic: String? = null,
|
||||||
val avatarUrl: String?,
|
val worldReadable: Boolean = false,
|
||||||
val homeServer: String?
|
val avatarUrl: String? = null,
|
||||||
|
val homeServer: String? = null,
|
||||||
|
val buildTask: Boolean = false
|
||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
val matrixItem: MatrixItem
|
val matrixItem: MatrixItem
|
||||||
get() = MatrixItem.RoomItem(roomId, roomName ?: roomAlias, avatarUrl)
|
get() = MatrixItem.RoomItem(roomId, roomName ?: roomAlias, avatarUrl)
|
||||||
|
@ -48,6 +50,12 @@ class RoomPreviewActivity : VectorBaseActivity(), ToolbarConfigurable {
|
||||||
companion object {
|
companion object {
|
||||||
private const val ARG = "ARG"
|
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 {
|
fun getIntent(context: Context, publicRoom: PublicRoom, roomDirectoryData: RoomDirectoryData): Intent {
|
||||||
return Intent(context, RoomPreviewActivity::class.java).apply {
|
return Intent(context, RoomPreviewActivity::class.java).apply {
|
||||||
putExtra(ARG, RoomPreviewData(
|
putExtra(ARG, RoomPreviewData(
|
||||||
|
|
|
@ -48,13 +48,15 @@ class RoomPreviewNoPreviewFragment @Inject constructor(
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
setupToolbar(roomPreviewNoPreviewToolbar)
|
setupToolbar(roomPreviewNoPreviewToolbar)
|
||||||
|
val titleText = roomPreviewData.roomName ?: roomPreviewData.roomAlias ?: roomPreviewData.roomId
|
||||||
|
|
||||||
// Toolbar
|
// Toolbar
|
||||||
avatarRenderer.render(roomPreviewData.matrixItem, roomPreviewNoPreviewToolbarAvatar)
|
avatarRenderer.render(roomPreviewData.matrixItem, roomPreviewNoPreviewToolbarAvatar)
|
||||||
roomPreviewNoPreviewToolbarTitle.text = roomPreviewData.roomName ?: roomPreviewData.roomAlias
|
roomPreviewNoPreviewToolbarTitle.text = titleText
|
||||||
|
|
||||||
// Screen
|
// Screen
|
||||||
avatarRenderer.render(roomPreviewData.matrixItem, roomPreviewNoPreviewAvatar)
|
avatarRenderer.render(roomPreviewData.matrixItem, roomPreviewNoPreviewAvatar)
|
||||||
roomPreviewNoPreviewName.text = roomPreviewData.roomName ?: roomPreviewData.roomAlias
|
roomPreviewNoPreviewName.text = titleText
|
||||||
roomPreviewNoPreviewTopic.setTextOrHide(roomPreviewData.topic)
|
roomPreviewNoPreviewTopic.setTextOrHide(roomPreviewData.topic)
|
||||||
|
|
||||||
if (roomPreviewData.worldReadable) {
|
if (roomPreviewData.worldReadable) {
|
||||||
|
@ -98,7 +100,7 @@ class RoomPreviewNoPreviewFragment @Inject constructor(
|
||||||
// Quit this screen
|
// Quit this screen
|
||||||
requireActivity().finish()
|
requireActivity().finish()
|
||||||
// Open room
|
// Open room
|
||||||
navigator.openRoom(requireActivity(), roomPreviewData.roomId)
|
navigator.openRoom(requireActivity(), roomPreviewData.roomId, roomPreviewData.eventId, roomPreviewData.buildTask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue