Fix switch to best space when tapping notification
This commit is contained in:
parent
31e487b073
commit
1d7ce1c794
|
@ -0,0 +1 @@
|
|||
Notification does not take me to the room when another space was last viewed
|
|
@ -78,11 +78,17 @@ class AppStateHandler @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun setCurrentSpace(spaceId: String?, session: Session? = null) {
|
||||
fun setCurrentSpace(spaceId: String?, session: Session? = null, persistNow: Boolean = false) {
|
||||
val uSession = session ?: activeSessionHolder.getSafeActiveSession() ?: return
|
||||
if (selectedSpaceDataSource.currentValue?.orNull() is RoomGroupingMethod.BySpace &&
|
||||
spaceId == selectedSpaceDataSource.currentValue?.orNull()?.space()?.roomId) return
|
||||
val spaceSum = spaceId?.let { uSession.getRoomSummary(spaceId) }
|
||||
|
||||
if (persistNow) {
|
||||
uiStateRepository.storeGroupingMethod(true, uSession.sessionId)
|
||||
uiStateRepository.storeSelectedSpace(spaceSum?.roomId, uSession.sessionId)
|
||||
}
|
||||
|
||||
selectedSpaceDataSource.post(Option.just(RoomGroupingMethod.BySpace(spaceSum)))
|
||||
if (spaceId != null) {
|
||||
uSession.coroutineScope.launch(Dispatchers.IO) {
|
||||
|
|
|
@ -237,7 +237,8 @@ data class RoomDetailArgs(
|
|||
val roomId: String,
|
||||
val eventId: String? = null,
|
||||
val sharedData: SharedData? = null,
|
||||
val openShareSpaceForId: String? = null
|
||||
val openShareSpaceForId: String? = null,
|
||||
val switchToParentSpace: Boolean = false
|
||||
) : Parcelable
|
||||
|
||||
class RoomDetailFragment @Inject constructor(
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.airbnb.mvrx.Uninitialized
|
|||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import im.vector.app.AppStateHandler
|
||||
import im.vector.app.BuildConfig
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||
|
@ -55,6 +56,7 @@ import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
|||
import im.vector.app.features.session.coroutineScope
|
||||
import im.vector.app.features.settings.VectorDataStore
|
||||
import im.vector.app.features.settings.VectorPreferences
|
||||
import im.vector.app.space
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
|
@ -114,7 +116,8 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
private val jitsiService: JitsiService,
|
||||
private val activeConferenceHolder: JitsiActiveConferenceHolder,
|
||||
private val decryptionFailureTracker: DecryptionFailureTracker,
|
||||
timelineFactory: TimelineFactory
|
||||
timelineFactory: TimelineFactory,
|
||||
appStateHandler: AppStateHandler
|
||||
) : VectorViewModel<RoomDetailViewState, RoomDetailAction, RoomDetailViewEvents>(initialState),
|
||||
Timeline.Listener, ChatEffectManager.Delegate, CallProtocolsChecker.Listener {
|
||||
|
||||
|
@ -179,6 +182,24 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
if (OutboundSessionKeySharingStrategy.WhenEnteringRoom == BuildConfig.outboundSessionKeySharingStrategy && room.isEncrypted()) {
|
||||
prepareForEncryption()
|
||||
}
|
||||
|
||||
if (initialState.switchToParentSpace) {
|
||||
// We are coming from a notification, try to switch to the most relevant space
|
||||
// so that when hitting back the room will appear in the list
|
||||
appStateHandler.getCurrentRoomGroupingMethod()?.space().let { currentSpace ->
|
||||
val currentRoomSummary = room.roomSummary() ?: return@let
|
||||
// nothing we are good
|
||||
if (currentSpace == null || !currentRoomSummary.flattenParentIds.contains(currentSpace.roomId)) {
|
||||
// take first one or switch to home
|
||||
appStateHandler.setCurrentSpace(
|
||||
currentRoomSummary
|
||||
.flattenParentIds.firstOrNull { it.isNotBlank() },
|
||||
// force persist, because if not on resume the AppStateHandler will resume
|
||||
// the current space from what was persisted on enter background
|
||||
persistNow = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeDataStore() {
|
||||
|
|
|
@ -66,14 +66,16 @@ data class RoomDetailViewState(
|
|||
val isAllowedToStartWebRTCCall: Boolean = true,
|
||||
val isAllowedToSetupEncryption: Boolean = true,
|
||||
val hasFailedSending: Boolean = false,
|
||||
val jitsiState: JitsiState = JitsiState()
|
||||
val jitsiState: JitsiState = JitsiState(),
|
||||
val switchToParentSpace: Boolean = false
|
||||
) : MavericksState {
|
||||
|
||||
constructor(args: RoomDetailArgs) : this(
|
||||
roomId = args.roomId,
|
||||
eventId = args.eventId,
|
||||
// Also highlight the target event, if any
|
||||
highlightedEventId = args.eventId
|
||||
highlightedEventId = args.eventId,
|
||||
switchToParentSpace = args.switchToParentSpace
|
||||
)
|
||||
|
||||
fun isWebRTCCallOptionAvailable() = (asyncRoomSummary.invoke()?.joinedMembersCount ?: 0) <= 2
|
||||
|
|
|
@ -773,7 +773,7 @@ class NotificationUtils @Inject constructor(private val context: Context,
|
|||
}
|
||||
|
||||
private fun buildOpenRoomIntent(roomId: String): PendingIntent? {
|
||||
val roomIntentTap = RoomDetailActivity.newIntent(context, RoomDetailArgs(roomId))
|
||||
val roomIntentTap = RoomDetailActivity.newIntent(context, RoomDetailArgs(roomId = roomId, switchToParentSpace = true))
|
||||
roomIntentTap.action = TAP_TO_VIEW_ACTION
|
||||
// pending intent get reused by system, this will mess up the extra params, so put unique info to avoid that
|
||||
roomIntentTap.data = createIgnoredUri("openRoom?$roomId")
|
||||
|
|
Loading…
Reference in New Issue