Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when opening an unknown room #6978

Merged
merged 7 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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