Skip to content

Commit 318352f

Browse files
authored
Merge pull request #6978 from vector-im/feature/bma/null_room
Fix crash when opening an unknown room
2 parents 6341cf9 + fe42cdc commit 318352f

File tree

6 files changed

+192
-45
lines changed

6 files changed

+192
-45
lines changed

changelog.d/6978.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix crash when opening an unknown room

vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import com.airbnb.epoxy.EpoxyModel
6262
import com.airbnb.epoxy.OnModelBuildFinishedListener
6363
import com.airbnb.epoxy.addGlidePreloader
6464
import com.airbnb.epoxy.glidePreloader
65+
import com.airbnb.mvrx.Fail
6566
import com.airbnb.mvrx.args
6667
import com.airbnb.mvrx.fragmentViewModel
6768
import com.airbnb.mvrx.withState
@@ -161,6 +162,7 @@ import im.vector.app.features.home.room.detail.composer.SendMode
161162
import im.vector.app.features.home.room.detail.composer.boolean
162163
import im.vector.app.features.home.room.detail.composer.voice.VoiceMessageRecorderView
163164
import im.vector.app.features.home.room.detail.composer.voice.VoiceMessageRecorderView.RecordingUiState
165+
import im.vector.app.features.home.room.detail.error.RoomNotFound
164166
import im.vector.app.features.home.room.detail.readreceipts.DisplayReadReceiptsBottomSheet
165167
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
166168
import im.vector.app.features.home.room.detail.timeline.action.EventSharedAction
@@ -992,9 +994,9 @@ class TimelineFragment :
992994
views.jumpToBottomView.debouncedClicks {
993995
timelineViewModel.handle(RoomDetailAction.ExitTrackingUnreadMessagesState)
994996
views.jumpToBottomView.visibility = View.INVISIBLE
995-
if (!timelineViewModel.timeline.isLive) {
997+
if (timelineViewModel.timeline?.isLive == false) {
996998
scrollOnNewMessageCallback.forceScrollOnNextUpdate()
997-
timelineViewModel.timeline.restartWithEventId(null)
999+
timelineViewModel.timeline?.restartWithEventId(null)
9981000
} else {
9991001
layoutManager.scrollToPosition(0)
10001002
}
@@ -1224,12 +1226,12 @@ class TimelineFragment :
12241226
}
12251227
}
12261228

1227-
private fun handleSearchAction() {
1229+
private fun handleSearchAction() = withState(timelineViewModel) { state ->
12281230
navigator.openSearch(
12291231
context = requireContext(),
12301232
roomId = timelineArgs.roomId,
1231-
roomDisplayName = timelineViewModel.getRoomSummary()?.displayName,
1232-
roomAvatarUrl = timelineViewModel.getRoomSummary()?.avatarUrl
1233+
roomDisplayName = state.asyncRoomSummary()?.displayName,
1234+
roomAvatarUrl = state.asyncRoomSummary()?.avatarUrl
12331235
)
12341236
}
12351237

@@ -1640,6 +1642,10 @@ class TimelineFragment :
16401642

16411643
override fun invalidate() = withState(timelineViewModel, messageComposerViewModel) { mainState, messageComposerState ->
16421644
invalidateOptionsMenu()
1645+
if (mainState.asyncRoomSummary is Fail) {
1646+
handleRoomSummaryFailure(mainState.asyncRoomSummary)
1647+
return@withState
1648+
}
16431649
val summary = mainState.asyncRoomSummary()
16441650
renderToolbar(summary)
16451651
renderTypingMessageNotification(summary, mainState)
@@ -1695,6 +1701,23 @@ class TimelineFragment :
16951701
updateLiveLocationIndicator(mainState.isSharingLiveLocation)
16961702
}
16971703

1704+
private fun handleRoomSummaryFailure(asyncRoomSummary: Fail<RoomSummary>) {
1705+
views.roomNotFound.isVisible = true
1706+
views.roomNotFoundText.text = when (asyncRoomSummary.error) {
1707+
is RoomNotFound -> {
1708+
getString(
1709+
R.string.timeline_error_room_not_found,
1710+
if (vectorPreferences.developerMode()) {
1711+
"\nDeveloper info: $timelineArgs"
1712+
} else {
1713+
""
1714+
}
1715+
)
1716+
}
1717+
else -> errorFormatter.toHumanReadable(asyncRoomSummary.error)
1718+
}
1719+
}
1720+
16981721
private fun updateLiveLocationIndicator(isSharingLiveLocation: Boolean) {
16991722
views.liveLocationStatusIndicator.isVisible = isSharingLiveLocation
17001723
}
@@ -2520,15 +2543,19 @@ class TimelineFragment :
25202543
* Navigate to Threads timeline for the specified rootThreadEventId
25212544
* using the ThreadsActivity.
25222545
*/
2523-
private fun navigateToThreadTimeline(rootThreadEventId: String, startsThread: Boolean = false, showKeyboard: Boolean = false) {
2546+
private fun navigateToThreadTimeline(
2547+
rootThreadEventId: String,
2548+
startsThread: Boolean = false,
2549+
showKeyboard: Boolean = false,
2550+
) = withState(timelineViewModel) { state ->
25242551
analyticsTracker.capture(Interaction.Name.MobileRoomThreadSummaryItem.toAnalyticsInteraction())
25252552
context?.let {
25262553
val roomThreadDetailArgs = ThreadTimelineArgs(
25272554
startsThread = startsThread,
25282555
roomId = timelineArgs.roomId,
2529-
displayName = timelineViewModel.getRoomSummary()?.displayName,
2530-
avatarUrl = timelineViewModel.getRoomSummary()?.avatarUrl,
2531-
roomEncryptionTrustLevel = timelineViewModel.getRoomSummary()?.roomEncryptionTrustLevel,
2556+
displayName = state.asyncRoomSummary()?.displayName,
2557+
avatarUrl = state.asyncRoomSummary()?.avatarUrl,
2558+
roomEncryptionTrustLevel = state.asyncRoomSummary()?.roomEncryptionTrustLevel,
25322559
rootThreadEventId = rootThreadEventId,
25332560
showKeyboard = showKeyboard
25342561
)
@@ -2559,14 +2586,14 @@ class TimelineFragment :
25592586
* Navigate to Threads list for the current room
25602587
* using the ThreadsActivity.
25612588
*/
2562-
private fun navigateToThreadList() {
2589+
private fun navigateToThreadList() = withState(timelineViewModel) { state ->
25632590
analyticsTracker.capture(Interaction.Name.MobileRoomThreadListButton.toAnalyticsInteraction())
25642591
context?.let {
25652592
val roomThreadDetailArgs = ThreadTimelineArgs(
25662593
roomId = timelineArgs.roomId,
2567-
displayName = timelineViewModel.getRoomSummary()?.displayName,
2568-
roomEncryptionTrustLevel = timelineViewModel.getRoomSummary()?.roomEncryptionTrustLevel,
2569-
avatarUrl = timelineViewModel.getRoomSummary()?.avatarUrl
2594+
displayName = state.asyncRoomSummary()?.displayName,
2595+
roomEncryptionTrustLevel = state.asyncRoomSummary()?.roomEncryptionTrustLevel,
2596+
avatarUrl = state.asyncRoomSummary()?.avatarUrl
25702597
)
25712598
navigator.openThreadList(it, roomThreadDetailArgs)
25722599
}

0 commit comments

Comments
 (0)