Skip to content

Commit

Permalink
Merge pull request #6978 from vector-im/feature/bma/null_room
Browse files Browse the repository at this point in the history
Fix crash when opening an unknown room
  • Loading branch information
bmarty authored Aug 31, 2022
2 parents 6341cf9 + fe42cdc commit 318352f
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 45 deletions.
1 change: 1 addition & 0 deletions changelog.d/6978.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash when opening an unknown room
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import com.airbnb.epoxy.EpoxyModel
import com.airbnb.epoxy.OnModelBuildFinishedListener
import com.airbnb.epoxy.addGlidePreloader
import com.airbnb.epoxy.glidePreloader
import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
Expand Down Expand Up @@ -161,6 +162,7 @@ import im.vector.app.features.home.room.detail.composer.SendMode
import im.vector.app.features.home.room.detail.composer.boolean
import im.vector.app.features.home.room.detail.composer.voice.VoiceMessageRecorderView
import im.vector.app.features.home.room.detail.composer.voice.VoiceMessageRecorderView.RecordingUiState
import im.vector.app.features.home.room.detail.error.RoomNotFound
import im.vector.app.features.home.room.detail.readreceipts.DisplayReadReceiptsBottomSheet
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
import im.vector.app.features.home.room.detail.timeline.action.EventSharedAction
Expand Down Expand Up @@ -992,9 +994,9 @@ class TimelineFragment :
views.jumpToBottomView.debouncedClicks {
timelineViewModel.handle(RoomDetailAction.ExitTrackingUnreadMessagesState)
views.jumpToBottomView.visibility = View.INVISIBLE
if (!timelineViewModel.timeline.isLive) {
if (timelineViewModel.timeline?.isLive == false) {
scrollOnNewMessageCallback.forceScrollOnNextUpdate()
timelineViewModel.timeline.restartWithEventId(null)
timelineViewModel.timeline?.restartWithEventId(null)
} else {
layoutManager.scrollToPosition(0)
}
Expand Down Expand Up @@ -1224,12 +1226,12 @@ class TimelineFragment :
}
}

private fun handleSearchAction() {
private fun handleSearchAction() = withState(timelineViewModel) { state ->
navigator.openSearch(
context = requireContext(),
roomId = timelineArgs.roomId,
roomDisplayName = timelineViewModel.getRoomSummary()?.displayName,
roomAvatarUrl = timelineViewModel.getRoomSummary()?.avatarUrl
roomDisplayName = state.asyncRoomSummary()?.displayName,
roomAvatarUrl = state.asyncRoomSummary()?.avatarUrl
)
}

Expand Down Expand Up @@ -1640,6 +1642,10 @@ class TimelineFragment :

override fun invalidate() = withState(timelineViewModel, messageComposerViewModel) { mainState, messageComposerState ->
invalidateOptionsMenu()
if (mainState.asyncRoomSummary is Fail) {
handleRoomSummaryFailure(mainState.asyncRoomSummary)
return@withState
}
val summary = mainState.asyncRoomSummary()
renderToolbar(summary)
renderTypingMessageNotification(summary, mainState)
Expand Down Expand Up @@ -1695,6 +1701,23 @@ class TimelineFragment :
updateLiveLocationIndicator(mainState.isSharingLiveLocation)
}

private fun handleRoomSummaryFailure(asyncRoomSummary: Fail<RoomSummary>) {
views.roomNotFound.isVisible = true
views.roomNotFoundText.text = when (asyncRoomSummary.error) {
is RoomNotFound -> {
getString(
R.string.timeline_error_room_not_found,
if (vectorPreferences.developerMode()) {
"\nDeveloper info: $timelineArgs"
} else {
""
}
)
}
else -> errorFormatter.toHumanReadable(asyncRoomSummary.error)
}
}

private fun updateLiveLocationIndicator(isSharingLiveLocation: Boolean) {
views.liveLocationStatusIndicator.isVisible = isSharingLiveLocation
}
Expand Down Expand Up @@ -2520,15 +2543,19 @@ class TimelineFragment :
* Navigate to Threads timeline for the specified rootThreadEventId
* using the ThreadsActivity.
*/
private fun navigateToThreadTimeline(rootThreadEventId: String, startsThread: Boolean = false, showKeyboard: Boolean = false) {
private fun navigateToThreadTimeline(
rootThreadEventId: String,
startsThread: Boolean = false,
showKeyboard: Boolean = false,
) = withState(timelineViewModel) { state ->
analyticsTracker.capture(Interaction.Name.MobileRoomThreadSummaryItem.toAnalyticsInteraction())
context?.let {
val roomThreadDetailArgs = ThreadTimelineArgs(
startsThread = startsThread,
roomId = timelineArgs.roomId,
displayName = timelineViewModel.getRoomSummary()?.displayName,
avatarUrl = timelineViewModel.getRoomSummary()?.avatarUrl,
roomEncryptionTrustLevel = timelineViewModel.getRoomSummary()?.roomEncryptionTrustLevel,
displayName = state.asyncRoomSummary()?.displayName,
avatarUrl = state.asyncRoomSummary()?.avatarUrl,
roomEncryptionTrustLevel = state.asyncRoomSummary()?.roomEncryptionTrustLevel,
rootThreadEventId = rootThreadEventId,
showKeyboard = showKeyboard
)
Expand Down Expand Up @@ -2559,14 +2586,14 @@ class TimelineFragment :
* Navigate to Threads list for the current room
* using the ThreadsActivity.
*/
private fun navigateToThreadList() {
private fun navigateToThreadList() = withState(timelineViewModel) { state ->
analyticsTracker.capture(Interaction.Name.MobileRoomThreadListButton.toAnalyticsInteraction())
context?.let {
val roomThreadDetailArgs = ThreadTimelineArgs(
roomId = timelineArgs.roomId,
displayName = timelineViewModel.getRoomSummary()?.displayName,
roomEncryptionTrustLevel = timelineViewModel.getRoomSummary()?.roomEncryptionTrustLevel,
avatarUrl = timelineViewModel.getRoomSummary()?.avatarUrl
displayName = state.asyncRoomSummary()?.displayName,
roomEncryptionTrustLevel = state.asyncRoomSummary()?.roomEncryptionTrustLevel,
avatarUrl = state.asyncRoomSummary()?.avatarUrl
)
navigator.openThreadList(it, roomThreadDetailArgs)
}
Expand Down
Loading

0 comments on commit 318352f

Please sign in to comment.